#!/bin/bash

# Git 稀疏克隆 OpenWrt rockchip 内容到【当前目录】
git_sparse_clone() {
  branch="$1"
  repourl="$2"
  sparse_path="$3"

  git clone \
    --depth=1 \
    -b "$branch" \
    --single-branch \
    --filter=blob:none \
    --sparse \
    "$repourl"

  repodir="$(basename "$repourl" .git)"
  cd "$repodir" || exit 1

  git sparse-checkout set "$sparse_path"

  # 把 rockchip 目录里的内容直接移到外面的当前目录
  mv "$sparse_path"/* ../
  mv "$sparse_path"/.[!.]* ../ 2>/dev/null || true
  mv "$sparse_path"/..?* ../ 2>/dev/null || true

  cd ..
  rm -rf "$repodir"
}

git_sparse_clone openwrt-25.12 https://github.com/openwrt/openwrt.git target/linux/generic