Subject: Re: [PATCH v9 4/4] checkout: -m (--merge) uses autostash when switching branches

From: Jeff King <[email-masked]>
Date: Sat, 11 Apr 2026 14:38:23 -0400

On Fri, Apr 10, 2026 at 09:01:13PM +0000, Harald Nordgren via GitGitGadget wrote:

>  	if (do_merge) {
>  		ret = merge_working_tree(opts, &old_branch_info, new_branch_info, &writeout_error);
> +		if (ret && opts->merge) {
> +			create_autostash_ref_silent(the_repository,
> +						   "CHECKOUT_AUTOSTASH");

This tries to create a root-level ref called CHECKOUT_AUTOSTASH, which
violates the syntax rules given in gitglossary's "ref" entry:

  Ref names must either start with refs/ or be located in the root of
  the hierarchy. For the latter, their name must follow these rules:

    •   The name consists of only upper-case characters or underscores.

    •   The name ends with "_HEAD" or is equal to "HEAD".

Our enforcement of these rules has some holes, but I have a local series
to fix that (which is how I noticed the problem). The entry continues to
list some exceptions:

  There are some irregular refs in the root of the hierarchy that do not
  match these rules. The following list is exhaustive and shall not be
  extended in the future:

    •   AUTO_MERGE

    •   BISECT_EXPECTED_REV

    •   NOTES_MERGE_PARTIAL

    •   NOTES_MERGE_REF

    •   MERGE_AUTOSTASH

We can add CHECKOUT_AUTOSTASH to the list of exceptions, but I wonder if
there is another name we could use that would conform to the usual
rules.

-Peff