Skip to content

checkout: finish switch when tracking config cannot be written

tsukasa-ino via GitGitGadget git 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 2 repliesIn review
  2. v11 patch 2 repliesSuperseded

Changes in v2 from the cover letter

* 1/3: the test now compares the whole hint message, as suggested by Harald Nordgren. It also checks that the command in the hint works once the lock is removed, as suggested by Junio
(https://lore.kernel.org/git/[email protected]/).
* 2/3 and 3/3 are new. They implement the direction agreed on the bug report thread (https://lore.kernel.org/git/[email protected]/).

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3branch: strip refs/heads/ from the --set-upstream-to hintbranch.c t/t3200-branch.sh+30 -30 replies
2/3branch: return an error from setup_tracking()branch.c branch.h builtin/branch.c +1 more+55 -350 replies
3/3checkout: finish switching when the tracking config cannot be writtenbuiltin/checkout.c t/t2027-checkout-track.sh t/t2060-switch.sh +1 more+67 -90 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/3] checkout: finish switch when tracking config cannot be written

When the tracking config cannot be written (for example, because .git/config.lock exists), git switch -c and checkout -b stop halfway. The worktree, the index and the new branch ref are already updated, but HEAD stays on the old branch, and the changes are left staged. The hint printed at that point was also wrong: it suggested origin/refs/heads/.

1/3 strips refs/heads/ from the hint. 2/3 makes setup_tracking() return an error instead of calling exit(). No behavior change yet. 3/3 makes switch and checkout finish the switch and exit with status 0, as push -u, clone and fetch already do. git branch still fails.

Changes since v1:

* 1/3: the test now compares the whole hint message, as suggested by Harald Nordgren. It also checks that the command in the hint works once the lock is removed, as suggested by Junio
(https://lore.kernel.org/git/[email protected]/).
* 2/3 and 3/3 are new. They implement the direction agreed on the bug report thread (https://lore.kernel.org/git/[email protected]/).

Making the switch fully atomic, so that a failure undoes the worktree, the index, the ref and the config, is left for a separate topic.

tsukasa inoue (3):
branch: strip refs/heads/ from the --set-upstream-to hint
branch: return an error from setup_tracking()
checkout: finish switching when the tracking config cannot be written

 branch.c                  | 43 +++++++++++++++++++++++----------------
 branch.h                  | 21 +++++++++++--------
 builtin/branch.c          | 17 +++++++++++-----
 builtin/checkout.c        |  6 ++++++
 t/t2027-checkout-track.sh | 20 ++++++++++++++++++
 t/t2060-switch.sh         | 20 ++++++++++++++++++
 t/t3200-branch.sh         | 38 ++++++++++++++++++++++++++++++++++
 7 files changed, 135 insertions(+), 30 deletions(-)

base-commit: a018953688f1b10bddf91bff8747068f5f4746a4
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2268%2FtsukasaI%2Ffix%2Fbranch-upstream-hint-shortname-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2268/tsukasaI/fix/branch-upstream-hint-shortname-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2268

Range-diff vs v1:

1: 14eac9118e ! 1: e705918378 branch: strip refs/heads/ from the --set-upstream-to hint

     @@ t/t3200-branch.sh: test_expect_success '--set-upstream-to fails on locked config
      +	>.git/config.lock &&
      +	test_must_fail git -c core.configLockTimeout=0 \
      +		branch --set-upstream-to=hintremote/hintbranch hint-local 2>err &&
     -+	test_grep "git branch --set-upstream-to=hintremote/hintbranch\$" err &&
     -+	test_grep ! "refs/heads/" err
     ++	cat >expect <<-\EOF &&
     ++	hint:
     ++	hint: After fixing the error cause you may try to fix up
     ++	hint: the remote tracking information by invoking:
     ++	hint:   git branch --set-upstream-to=hintremote/hintbranch
     ++	EOF
     ++	grep "^hint:" err >actual &&
     ++	test_cmp expect actual &&
     ++	rm -f .git/config.lock &&
     ++	git branch --set-upstream-to=hintremote/hintbranch hint-local &&
     ++	test_cmp_config hintremote branch.hint-local.remote &&
     ++	test_cmp_config refs/heads/hintbranch branch.hint-local.merge
      +'
      +
       test_expect_success 'use --set-upstream-to modify HEAD' '
 -:  ---------- > 2:  4d2cbaf170 branch: return an error from setup_tracking()
 -:  ---------- > 3:  be94ac75bf checkout: finish switching when the tracking config cannot be written
Signature · 1 line
gitgitgadget