refactor(lib): 開啟目標專案 git repo 的那幾行收進 lib

「路徑不是 repo 就報 NOT_A_GIT_REPO」加上「把 cwd 綁進 runGit」原本在 branch-prep 與
commit-split 各寫一份。錯誤碼要一致,而這件事寫第三遍就該收起來了。
This commit is contained in:
2026-09-17 08:23:26 +00:00
parent fbc80f286f
commit 95e6026950
2 changed files with 18 additions and 8 deletions
+16
View File
@@ -379,6 +379,22 @@ export function runGit(args, { cwd } = {}) {
}
}
/**
* 開一個目標專案的 git repo,回傳綁在它身上的執行器。
*
* 碰目標專案 git 的腳本都從這裡進去:路徑不是 repo 時的錯誤碼要一致,
* 而「把 cwd 綁進 runGit」這件事寫第三遍就該收起來了。
*
* @param {string} path 目標專案的根目錄
* @returns {(...args: string[]) => string} 綁定 cwd 的 git 執行器
*/
export function openGitRepo(path) {
if (!existsSync(join(path, '.git'))) {
throw new ScriptError('NOT_A_GIT_REPO', `${path} 不是 git repo;請用 --path 指向目標專案的根目錄`);
}
return (...args) => runGit(args, { cwd: path });
}
// ── 四層前置檢查 ───────────────────────────────────────────────────
/**