git-clone-resume 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,167 @@
1
+ # Git 断点续传克隆(Windows)
2
+
3
+ 针对 GitHub 等网络不稳定场景:先用 **partial clone** 只拉 commit/tree 元数据,再 **按批 checkout 文件**。中断后用同一条命令再跑即可续传。
4
+
5
+ 对应 Linux 参考脚本:<https://github.com/chaihahaha/git-cheatsheet> 中的 `clone_1by1.sh`。
6
+
7
+ 交互式全屏 TUI(无参数启动进入向导;克隆中可暂停 / 停止,重跑同一命令续传):
8
+
9
+ | 向导 | 克隆中 |
10
+ | --- | --- |
11
+ | ![向导主页面](snap/main.png) | ![克隆运行界面](snap/run.png) |
12
+
13
+ ## 文件
14
+
15
+ | 文件 | 说明 |
16
+ | --- | --- |
17
+ | `git-clone-resume.ps1` | 主脚本,PowerShell 5.1 / 7+ |
18
+ | `git-clone-resume.tui.ps1` | 全屏 TUI(向导、进度面板、快捷键),由主脚本自动加载 |
19
+ | `git-clone-resume.cmd` | 双击或 cmd 下调用的启动器(无参数会打开 TUI 向导) |
20
+ | `snap/` | README 截图(向导主页面、克隆运行界面) |
21
+
22
+ ## 依赖
23
+
24
+ - [Git for Windows](https://git-scm.com/download/win) **>= 2.19**(partial clone)
25
+ - Windows PowerShell 5.1(系统自带)或 PowerShell 7+
26
+ - 建议打开 Windows 长路径:`git config --global core.longpaths true`
27
+
28
+ ## 安装与短命令
29
+
30
+ 发布版本会提供一个 ZIP 压缩包。解压到不会随意移动的目录后,将该目录加入用户或系统 `PATH`,即可使用短命令 `gcr`:
31
+
32
+ ```bat
33
+ gcr https://github.com/user/repo.git
34
+ gcr https://github.com/user/repo.git -Ref main -OutDir D:\src\repo
35
+ ```
36
+
37
+ 压缩包同时包含完整命令 `git-clone-resume`。`gcr` 只是同目录启动器,不会复制或改变核心脚本;三个 PowerShell 文件需要保持在同一目录。
38
+
39
+ 安装后可在 `cmd.exe`、PowerShell、Windows Terminal 和脚本/CI 中调用。CI 或重定向输出时建议显式使用 `-NoTui`。
40
+
41
+ 后续发布渠道会复用 GitHub Release 中的同一 ZIP 和 SHA256 校验值:
42
+
43
+ - Scoop:执行下面的命令后直接提供 `gcr` 命令。
44
+
45
+ ```powershell
46
+ scoop bucket add git-clone-resume https://github.com/normalwindow/git-clone-resume
47
+ scoop install git-clone-resume
48
+ ```
49
+
50
+ - winget:从 0.1.1 起提供 `.exe` 启动器;manifest 已准备,提交官方仓库审核后可用于系统级安装、升级和卸载。
51
+
52
+ - npm:执行 `npm install -g git-clone-resume` 后提供 `gcr` 命令,但仍需要 Git for Windows 和 PowerShell。
53
+
54
+ 卸载时只移除工具目录,不会删除任何目标仓库、`.git/partial-resume/` 状态或历史记录文件。
55
+
56
+ ## 用法
57
+
58
+ 交互式(推荐):双击 `git-clone-resume.cmd`,或在终端里不带 URL 运行,会打开全屏 TUI 向导。剪贴板里如果是仓库地址会自动填入;底栏会显示当前选项的简短说明。
59
+
60
+ ```bat
61
+ git-clone-resume.cmd
62
+ git-clone-resume.cmd https://github.com/user/repo.git
63
+ ```
64
+
65
+ 或:
66
+
67
+ ```powershell
68
+ powershell -NoProfile -ExecutionPolicy Bypass -File .\git-clone-resume.ps1
69
+ powershell -NoProfile -ExecutionPolicy Bypass -File .\git-clone-resume.ps1 https://github.com/user/repo.git
70
+ ```
71
+
72
+ 在 Windows Terminal / 现代控制台里,带 URL 启动同样进入进度面板:百分比、ETA、活动日志、失败列表。脚本/CI 或输出被重定向时自动退回原来的纯日志模式。
73
+
74
+ 常用参数:
75
+
76
+ ```powershell
77
+ # 指定目录和分支
78
+ .\git-clone-resume.ps1 https://github.com/user/repo.git -Ref main -OutDir D:\src\repo
79
+
80
+ # 只拉部分路径
81
+ .\git-clone-resume.ps1 https://github.com/user/repo.git -Include src/*,docs/* -Exclude *.bin
82
+
83
+ # 更大批次(更快,中断粒度更粗)
84
+ .\git-clone-resume.ps1 https://github.com/user/repo.git -BatchSize 64 -MaxRetries 12
85
+
86
+ # 续传时按 blob 哈希校验已存在文件
87
+ .\git-clone-resume.ps1 https://github.com/user/repo.git -Verify
88
+
89
+ # 只列出文件,不下载 blob
90
+ .\git-clone-resume.ps1 https://github.com/user/repo.git -DryRun
91
+
92
+ # 强制 / 禁用全屏 TUI
93
+ .\git-clone-resume.ps1 https://github.com/user/repo.git -Tui
94
+ .\git-clone-resume.ps1 https://github.com/user/repo.git -NoTui
95
+
96
+ # 从本机历史恢复最近一次未完成的克隆
97
+ .\git-clone-resume.ps1 -ResumeLast
98
+ ```
99
+
100
+ 完整帮助:`git-clone-resume.cmd -Help`
101
+
102
+ ### TUI 快捷键
103
+
104
+ 克隆过程中(底栏会随阶段切换提示):
105
+
106
+ | 键 | 作用 |
107
+ | --- | --- |
108
+ | `Q` / `Ctrl+C` | 当前 git 命令结束后停止;再按一次强制结束 |
109
+ | `P` / `Esc` | 当前批次结束后暂停 |
110
+ | `Space` | 从暂停恢复 |
111
+ | `F` | 切换失败文件列表 |
112
+ | `↑` `↓` / `j` `k` | 滚动活动日志 |
113
+ | `End` | 跟随最新日志 |
114
+ | `?` / `H` | 帮助 |
115
+ | `Enter` | 结束页关闭 |
116
+
117
+ 向导里:`Enter` 编辑或开始,`Space` 切换开关,`←` `→` 改批次大小,`Tab` 最近任务,`Ctrl+V` 粘贴 URL,`Q` 退出。高亮某一选项时,底栏上一行会显示该选项的简短说明(Guide)。
118
+
119
+ 历史记录写在 `%LOCALAPPDATA%\git-clone-resume\history.json`。框线在中文控制台里若变宽,会自动改用 ASCII;也可设 `GCR_ASCII=1` 强制 ASCII。
120
+
121
+ ## 工作原理
122
+
123
+ 1. `git init` + `remote.origin.partialclonefilter=blob:none`(不直接 `git clone`,这样元数据 fetch 失败也可重试)
124
+ 2. `git fetch --filter=blob:none origin <ref>` 只拉 commit / tree
125
+ 3. 把 HEAD 钉在该 commit SHA 上,避免中途远端更新导致续传错位
126
+ 4. `git ls-tree -r` 得到文件清单(**不用 -l**,否则 blob:none 会为了拿 size 把全部 blob 拉下来;也不用 `-z`,PowerShell 5.1 会把 NUL 截断)
127
+ 5. 分批 `git checkout <sha> -- file1 file2 ...`,由 promisor remote 按需拉 blob
128
+ 6. 成功的路径追加写入 `.git/partial-resume/done.txt`
129
+ 7. 再次运行:跳过已落盘文件。整批 checkout 失败立刻拆成单文件(单文件才指数退避)。结束时修复 Windows 上被弄乱的 git index
130
+
131
+ 进度目录(不会进工作区):
132
+
133
+ ```
134
+ .git/partial-resume/
135
+ meta.txt URL / ref / 钉住的 commit
136
+ files.tsv 待处理文件清单
137
+ done.txt 已完成路径(追加写入)
138
+ failed.txt 多次重试仍失败的路径
139
+ log.txt 运行日志
140
+ ```
141
+
142
+ ## 比原 bash 脚本多做的事
143
+
144
+ - 目录已存在时续传,不会因为 `git clone` 到一半而从头失败
145
+ - 元数据 fetch 与 blob checkout 都有重试 / 指数退避
146
+ - 批次 checkout;整批失败立刻拆成单文件,避免同一批重试十几次(sha1 missing / Directory not empty)
147
+ - Windows 长路径、`http.version=HTTP/1.1`、低速断开、UTF-8 路径、`index.lock` 清理
148
+ - 跳过 submodule gitlink;可用 `-Include` / `-Exclude` 过滤
149
+ - Ctrl+C 或断电后重跑同一命令即可,不需要手动改文件列表
150
+ - 交互式全屏 TUI:无参数向导、进度面板、暂停/停止、最近任务续传(`-NoTui` 可关闭)
151
+
152
+ ## 注意事项
153
+
154
+ - **不要**删掉目标目录里的 `.git`,否则进度和已下 blob 都没了。
155
+ - 私有仓库走本机已有的凭据即可(Git Credential Manager / `gh auth` / SSH key)。
156
+ - 子模块不会自动递归;要对子模块再执行一次本脚本。
157
+ - Git LFS 文件 checkout 后如需真正指针内容,请再执行 `git lfs pull`。
158
+ - 若 fetch 阶段就反复 `HTTP/2` / `RPC failed`,脚本已强制 `HTTP/1.1`;仍失败时检查代理、`GIT_SSL_NO_VERIFY` 不要随便开。
159
+ - 想换分支或更新到最新 commit:加 `-ForceRefetch`(会按新 SHA 补下差异文件)。
160
+
161
+ ## 退出码
162
+
163
+ | 码 | 含义 |
164
+ | --- | --- |
165
+ | 0 | 全部完成或本来就已经齐 |
166
+ | 1 | 有文件最终仍失败,或中途异常;可重跑续传 |
167
+ | 2 | 参数错误 / 找不到 git |
package/gcr.cmd ADDED
@@ -0,0 +1,4 @@
1
+ @echo off
2
+ setlocal EnableExtensions
3
+ call "%~dp0git-clone-resume.cmd" %*
4
+ exit /b %ERRORLEVEL%
@@ -0,0 +1,22 @@
1
+ @echo off
2
+ setlocal EnableExtensions
3
+ REM Git resume clone launcher. No args -> interactive TUI wizard.
4
+ chcp 65001 >nul 2>nul
5
+ set "SCRIPT=%~dp0git-clone-resume.ps1"
6
+ if not exist "%SCRIPT%" (
7
+ echo Cannot find git-clone-resume.ps1 next to this launcher.
8
+ exit /b 2
9
+ )
10
+ where git >nul 2>nul
11
+ if errorlevel 1 (
12
+ echo Git is not in PATH. Install Git for Windows: https://git-scm.com/download/win
13
+ exit /b 2
14
+ )
15
+ powershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT%" %*
16
+ set "ERR=%ERRORLEVEL%"
17
+ if not "%ERR%"=="0" if "%~1"=="" (
18
+ echo.
19
+ echo Exit code %ERR%. Press any key to close.
20
+ pause >nul
21
+ )
22
+ exit /b %ERR%