Bug 1:x repo <id> 在本地仓库不存在时会 clone 两次
复现
rm -rf ~/.x-repo/github.com/x-cmd/x-cmd-version
x repo x-cmd/x-cmd-version
预期
clone 一次,然后 cd 进入目录。
实际
Cloning into '/Users/liaoxuanbin/.x-repo/github.com/x-cmd/x-cmd-version'...
...
fatal: destination path 'x-cmd-version' already exists and is not an empty directory.
根因
___x_cmd_repo_cd(以及 edit/code)在目录不存在时调用 ___x_cmd_repo_update "$id" "$x_",把 $x_(本地路径)当作第二个 repo ID 传入。___x_cmd_repo_update 的 while 循环将所有位置参数视为 repo ID:
- 第一轮:
$id = x-cmd/x-cmd-version → 目录不存在 → clone 成功
- 第二轮:
$id = /Users/.../.x-repo/.../x-cmd-version → resolve 到刚 clone 的目录 → update 内部尝试 clone,报 already exists
修复
| 位置 |
函数 |
改动 |
lib/main:88 |
___x_cmd_repo_edit |
"$id" "$x_" → "$id" |
lib/main:109 |
___x_cmd_repo_cd |
"$id" "$x_" → "$id" |
lib/main:123 |
___x_cmd_repo_code |
"$id" "$x_" → "$id" |
Bug 2a:x repo fresh <不存在的id> 缺少错误检查
复现
x repo fresh nonexistent/repo-12345
预期
报错提示仓库不存在。
实际
___x_cmd_repo_resolve_ resolve 失败后未检查返回值,$x_ 为空,继续执行了 ___x_cmd fresh ""。
根因
lib/main:51 — ___x_cmd_repo_resolve_ "$id" 后缺少 || return $?。
修复
| 位置 |
函数 |
改动 |
lib/main:51 |
___x_cmd_repo_fresh |
加 || return $? |
Bug 2b:x repo cd <不存在的id> 缺少错误检查
复现
x repo cd nonexistent/repo-12345
预期
报错提示仓库不存在。
实际
resolve 失败后 $x_ 为空,[ -d "" ] 为 false,触发 ___x_cmd_repo_update "",行为不可预期。
根因
lib/main:107 — ___x_cmd_repo_resolve_ "$id" 后缺少 || return $?。
修复
| 位置 |
函数 |
改动 |
lib/main:107 |
___x_cmd_repo_cd |
加 || return $? |
Bug 1:
x repo <id>在本地仓库不存在时会 clone 两次复现
rm -rf ~/.x-repo/github.com/x-cmd/x-cmd-version x repo x-cmd/x-cmd-version预期
clone 一次,然后
cd进入目录。实际
根因
___x_cmd_repo_cd(以及edit/code)在目录不存在时调用___x_cmd_repo_update "$id" "$x_",把$x_(本地路径)当作第二个 repo ID 传入。___x_cmd_repo_update的 while 循环将所有位置参数视为 repo ID:$id=x-cmd/x-cmd-version→ 目录不存在 → clone 成功$id=/Users/.../.x-repo/.../x-cmd-version→ resolve 到刚 clone 的目录 → update 内部尝试 clone,报already exists修复
lib/main:88___x_cmd_repo_edit"$id" "$x_"→"$id"lib/main:109___x_cmd_repo_cd"$id" "$x_"→"$id"lib/main:123___x_cmd_repo_code"$id" "$x_"→"$id"Bug 2a:
x repo fresh <不存在的id>缺少错误检查复现
预期
报错提示仓库不存在。
实际
___x_cmd_repo_resolve_resolve 失败后未检查返回值,$x_为空,继续执行了___x_cmd fresh ""。根因
lib/main:51—___x_cmd_repo_resolve_ "$id"后缺少|| return $?。修复
lib/main:51___x_cmd_repo_fresh|| return $?Bug 2b:
x repo cd <不存在的id>缺少错误检查复现
x repo cd nonexistent/repo-12345预期
报错提示仓库不存在。
实际
resolve 失败后
$x_为空,[ -d "" ]为 false,触发___x_cmd_repo_update "",行为不可预期。根因
lib/main:107—___x_cmd_repo_resolve_ "$id"后缺少|| return $?。修复
lib/main:107___x_cmd_repo_cd|| return $?