From: Phillip Wood Date: Fri, 12 May 2023 15:18:39 GMT Subject: Re: git rebase --root bug Message-ID: In-Reply-To: Hi Taylor On 11/05/2023 17:16, Taylor Blau wrote: > On Thu, May 11, 2023 at 03:21:11PM +0100, Phillip Wood wrote: >> The cause of the problem is that --root creates an empty commit (known as >> "squash_onto" in the code) which it uses as the "onto" commit. When it picks >> the first commit in the todo list the "onto" commit is amended and so is >> unreachable when the reflog is expired above. I think the best fix would be >> to stop pretending that we have a real "onto" commit when --root is used >> without --onto and either store "new root" .git/rebase-merge/onto or not >> create that file at all. > > Wouldn't it suffice to consider the squash_onto commit as reachable the > same way we do for `--indexed-objects`? We could do that rather than clean up the implementation of --root. We should definitely consider the commit stored in .git/rebase-merge/orig-head to be reachable as the following test fails diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index ff0afad63e..8ac5e2eec6 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -66,6 +66,19 @@ test_expect_success 'setup' ' SHELL= export SHELL +test_expect_success 'orig-head is not garbage collected' ' + git checkout --detach && + test_commit --no-tag x && + ( + set_fake_editor && + FAKE_LINES="1 edit 2" git rebase -i @~2 + ) && + git reset @^ && + git reflog expire --expire-unreachable=now && + git gc --prune=now && + git rebase --abort +' + test_expect_success 'rebase --keep-empty' ' git checkout -b emptybranch primary && git commit --allow-empty -m "empty" && I'm not familiar with the gc code, does it use the --indexed-objects option of "git rev-list"? Best Wishes Phillip