git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

Previous: 井上司
Message 9 of 9 in “switch/checkout stops halfway when it fails to write tracking config”
  1. 井上司Oct 20, 2026
  2. Junio C HamanoOct 20, 2026
  3. 井上司Oct 20, 2026
  4. Junio C HamanoOct 21, 2026
  5. D. Ben KnobleOct 20, 2026
  6. 井上司Oct 20, 2026
  7. D. Ben KnobleOct 22, 2026
  8. 井上司Oct 22, 2026
  9. 井上司Nov 8, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.