]> git.ipfire.org Git - thirdparty/git.git/commitdiff
rebase -i: demonstrate obscure loose object cache bug
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 13 Mar 2019 10:16:31 +0000 (03:16 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 14 Mar 2019 03:46:29 +0000 (12:46 +0900)
We specifically support `exec` commands in `git rebase -i`'s todo lists
to rewrite the very same todo list. Of course, we need to validate that
todo list when re-reading it.

It is also totally legitimate to extend the todo list by `pick` lines
using short names of commits that were created only after the rebase
started.

And this is where the loose object cache interferes with this feature:
if *some* loose object was read whose hash shares the same first two
digits with a commit that was not yet created when that loose object was
created, then we fail to find that new commit by its short name in
`get_oid()`, and the interactive rebase fails with an obscure error
message like:

error: invalid line 1: pick 6568fef
error: please fix this using 'git rebase --edit-todo'.

Let's first demonstrate that this is actually a bug in a new regression
test, in a separate commit so that other developers who do not believe
me can cherry-pick it to confirm the problem.

This new regression test generates two commits whose hashes share the
first two hex digits (so that their corresponding loose objects live in
the same subdirectory of .git/objects/, and are therefore supposed to be
in the same loose object cache bin).

It then picks the first, to make sure that the loose object cache is
initialized and cached that object directory, then generates the second
commit and picks it, too. Since the commit was generated in a different
process than the sequencer that wants to pick it, the loose object cache
had no chance of being updated in the meantime.

Technically, we would need only one `exec` command in this regression
test case, but for ease of implementation, it uses a pseudo-recursive
call to the same script.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t3429-rebase-edit-todo.sh

index b9292dfc2a329b32472368fb2874cc4a1e14cf47..862f229c875211cf0b45d7691b71c626468d37fc 100755 (executable)
@@ -11,4 +11,26 @@ test_expect_success 'rebase exec modifies rebase-todo' '
        test -e F
 '
 
+test_expect_failure SHA1 'loose object cache vs re-reading todo list' '
+       GIT_REBASE_TODO=.git/rebase-merge/git-rebase-todo &&
+       export GIT_REBASE_TODO &&
+       write_script append-todo.sh <<-\EOS &&
+       # For values 5 and 6, this yields SHA-1s with the same first two digits
+       echo "pick $(git rev-parse --short \
+               $(printf "%s\\n" \
+                       "tree $EMPTY_TREE" \
+                       "author A U Thor <author@example.org> $1 +0000" \
+                       "committer A U Thor <author@example.org> $1 +0000" \
+                       "" \
+                       "$1" |
+                 git hash-object -t commit -w --stdin))" >>$GIT_REBASE_TODO
+
+       shift
+       test -z "$*" ||
+       echo "exec $0 $*" >>$GIT_REBASE_TODO
+       EOS
+
+       git rebase HEAD -x "./append-todo.sh 5 6"
+'
+
 test_done