fix: sync repo default branch
This commit is contained in:
+18
-9
@@ -152,10 +152,13 @@ def sync_git(args):
|
||||
repo_url = repo_url.replace("https://", f"https://{args.auth_token}@")
|
||||
|
||||
dest = args.target_path
|
||||
branch = args.branch or "main"
|
||||
branch = args.branch
|
||||
|
||||
# 如果指定了 path 且是单文件模式,使用 raw URL 下载
|
||||
if args.path and args.single_file:
|
||||
# 单文件下载必须指定分支,如果未指定则默认为 main
|
||||
if not args.branch:
|
||||
args.branch = "main"
|
||||
sync_git_file(args, repo_url, env)
|
||||
return
|
||||
|
||||
@@ -199,28 +202,34 @@ def sync_git(args):
|
||||
|
||||
# 稀疏 clone(如果指定了 path)
|
||||
if args.path:
|
||||
run([
|
||||
cmd = [
|
||||
"git", "clone",
|
||||
"--depth", "1",
|
||||
"--filter=blob:none",
|
||||
"--no-checkout",
|
||||
"-b", branch,
|
||||
repo_url,
|
||||
dest
|
||||
], env=env)
|
||||
]
|
||||
if branch:
|
||||
cmd.extend(["-b", branch])
|
||||
|
||||
run(cmd, env=env)
|
||||
|
||||
run(["git", "sparse-checkout", "init", "--cone"], cwd=dest, env=env)
|
||||
run(["git", "sparse-checkout", "set", args.path], cwd=dest, env=env)
|
||||
run(["git", "checkout"], cwd=dest, env=env)
|
||||
else:
|
||||
# 普通 clone
|
||||
run([
|
||||
cmd = [
|
||||
"git", "clone",
|
||||
"--depth", "1",
|
||||
"-b", branch,
|
||||
repo_url,
|
||||
dest
|
||||
], env=env)
|
||||
]
|
||||
if branch:
|
||||
cmd.extend(["-b", branch])
|
||||
|
||||
run(cmd, env=env)
|
||||
|
||||
print("同步完成")
|
||||
|
||||
@@ -286,8 +295,8 @@ def main():
|
||||
help="源地址(Git仓库URL或文件URL)")
|
||||
parser.add_argument("--target-path", required=True,
|
||||
help="目标路径")
|
||||
parser.add_argument("--branch", default="main",
|
||||
help="Git 分支名(仅 git 类型有效)")
|
||||
parser.add_argument("--branch",
|
||||
help="Git 分支名(仅 git 类型有效,不填则使用默认分支)")
|
||||
parser.add_argument("--path",
|
||||
help="仅拉取指定文件或目录(仅 git 类型有效)")
|
||||
parser.add_argument("--single-file", action="store_true",
|
||||
|
||||
@@ -172,7 +172,7 @@ async function save() {
|
||||
</div>
|
||||
<div v-if="repoConfig.source_type === 'git'" class="grid grid-cols-1 sm:grid-cols-4 items-center gap-2 sm:gap-3">
|
||||
<Label class="sm:text-right text-sm">分支</Label>
|
||||
<Input v-model="repoConfig.branch" placeholder="main (可选)" class="sm:col-span-3 h-8 text-sm" autocomplete="off" />
|
||||
<Input v-model="repoConfig.branch" placeholder="默认分支 (可选)" class="sm:col-span-3 h-8 text-sm" autocomplete="off" />
|
||||
</div>
|
||||
<div v-if="repoConfig.source_type === 'git'" class="grid grid-cols-1 sm:grid-cols-4 items-center gap-2 sm:gap-3">
|
||||
<Label class="sm:text-right text-sm">稀疏路径</Label>
|
||||
|
||||
Reference in New Issue
Block a user