Re: [PATCH] checkout: add --autostash option for branch switching
- From
Harald Nordgren <haraldnordgren@gmail.com>
- Date
- Mar 17, 2026, 09:47 UTC
- Message-ID
- <20260317094716.43654-1-haraldnordgren@gmail.com>
- In-Reply-To
- <xmqqcy13o81b.fsf@gitster.g>
Show 14 quoted lines
>> Why is the dry-run of unpack_trees() not an extra check? I was assuming >> that it was because we do the dry-run and then do it for real after >> possibly stashing any local changes. That's why I was wondering if we >> could avoid the dry-run by creating the stash if the non-dry-run >> unpack_trees() failed. > > Ah, I didn't even think about that possibility. > > Try to unpack anyway, and if unpack_trees() branch switching > succeeds, we are done. Otherwise, we can trust that unpack_trees() > did not do _anything_ to the index or the working tree files, so we > can create the stash at that time. > > Makes sense.
Interesting idea, and thanks for your help with this! I gave it a shot with this simplification.
It passes the tests, which either means it works, or just that the test coverage is not good enough to detect new issues introduced by me here.
Harald