fix(claim): 被碼錶擋下時明說停錶不會動到既有的工作樹

議題 #38 的使用者故事第 30 條:使用者常以為停錶等於放棄那顆工作包,於是寧可
不停——工時就記到別顆議題去了。碼錶只管時間、工作樹只管檔案,兩者互不相干,
這件事要在擋下來的當下就講,不能指望使用者自己推論。

領取與起錶會撞到同一個擋路理由,訊息收進 lib 只寫一份。順手收掉 review 指出的
三處:planWorktree 沒用到的 repo 參數、與 path.resolve 同名而誤導的區域函式、
以及只有 lib 自己用得到卻對外 export 的兩支路徑函式。

回滾補上最後一道:git 清不掉時把目錄本身也刪掉。那條路徑在這次執行之前不存在
(不存在正是建立的前提),裡面不可能有使用者的東西,而留著它下一次重跑會直接
撞上 WORKTREE_PATH_TAKEN——一次失敗的建立不該讓人從此開不了工。

議題 #40

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-17 16:29:12 +08:00
co-authored by Claude Opus 5
parent 4583a5f210
commit 0154cf59d4
9 changed files with 65 additions and 36 deletions
+2 -9
View File
@@ -15,7 +15,6 @@
* node scripts/timer.js --repo owner/name --index 40 [--host <網址>] [--dry-run]
*/
import {
ScriptError,
expectOk,
fetchIssue,
giteaRequest,
@@ -26,6 +25,7 @@ import {
parseRepo,
preflight,
resolveLogin,
stopwatchElsewhere,
stopwatchOnIssue,
} from './lib.js';
@@ -47,14 +47,7 @@ main(async () => {
const watches = await listStopwatches(login);
const 已在計時 = stopwatchOnIssue(watches, repo, index) !== null;
if (!已在計時 && watches.length > 0) {
const elsewhere = watches[0];
throw new ScriptError(
'STOPWATCH_ON_OTHER_ISSUE',
`你的碼錶正跑在 ${elsewhere.repo_owner_name}/${elsewhere.repo_name} 的議題 ` +
`#${elsewhere.issue_index} 上,起錶前請先手動停錶,否則工時會記到那一顆去`,
);
}
if (!已在計時 && watches.length > 0) throw stopwatchElsewhere(watches[0], '起錶');
// 已經在跑就不重起:重新起錶會把已經累積的時間切成兩段
const planned = 已在計時 ? [] : [{ method: 'POST', path: `${issuePath}/stopwatch/start`, body: {} }];