Repository navigation
fix(git): ブランチ切替の dirty 確認が失敗したとき切替を止める - #3439
Merged
Merged
Conversation
force でない checkout は `status --porcelain` が null(失敗・timeout)を返すと
ガードを素通りしていた。null のときは checkout を実行せず
GitTimeoutError('Could not verify working tree state') を投げる。
エラー型: git-errors.ts に「状態を確かめられない」型は GitTimeoutError のみ
(timeout/失敗を示す既存型)なのでそれを使い、メッセージで dirty
(GitDirtyError, 409 dirty) と区別した。handleGitApiError は GitTimeoutError を
HTTP 504 `{ error: 'Git command timed out' }` に写す(メッセージは応答に出ない)。
force の checkout は従来どおりガードを通らない。
同型ガード探索 (grep "execGitCommand(['status'" src/lib/git):
- git-status.ts:36 getGitStatus: #3435 で別に直すので触らない
- git-stash/git-commit/git-route-helpers: null を clean とみなすガードなし
- git-reset.ts isDefaultBranchForReset: rev-parse HEAD が null だと false
(=デフォルトブランチ保護を外す)で reset --hard が進みうる fail-open。
同じく GitTimeoutError で拒否するよう修正。
対の場所探索: docs の ja/en・同処理の写し・古い動きを固定したテストを探したが
該当なし(既存テストは null を返すケースを固定していない)。
本文に無い指摘: なし
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
3 of 4 tasks
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
force でないブランチの checkout は、前に
git status --porcelainで dirty を確かめるが、execGitCommandがnull(失敗。負荷時の 1 秒 timeout を含む)を返すとガードを素通りしていた(src/lib/git/git-branches.ts:322)。statusがnullのときは checkout を実行せずGitTimeoutError('Could not verify working tree state')を投げる(fail-closed)。handleGitApiErrorは HTTP 504{ error: 'Git command timed out' }に写す。dirty(409)とは区別される。force は従来どおりこのガードを通らないsrc/lib/git/git-reset.tsのisDefaultBranchForResetはrev-parse HEADがnullだと false(=既定ブランチの保護が外れる)になり、reset --hardが進みえた。同じくGitTimeoutErrorで拒否するgit-status.ts(getGitStatus)は fix(git): git status が読めないとき worktree を clean と表示する #3435 で別に直すため触っていないRefs #3436(develop 向けのため Closes は使わない)
Test plan
commandmatedev verify --task(契約 gates: lint / typecheck / unit-related + work-evidence / scope / env-clean、requireCommit: true)すべて PASS(exit 0)tests/unit/lib/git/git-branches.test.tsに status 失敗で checkout しない・reset の保護が外れないケースを追加。既存の dirty / clean / force のテストは無変更で通過。既存のit/describeの削除 0 件tests/unit/guards合格、changelog-fragments.mjs checkexit 0🤖 Generated with Claude Code