Skip to content

Commit 2602762

Browse files
dschogitster
authored andcommitted
rebase -i: also avoid SHA-1 collisions with missingCommitsCheck
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b699226 commit 2602762

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

rebase-interactive.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ int edit_todo_list(struct repository *r, struct todo_list *todo_list,
104104
-1, flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP))
105105
return error_errno(_("could not write '%s'"), todo_file);
106106

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

111113
if (launch_sequence_editor(todo_file, &new_todo->buf, NULL))
112114
return -2;

t/t3404-rebase-interactive.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,8 @@ test_expect_success SHA1 'short SHA-1 collide' '
12771277
.git/rebase-merge/git-rebase-todo.tmp &&
12781278
grep "^pick [0-9a-f]\{40\}" \
12791279
.git/rebase-merge/git-rebase-todo &&
1280+
grep "^pick [0-9a-f]\{40\}" \
1281+
.git/rebase-merge/git-rebase-todo.backup &&
12801282
git rebase --continue
12811283
) &&
12821284
collide2="$(git rev-parse HEAD~1 | cut -c 1-4)" &&

0 commit comments

Comments
 (0)