Subject: [PATCH v14 0/5] checkout: 'autostash' for branch switching

From: "Harald Nordgren via GitGitGadget" <[email-masked]>
Date: Wed, 15 Apr 2026 16:24:14 +0000

Simplifying the tests in t/t3903-stash.sh according to Phillip Wood's
comment. I believe everything sound be fixed now or responded to.

Also rebasing against upstream.

Harald Nordgren (5):
  stash: add --label-ours, --label-theirs, --label-base for apply
  sequencer: allow create_autostash to run silently
  sequencer: teach autostash apply to take optional conflict marker
    labels
  checkout: rollback lock on early returns in merge_working_tree
  checkout -m: autostash when switching branches

 Documentation/git-checkout.adoc |  58 ++++-----
 Documentation/git-stash.adoc    |  11 +-
 Documentation/git-switch.adoc   |  33 ++---
 builtin/checkout.c              | 149 +++++++++++------------
 builtin/commit.c                |   3 +-
 builtin/merge.c                 |  15 ++-
 builtin/stash.c                 |  28 +++--
 sequencer.c                     |  73 ++++++++---
 sequencer.h                     |   7 +-
 t/t3420-rebase-autostash.sh     |  24 +++-
 t/t3903-stash.sh                |  24 ++++
 t/t7201-co.sh                   | 208 ++++++++++++++++++++++++++++++++
 t/t7600-merge.sh                |   2 +-
 xdiff-interface.c               |  12 ++
 xdiff-interface.h               |   1 +
 xdiff/xmerge.c                  |   6 +-
 16 files changed, 483 insertions(+), 171 deletions(-)

base-commit: 9f223ef1c026d91c7ac68cc0211bde255dda6199
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2234%2FHaraldNordgren%2Fcheckout_autostash-v14
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2234/HaraldNordgren/checkout_autostash-v14
Pull-Request: https://github.com/git/git/pull/2234

Range-diff vs v13:

 1:  43bfdf2136 ! 1:  e18c25599a stash: add --label-ours, --label-theirs, --label-base for apply
     @@ builtin/stash.c: static int branch_stash(int argc, const char **argv, const char

       ## t/t3903-stash.sh ##
     -@@ t/t3903-stash.sh: test_expect_success 'restore untracked files even when we hit conflicts' '
     - 	)
     +@@ t/t3903-stash.sh: setup_stash() {
     + 	git add other-file &&
     + 	test_tick &&
     + 	git commit -m initial &&
     ++	git tag initial &&
     + 	echo 2 >file &&
     + 	git add file &&
     + 	echo 3 >file &&
     +@@ t/t3903-stash.sh: test_expect_success 'stash.index=false overridden by --index' '
     + 	test_cmp expect file
       '
       
      +test_expect_success 'apply with custom conflict labels' '
     -+	test_when_finished "git reset --hard && git stash drop" &&
     -+	git reset --hard &&
     ++	git reset --hard initial &&
      +	test_commit label-base conflict-file base-content &&
      +	echo stashed >conflict-file &&
      +	git stash push -m "stashed" &&
     @@ t/t3903-stash.sh: test_expect_success 'restore untracked files even when we hit
      +'
      +
      +test_expect_success 'apply with empty conflict labels' '
     -+	test_when_finished "git reset --hard && git stash drop" &&
     -+	git reset --hard &&
     ++	git reset --hard initial &&
      +	test_commit empty-label-base conflict-file base-content &&
      +	echo stashed >conflict-file &&
      +	git stash push -m "stashed" &&
     @@ t/t3903-stash.sh: test_expect_success 'restore untracked files even when we hit
      +	test_grep "^>>>>>>>$" conflict-file
      +'
      +
     - test_expect_success 'stash create reports a locked index' '
     - 	test_when_finished "rm -rf repo" &&
     - 	git init repo &&
     + test_done
      
       ## xdiff/xmerge.c ##
      @@ xdiff/xmerge.c: static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
 2:  7f3c32f5e9 = 2:  ce29b10264 sequencer: allow create_autostash to run silently
 3:  b279d1dac8 = 3:  73051d1762 sequencer: teach autostash apply to take optional conflict marker labels
 4:  04869314ec = 4:  191058d8e3 checkout: rollback lock on early returns in merge_working_tree
 5:  4b3c6025ac = 5:  86f33df1eb checkout -m: autostash when switching branches

-- 
gitgitgadget