Re: Bug: being stuck in rebase mode when accidently typing `git am`
- From
D. Ben Knoble <ben.knoble@gmail.com>
- Date
- Apr 11, 2025, 18:32 UTC
- Message-ID
- <CALnO6CCYqF1QHQzS6DH200cqi6VRmhWjvts87S99a+jqqgHHfw@mail.gmail.com>
- In-Reply-To
- <CALnO6CCbzqez9-BvbuV3NRRMvFLHSv57Tfwj3ibadUAMKznWrw@mail.gmail.com>
On Fri, Apr 11, 2025 at 2:23 PM D. Ben Knoble <ben.knoble@gmail.com> wrote:
Show 11 quoted lines
> > On Thu, Apr 10, 2025 at 10:35 AM Ludo Pulles <ludo.pulles@gmail.com> wrote: > > 3. Run `git status`. It will say: 'You are currently rebasing. (all > > conflicts fixed: run "git rebase --continue")'. > > Yes, this is odd: my shell prompt (using the contrib script) says > "AM/REBASE", so I know better: git am --abort does the trick. > > This seems like a failure of git-status more than anything; I wonder > if there's some difference in how the prompt script checks for > in-progress am vs. how git-status does it?
Ok, looks like the prompt script checks for rebase, apply, and then gives up (its ambiguous):
if [ -d "$g/rebase-apply" ]; then __git_eread "$g/rebase-apply/next" step __git_eread "$g/rebase-apply/last" total if [ -f "$g/rebase-apply/rebasing" ]; then __git_eread "$g/rebase-apply/head-name" b r="|REBASE" elif [ -f "$g/rebase-apply/applying" ]; then r="|AM" else r="|AM/REBASE" fi
(with apologies for GMail stripping leading tabs :eyeroll:—source code link [1])
Meantime, wt-status just assumes it must be a rebase if it isn't an apply:
if (!stat(worktree_git_path(the_repository, wt, "rebase-apply"), &st)) { if (!stat(worktree_git_path(the_repository, wt, "rebase-apply/applying"), &st)) { state->am_in_progress = 1; if (!stat(worktree_git_path(the_repository, wt, "rebase-apply/patch"), &st) && !st.st_size) state->am_empty_patch = 1; } else { state->rebase_in_progress = 1; state->branch = get_branch(wt, "rebase-apply/head-name"); state->onto = get_branch(wt, "rebase-apply/onto"); }
(source: [2])
The shell distinction was contributed in e75201963f (Improve bash prompt to detect various states like an unfinished merge, 2007-09-30), author CC'd. I think the logic in wt-status.c is largely unchanged from 83c750acde (wt-status.*: better advices for git status added, 2012-06-05), author CC'd as well.
Maybe we can omit a "You might be rebasing or applying; we're not sure which?" type of message?
[1]: https://github.com/git/git/blob/08bdfd453584e489d5a551aecbdcb77584e1b958/contrib/completion/git-prompt.sh#L517-L527 [2]: https://github.com/git/git/blob/08bdfd453584e489d5a551aecbdcb77584e1b958/wt-status.c#L1725-L1734
-- D. Ben Knoble