Skip to content

Commit

Permalink
rebase -i: also avoid SHA-1 collisions with missingCommitsCheck
Browse files Browse the repository at this point in the history
When `rebase.missingCommitsCheck` is in effect, we use the backup of the
todo list that was copied just before the user was allowed to edit it.

That backup is, of course, just as susceptible to the hash collision as
the todo list itself: a reworded commit could make a previously
unambiguous short commit ID ambiguous all of a sudden.

So let's not just copy the todo list, but let's instead write out the
backup with expanded commit IDs.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
dscho authored and gitster committed Jan 23, 2020
1 parent b699226 commit 2602762
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions rebase-interactive.c
Expand Up @@ -104,9 +104,11 @@ int edit_todo_list(struct repository *r, struct todo_list *todo_list,
-1, flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP))
return error_errno(_("could not write '%s'"), todo_file);

if (initial && copy_file(rebase_path_todo_backup(), todo_file, 0666))
return error(_("could not copy '%s' to '%s'."), todo_file,
rebase_path_todo_backup());
if (initial &&
todo_list_write_to_file(r, todo_list, rebase_path_todo_backup(),
shortrevisions, shortonto, -1,
(flags | TODO_LIST_APPEND_TODO_HELP) & ~TODO_LIST_SHORTEN_IDS) < 0)
return error(_("could not write '%s'."), rebase_path_todo_backup());

if (launch_sequence_editor(todo_file, &new_todo->buf, NULL))
return -2;
Expand Down
2 changes: 2 additions & 0 deletions t/t3404-rebase-interactive.sh
Expand Up @@ -1277,6 +1277,8 @@ test_expect_success SHA1 'short SHA-1 collide' '
.git/rebase-merge/git-rebase-todo.tmp &&
grep "^pick [0-9a-f]\{40\}" \
.git/rebase-merge/git-rebase-todo &&
grep "^pick [0-9a-f]\{40\}" \
.git/rebase-merge/git-rebase-todo.backup &&
git rebase --continue
) &&
collide2="$(git rev-parse HEAD~1 | cut -c 1-4)" &&
Expand Down

0 comments on commit 2602762

Please sign in to comment.