Skip to content

Commit f8a3fd2

Browse files
committed
Merge branch 'es/rebase-i-no-abbrev' into maint
* es/rebase-i-no-abbrev: rebase -i: fix short SHA-1 collision t3404: rebase -i: demonstrate short SHA-1 collision t3404: make tests more self-contained Conflicts: t/t3404-rebase-interactive.sh
2 parents 9a3a02b + 75c6976 commit f8a3fd2

File tree

2 files changed

+117
-2
lines changed

2 files changed

+117
-2
lines changed

git-rebase--interactive.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,32 @@ skip_unnecessary_picks () {
690690
die "Could not skip unnecessary pick commands"
691691
}
692692

693+
transform_todo_ids () {
694+
while read -r command rest
695+
do
696+
case "$command" in
697+
"$comment_char"* | exec)
698+
# Be careful for oddball commands like 'exec'
699+
# that do not have a SHA-1 at the beginning of $rest.
700+
;;
701+
*)
702+
sha1=$(git rev-parse --verify --quiet "$@" ${rest%% *}) &&
703+
rest="$sha1 ${rest#* }"
704+
;;
705+
esac
706+
printf '%s\n' "$command${rest:+ }$rest"
707+
done <"$todo" >"$todo.new" &&
708+
mv -f "$todo.new" "$todo"
709+
}
710+
711+
expand_todo_ids() {
712+
transform_todo_ids
713+
}
714+
715+
collapse_todo_ids() {
716+
transform_todo_ids --short=7
717+
}
718+
693719
# Rearrange the todo list that has both "pick sha1 msg" and
694720
# "pick sha1 fixup!/squash! msg" appears in it so that the latter
695721
# comes immediately after the former, and change "pick" to
@@ -842,6 +868,7 @@ skip)
842868
edit-todo)
843869
git stripspace --strip-comments <"$todo" >"$todo".new
844870
mv -f "$todo".new "$todo"
871+
collapse_todo_ids
845872
append_todo_help
846873
git stripspace --comment-lines >>"$todo" <<\EOF
847874
@@ -853,6 +880,7 @@ EOF
853880

854881
git_sequence_editor "$todo" ||
855882
die "Could not execute editor"
883+
expand_todo_ids
856884

857885
exit
858886
;;
@@ -1009,6 +1037,8 @@ git_sequence_editor "$todo" ||
10091037
has_action "$todo" ||
10101038
die_abort "Nothing to do"
10111039

1040+
expand_todo_ids
1041+
10121042
test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks
10131043

10141044
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name"

0 commit comments

Comments
 (0)