Skip to content

checkout -m: refine autostash fallback - #2364

Open
HaraldNordgren wants to merge 2 commits into
git:masterfrom
HaraldNordgren:hn/git-checkout-m-leftoverbits
Open

checkout -m: refine autostash fallback#2364
HaraldNordgren wants to merge 2 commits into
git:masterfrom
HaraldNordgren:hn/git-checkout-m-leftoverbits

Conversation

@HaraldNordgren

@HaraldNordgren HaraldNordgren commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Avoiding checkout -m autostash retries when no tracked local changes exist and visually separating autostash conflict advice from the subsequent branch-switch message.

Addresses #leftoverbits from here: https://lore.kernel.org/git/cfd09dbf-8d77-4464-8030-3a0ffb4aeae7@gmail.com/

Add a conflicted parameter to apply_save_autostash_oid() and
apply_save_autostash_ref() so callers can learn whether applying the
stash resulted in conflicts.  Thread the parameter through
apply_autostash_ref() and update existing callers to pass NULL.

Signed-off-by: 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.

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.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
@HaraldNordgren
HaraldNordgren force-pushed the hn/git-checkout-m-leftoverbits branch from 10747bc to 37becf3 Compare July 25, 2026 14:40
@HaraldNordgren
HaraldNordgren marked this pull request as ready for review July 25, 2026 15:05
@HaraldNordgren

Copy link
Copy Markdown
Contributor Author

/submit

@gitgitgadget-git

Copy link
Copy Markdown

Submitted as pull.2364.git.git.1784993669.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2364/HaraldNordgren/hn/git-checkout-m-leftoverbits-v1

To fetch this version to local tag pr-git-2364/HaraldNordgren/hn/git-checkout-m-leftoverbits-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2364/HaraldNordgren/hn/git-checkout-m-leftoverbits-v1

Comment thread builtin/checkout.c
@@ -838,10 +838,11 @@ static void init_topts(struct unpack_trees_options *topts,
static int merge_working_tree(const struct checkout_opts *opts,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:

> 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.
>
> 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.
>
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> ---
>  builtin/checkout.c | 17 +++++++++++++----
>  t/t7201-co.sh      | 17 ++++++++++++++++-
>  2 files changed, 29 insertions(+), 5 deletions(-)

Thanks.  Will queue.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into seen via e6126a3.

@gitgitgadget-git

Copy link
Copy Markdown

This branch is now known as hn/checkout-m-autostash-refine.

@gitgitgadget-git

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch hn/checkout-m-autostash-refine on the Git mailing list:

The autostash fallback in 'git checkout -m' has been refined to only
retry when there are local changes.  Additionally, a blank line now
visually separates autostash conflict advice from the subsequent
branch-switch message.

Needs review.
cf. <xmqqwluebuhb.fsf@gitster.g>
source: <pull.2364.git.git.1784993669.gitgitgadget@gmail.com>

@gitgitgadget-git

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch hn/checkout-m-autostash-refine on the Git mailing list:

The autostash fallback in 'git checkout -m' has been refined to only
retry when there are local changes.  Additionally, a blank line now
visually separates autostash conflict advice from the subsequent
branch-switch message.

Needs review.
cf. <xmqqwluebuhb.fsf@gitster.g>
source: <pull.2364.git.git.1784993669.gitgitgadget@gmail.com>

@gitgitgadget-git

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch hn/checkout-m-autostash-refine on the Git mailing list:

The autostash fallback in 'git checkout -m' has been refined to only
retry when there are local changes.  Additionally, a blank line now
visually separates autostash conflict advice from the subsequent
branch-switch message.

Needs review.
cf. <xmqqwluebuhb.fsf@gitster.g>
source: <pull.2364.git.git.1784993669.gitgitgadget@gmail.com>

@gitgitgadget-git

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch hn/checkout-m-autostash-refine on the Git mailing list:

The autostash fallback in 'git checkout -m' has been refined to only
retry when there are local changes.  Additionally, a blank line now
visually separates autostash conflict advice from the subsequent
branch-switch message.

Needs review.
cf. <xmqqwluebuhb.fsf@gitster.g>
source: <pull.2364.git.git.1784993669.gitgitgadget@gmail.com>

@gitgitgadget-git

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch hn/checkout-m-autostash-refine on the Git mailing list:

The autostash fallback in 'git checkout -m' has been refined to only
retry when there are local changes.  Additionally, a blank line now
visually separates autostash conflict advice from the subsequent
branch-switch message.

Needs review.
cf. <xmqqwluebuhb.fsf@gitster.g>
source: <pull.2364.git.git.1784993669.gitgitgadget@gmail.com>

@gitgitgadget-git

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch hn/checkout-m-autostash-refine on the Git mailing list:

The autostash fallback in 'git checkout -m' has been refined to only
retry when there are local changes.  Additionally, a blank line now
visually separates autostash conflict advice from the subsequent
branch-switch message.

Needs review.
cf. <xmqqwluebuhb.fsf@gitster.g>
source: <pull.2364.git.git.1784993669.gitgitgadget@gmail.com>

@gitgitgadget-git

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch hn/checkout-m-autostash-refine on the Git mailing list:

The autostash fallback in 'git checkout -m' has been refined to only
retry when there are local changes.  Additionally, a blank line now
visually separates autostash conflict advice from the subsequent
branch-switch message.

Needs review.
cf. <xmqqwluebuhb.fsf@gitster.g>
source: <pull.2364.git.git.1784993669.gitgitgadget@gmail.com>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant