Re: [PATCH] checkout: add --autostash option for branch switching
- From
Harald Nordgren <haraldnordgren@gmail.com>
- Date
- Apr 15, 2026, 08:19 UTC
- Message-ID
- <20260415081900.86956-1-haraldnordgren@gmail.com>
- In-Reply-To
- <20260414201327.51745-1-haraldnordgren@gmail.com>
Show 13 quoted lines
> > > + strbuf_addf(&autostash_msg, > > > + "autostash while switching to '%s'", > > > + new_branch_info->name); > > > + create_autostash_ref_with_msg_silent(the_repository, > > > + "CHECKOUT_AUTOSTASH_HEAD", > > > > It's a shame we have to create a ref here. MERGE_AUTOSTASH exists so > > that "git merge --continue" can apply the stash once the user has > > resolved any merge conflicts. We don't have that problem here because > > there is no user interaction and we could just hold onto the stash oid > > in a variable. > > I don't know how to actually do that. Maybe better to do later?
A gave this a try, but it becomes a very big change. Or maybe I'm missing some key knowledge here.
Show 12 quoted lines
> > > + autostash_msg.buf);
> > > + created_autostash = 1;
> > > + ret = merge_working_tree(opts, &old_branch_info, new_branch_info, &writeout_error);
> > > + }
> > > if (ret) {
> >
> > I'm confused by this - if we stash then don't we expect the call to
> > unpack_trees() in merge_working_tree() to succeed and therefore return
> > 0? If opts->merge is false then we should not be trying to apply the
> > stash when merge_working_tree() fails.
>
> Same here, I'm not sure how to get this to work. Maybe better to do later?I think I succeeded with this one.
Harald