tummychow / git-absorb

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

absorb failed, err: HEAD is not a branch #64

Closed jyn514 closed 2 years ago

jyn514 commented 2 years ago

My use case is that I want to do interactive rebasing to absorb a past commit into the tree. I ran:

  1. git rebase -i origin/master
  2. Changed one of the commits from commit to edit
  3. When rebase stopped at that commit, ran git reset HEAD~ && git add -u && git absorb

That gives a hard error:

Jun 28 12:59:34.824 CRIT absorb failed, err: HEAD is not a branch

but I'm not sure why being on a branch should matter?

jyn514 commented 2 years ago

ah, by reading the source I found that I can use --force to ignore this error. It would be nice for absorb to suggest that.

tummychow commented 2 years ago

i'm not morally opposed to this but, as i discussed here https://github.com/tummychow/git-absorb/pull/49#issuecomment-939393646 the correct behavior is not obvious when head is detached. sometimes it makes sense to force, other times passing force will do nothing because your head is actually the same as some commit on a branch. happy to take suggestions on how the ux should be adjusted

jyn514 commented 2 years ago

it'll hide all ancestors of the master branch, which includes 3333, so there will be no commits in the stack, and you'll get the "No commits available to fix up" error.

you wouldn't be able to absorb earlier into, say, 2222 (unless you used the --base flag). my guess is, what you really want is for git absorb to pick the root of the rebase as the default base if there is one. that would be a bit harder to do; idk if libgit2 makes it easy to get that information.

this seems fine, though? absorb already requires you to specify --base if you pass --force outside a branch, I think that behavior is fine.

jyn514 commented 2 years ago

I agree using merge-base of HEAD and the target branch would be nice, but I don't think absorb should give a hard error if it can't determine the base; it should just require you to pass --base yourself.

jyn514 commented 2 years ago

by the way, I just wanted to say thank you so much for making git-absorb, it's saved me at least half an hour just today :)

tummychow commented 2 years ago

hm, that's a good point. lemme see if amending the error message is the most sensible thing to do

tummychow commented 2 years ago

yeah it seemed reasonable since we already have another warning that's similar

Jul 04 16:53:46.261 CRIT absorb failed, err: HEAD is not a branch, use --force to override, line: 109, module: git_absorb
jyn514 commented 2 years ago

Amazing, thank you!