Re: switch/checkout stops halfway when it fails to write tracking config
- From
- 井上司 <inoue.tsukasa.4@gmail.com>
- Date
- Nov 8, 2026, 12:54 UTC
- Message-ID
- <CAP8tz2K2u4yuNE5ck777JVAgCk0-4yoToc1RNaFwMDKVH4zabA@mail.gmail.com>
- In-Reply-To
- <CAP8tz2+cJ4E+Nv_dHuY-8-DoGj7_nP1=98Nn5+M3qMb5WezYVw@mail.gmail.com>
To: Junio C Hamano <gitster@pobox.com> Cc: git@vger.kernel.org, "D. Ben Knoble" <ben.knoble@gmail.com>, Patrick Steinhardt <ps@pks.im> Subject: Re: switch/checkout stops halfway when it fails to write tracking config In-Reply-To: <xmqqecdjsryk.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
> > ... and to leave full atomicity as a separate topic. > > Sounds like a good direction to go.
Thanks for merging ti/checkout-track-failure, and thanks to Ben for the questions in this thread.
I'd like to work on the all-or-none switch now. Today switch_branches() updates the worktree first, then creates the branch ref, writes the tracking config and updates HEAD, so a failure after the first step leaves the worktree switched. I looked at two ways to fix this:
A. Put the branch ref and HEAD in one transaction, prepare it before merge_working_tree(), and commit or abort it afterwards.
B. Prepare that transaction only as a check and abort it, then do the real updates after the worktree update, as today.
I tried both with "git update-ref --stdin" on current master, files and reftable:
- In both, a stale branch lock or a reference-transaction hook rejecting at "prepared" stops the switch before the worktree changes. - With A, every other ref update in a reftable repository fails while the transaction is held, and with files a commit from another process fails on HEAD.lock. The -m autostash steps fail too, because they update HEAD. - A also has to put the branch and HEAD in one transaction, which runs into a reftable reflog bug I reported separately: https://lore.kernel.org/git/CAP8tz2L3Dfhd+ec4+SFkZgXmzQnBg+3Y0REAV+1Hf5X415qnfw@mail.gmail.com/ - With B nothing is locked during the worktree update, so -m and other processes work as before. A branch created by another process between the check and the commit still leaves the switch halfway, and hooks see the check as "prepared" followed by "aborted".
So I'd like to go with B. The tracking config would be written before the worktree update and removed if a later step fails. For -C on the current branch HEAD does not change, so it would be left out of the check.
Does B sound acceptable, given that it does not cover the race with another process?
Thanks, Tsukasa