All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org
Cc: Harald Nordgren <haraldnordgren@gmail.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 2/2] checkout -m: refine autostash fallback
Date: Thu, 27 Aug 2026 14:05:12 +0100	[thread overview]
Message-ID: <28428451-8a56-43be-8ee4-af5a704977a9@gmail.com> (raw)
In-Reply-To: <37becf38c2ef175a3dadcf750e2cca836942d83e.1784993669.git.gitgitgadget@gmail.com>

Hi Harald

On 25/07/2026 16:34, Harald Nordgren via GitGitGadget wrote:
> From: Harald Nordgren <haraldnordgren@gmail.com>
> 
> When unpack_trees() fails under "git checkout -m", only create an
> autostash and retry if there are tracked local changes.  Without such
> changes, the fallback cannot help and merely repeats the same failure.

Unfortunately to do that we have to look for local changes before the 
first call to unpack_trees() so we're trading an occasional 
inconvenience of an unnecessary stash and unstash for the cost of 
looking for local changes on every invocation of "git checkout -m". I 
don't think that is a good trade off, especially as there is no 
guarantee that stashing the local changes will make unpack_trees() 
succeed. To do this effectively would require refactoring unpack_trees() 
to write its error messages to a buffer and return an error flag that 
indicates all the errors that were encountered. We could then check if 
the only thing that prevented upack_trees() from succeeding was local 
changes to files and stash them, or if there are other errors print the 
error message. I suspect such a change is far from straight forward.

> Use the conflict result from apply_autostash_ref() to print a blank line
> before the branch-switch message, visually separating it from the
> conflict advice.


This change is very welcome and could happily be squashed into the first 
patch as it motivates the changes in it.

> diff --git a/t/t7201-co.sh b/t/t7201-co.sh
> index 0ddd1ad7aa..f9696dab36 100755
> --- a/t/t7201-co.sh
> +++ b/t/t7201-co.sh
> @@ -240,6 +240,14 @@ test_expect_success 'checkout -m creates a recoverable stash on conflict' '
>   	test_grep "git stash drop" actual &&
>   	test_grep "git stash pop" actual &&
>   	test_grep "The following paths have local changes" actual &&
> +	sed -n "/apply the local changes later/,/Switched to branch/p" \
> +		actual >separator.actual &&
> +	cat >separator.expect <<-EOF &&
> +	apply the local changes later by running "git stash pop".
> +
> +	Switched to branch ${SQ}side${SQ}
> +	EOF
> +	test_cmp separator.expect separator.actual &&

I wonder whether we should just bite the bullet and check what gets 
printed to the screen with test_cmp, rather than grepping for all these 
separate parts of the message. Is there something in the message that 
makes that difficult?

Thanks

Phillip

>   	git log -p -1 --format="%gs%n%B" -g --diff-merges=1 refs/stash >actual &&
>   	sed /^index/d actual >actual.trimmed &&
>   	cat >expect <<-EOF &&
> @@ -262,11 +270,18 @@ test_expect_success 'checkout -m creates a recoverable stash on conflict' '
>   	git reset --hard
>   '
>   
> -test_expect_success 'checkout -m which would overwrite untracked file' '
> +test_expect_success 'checkout -m only retries untracked-file failure with local changes' '
>   	git checkout -f --detach main &&
>   	test_commit another-file &&
>   	git checkout HEAD^ &&
>   	>another-file.t &&
> +	test_must_fail env GIT_TRACE2_EVENT="$(pwd)/trace" \
> +		git checkout -m @{-1} 2>err &&
> +	test_grep "untracked working tree files" err &&
> +	grep "\"region_enter\".*\"category\":\"index\",\"label\":\"refresh\"" \
> +		trace >refresh.events &&
> +	test_line_count = 1 refresh.events &&
> +
>   	fill 1 2 3 4 5 >one &&
>   	test_must_fail git checkout -m @{-1} 2>err &&
>   	q_to_tab >expect <<-\EOF &&


  parent reply	other threads:[~2026-08-27 13:05 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-25 15:34 [PATCH 0/2] checkout -m: refine autostash fallback Harald Nordgren via GitGitGadget
2026-07-25 15:34 ` [PATCH 1/2] sequencer: teach autostash apply to report conflicts Harald Nordgren via GitGitGadget
2026-08-27 13:01   ` Phillip Wood
2026-08-31 10:18     ` Harald Nordgren
2026-08-31 13:15       ` phillip.wood123
2026-07-25 15:34 ` [PATCH 2/2] checkout -m: refine autostash fallback Harald Nordgren via GitGitGadget
2026-07-28 22:49   ` Junio C Hamano
2026-08-27 13:05   ` Phillip Wood [this message]
2026-08-26 19:14 ` [PATCH 0/2] " Junio C Hamano
2026-08-27 13:12   ` Phillip Wood
2026-08-31 12:00 ` [PATCH v2] checkout: print blank line after autostash conflict advice Harald Nordgren via GitGitGadget
2026-08-31 17:19   ` Junio C Hamano
2026-09-01  9:31     ` Phillip Wood
2026-09-01 13:50       ` Junio C Hamano
2026-09-01  9:49 ` [PATCH v3] checkout: separate autostash conflict advice from branch-switch message Harald Nordgren via GitGitGadget
2026-09-01 13:42   ` Phillip Wood
2026-09-01 17:31     ` Junio C Hamano
2026-09-02 18:29 ` [PATCH v4 0/2] checkout -m: refine autostash fallback Harald Nordgren via GitGitGadget
2026-09-02 18:29   ` [PATCH v4 1/2] stash: reserve exit status 1 for conflicts Harald Nordgren via GitGitGadget
2026-09-02 19:51     ` Junio C Hamano
2026-09-02 20:08       ` Junio C Hamano
2026-09-03 13:57       ` Phillip Wood
2026-09-03 14:45         ` Harald Nordgren
2026-09-03 18:42           ` Junio C Hamano
2026-09-03 19:09             ` Harald Nordgren
2026-09-03 19:45               ` Junio C Hamano
2026-09-04  8:16                 ` Harald Nordgren
2026-09-04 15:09                   ` Phillip Wood
2026-09-04 16:42                     ` Harald Nordgren
2026-09-04 15:21                   ` Junio C Hamano
2026-09-02 18:29   ` [PATCH v4 2/2] checkout: separate autostash conflict advice from branch-switch message Harald Nordgren via GitGitGadget
2026-09-02 19:52     ` Junio C Hamano
2026-09-03 14:00   ` [PATCH v4 0/2] checkout -m: refine autostash fallback Phillip Wood
2026-09-03 14:39 ` [PATCH v5 " Harald Nordgren via GitGitGadget
2026-09-03 14:39   ` [PATCH v5 1/2] stash: reserve exit status 1 for conflicts Harald Nordgren via GitGitGadget
2026-09-03 14:39   ` [PATCH v5 2/2] checkout: separate autostash conflict advice from branch-switch message Harald Nordgren via GitGitGadget
2026-09-03 18:53   ` [PATCH v5 0/2] checkout -m: refine autostash fallback Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=28428451-8a56-43be-8ee4-af5a704977a9@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=haraldnordgren@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.