refactor(lib): 開啟目標專案 git repo 的那幾行收進 lib
「路徑不是 repo 就報 NOT_A_GIT_REPO」加上「把 cwd 綁進 runGit」原本在 branch-prep 與 commit-split 各寫一份。錯誤碼要一致,而這件事寫第三遍就該收起來了。
This commit is contained in:
@@ -23,9 +23,7 @@
|
||||
* node scripts/branch-prep.js --source <來源分支> --slug <英文-kebab>
|
||||
* [--type feat] [--path <目標專案>] [--dry-run]
|
||||
*/
|
||||
import { existsSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { ScriptError, main, parseFlags, runGit } from './lib.js';
|
||||
import { ScriptError, main, openGitRepo, parseFlags } from './lib.js';
|
||||
|
||||
/** 需求描述的長度上限。超過就換一個短的說法,不要靠截斷。 */
|
||||
const SLUG_MAX = 40;
|
||||
@@ -43,11 +41,7 @@ main(async () => {
|
||||
const source = flags.source;
|
||||
const branch = buildBranchName(source, flags.slug, flags.type);
|
||||
|
||||
if (!existsSync(join(path, '.git'))) {
|
||||
throw new ScriptError('NOT_A_GIT_REPO', `${path} 不是 git repo;請用 --path 指向目標專案的根目錄`);
|
||||
}
|
||||
|
||||
const git = (...args) => runGit(args, { cwd: path });
|
||||
const git = openGitRepo(path);
|
||||
checkClean(git, path);
|
||||
|
||||
const hasOrigin = git('remote').split('\n').includes('origin');
|
||||
|
||||
Reference in New Issue
Block a user