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

Fix --and-rebase when last commit is the repository root #26

Closed cstyles closed 4 years ago

cstyles commented 4 years ago

When the last commit in the stack is the repository root, this assertion fails because it expects the last commit to always have exactly one parent. This patch fixes the assertion to allow a base commit with zero parents (i.e., the repository root) and in that case executes git rebase with the --root option so we can absorb changes into the root commit.

Steps to reproduce the bug:

$ mkdir testrepo; cd testrepo
$ git init
Initialized empty Git repository in /Users/collin.styles/testrepo/.git/
$ echo 'file contents' > file.txt
$ git add file.txt
$ git commit -m 'Initial commit'
[master (root-commit) 6a01e2a] Initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 file.txt
$ echo 'Additional changes' >> file.txt
$ git add file.txt
$ git absorb --and-rebase
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `0`,
 right: `1`', src/lib.rs:258:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
Dec 06 03:09:16.996 INFO committed, header: -1,0 +2,1, commit: c51a1357e104af06318c897bd08388433ee49fde