tummychow / git-absorb

git commit --fixup, but automatic
https://crates.io/crates/git-absorb
BSD 3-Clause "New" or "Revised" License
4.64k stars 71 forks source link

Remove "HEAD is not a branch" error? #47

Closed nyanpasu64 closed 3 years ago

nyanpasu64 commented 3 years ago

Sometimes I want to use git absorb when HEAD is detached, for example during an interactive rebase, when I've checked out an old commit, or during a bisect. In this case, I want to absorb a feature-branch commit into previous commits, using git checkout --soft HEAD~; git absorb. However, git-absorb refuses to run when HEAD is detached:

https://github.com/tummychow/git-absorb/blob/6b7cb2fba3e68527af5072cb8f8561ae773d2d08/src/stack.rs#L27-L29

I ended up building git absorb locally with the check removed, installing using cargo install --path ., and running it during an interactive rebase. It actually worked fine, though I had to specify git absorb --base dev. If I didn't specify the base, I instead got:

WARN Please use --base to specify a base commit.
CRIT No commits available to fix up, exiting

Is it possible to remove the branch check upstream?

tummychow commented 3 years ago

hm, yes, i would accept a PR for this. if HEAD is detached and no --base is provided, we should just mask out all the branches (https://github.com/tummychow/git-absorb/blob/6b7cb2fba3e68527af5072cb8f8561ae773d2d08/src/stack.rs#L52). the limit on max stack size would still apply so it wouldn't do anything too silly

nyanpasu64 commented 3 years ago

I don't know what "mask out all the branches" means. Should I make a pull request with just this one check removed, or would I have to read more of the code to learn how branch masking works?

tummychow commented 3 years ago

I don't know what "mask out all the branches" means.

when i say "mask out all the branches", i mean this https://github.com/tummychow/git-absorb/blob/6b7cb2fba3e68527af5072cb8f8561ae773d2d08/src/stack.rs#L53 we hide all the non-HEAD branches from the revwalk so that we don't accidentally absorb a commit that's shared with some other branch. if HEAD is detached then we should hide all the branches period. (which might already be the existing behavior, i'm not sure what head.name() will return when it's detached. might just be the literal string HEAD. if so, then yes you can just remove that check and it'll work)