156
157
These lines can be re-ordered; they are executed from top to bottom.
158
159
+EOF
160
+ if test $(get_missing_commit_check_level) = error
161
+ then
162
+ git stripspace --comment-lines >>"$todo" <<\EOF
163
+Do not remove any line. Use 'drop' explicitly to remove a commit.
164
+EOF
165
+ else
166
+ git stripspace --comment-lines >>"$todo" <<\EOF
167
If you remove a line here THAT COMMIT WILL BE LOST.
168
EOF
169
+ fi
170
}
171
172
make_patch () {
846
mv "$1.new" "$1"
847
}
848
849
+# Print the list of the SHA-1 of the commits
850
+# from stdin to stdout
851
+todo_list_to_sha_list () {
852
+ git stripspace --strip-comments |
853
+ while read -r command sha1 rest
854
+ do
855
+ case $command in
856
+ "$comment_char"*|''|noop|x|"exec")
857
+ ;;
858
+ *)
859
+ long_sha=$(git rev-list --no-walk "$sha1" 2>/dev/null)
860
+ printf "%s\n" "$long_sha"
861
+ ;;
862
+ esac
863
+ done
864
+}
865
+
866
+# Use warn for each line in stdin
867
+warn_lines () {
868
+ while read -r line
869
+ do
870
+ warn " - $line"
871
+ done
872
+}
873
+
874
+# Switch to the branch in $into and notify it in the reflog
875
+checkout_onto () {
876
+ GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name"
877
+ output git checkout $onto || die_abort "could not detach HEAD"
878
+ git update-ref ORIG_HEAD $orig_head
879
+}
880
+
881
+get_missing_commit_check_level () {
882
+ check_level=$(git config --get rebase.missingCommitsCheck)
883
+ check_level=${check_level:-ignore}
884
+ # Don't be case sensitive
885
+ printf '%s' "$check_level" | tr 'A-Z' 'a-z'
886
+}
887
+
888
+# Check if the user dropped some commits by mistake
889
+# Behaviour determined by rebase.missingCommitsCheck.
890
+check_todo_list () {
891
+ raise_error=f
892
+
893
+ check_level=$(get_missing_commit_check_level)
894
+
895
+ case "$check_level" in
896
+ warn|error)
897
+ # Get the SHA-1 of the commits
898
+ todo_list_to_sha_list <"$todo".backup >"$todo".oldsha1
899
+ todo_list_to_sha_list <"$todo" >"$todo".newsha1
900
+
901
+ # Sort the SHA-1 and compare them
902
+ sort -u "$todo".oldsha1 >"$todo".oldsha1+
903
+ mv "$todo".oldsha1+ "$todo".oldsha1
904
+ sort -u "$todo".newsha1 >"$todo".newsha1+
905
+ mv "$todo".newsha1+ "$todo".newsha1
906
+ comm -2 -3 "$todo".oldsha1 "$todo".newsha1 >"$todo".miss
907
+
908
+ # Warn about missing commits
909
+ if test -s "$todo".miss
910
+ then
911
+ test "$check_level" = error && raise_error=t
912
+
913
+ warn "Warning: some commits may have been dropped" \
914
+ "accidentally."
915
+ warn "Dropped commits (newer to older):"
916
+
917
+ # Make the list user-friendly and display
918
+ opt="--no-walk=sorted --format=oneline --abbrev-commit --stdin"
919
+ git rev-list $opt <"$todo".miss | warn_lines
920
+
921
+ warn "To avoid this message, use \"drop\" to" \
922
+ "explicitly remove a commit."
923
+ warn
924
+ warn "Use 'git config rebase.missingCommitsCheck' to change" \
925
+ "the level of warnings."
926
+ warn "The possible behaviours are: ignore, warn, error."
927
+ warn
928
+ fi
929
+ ;;
930
+ ignore)
931
+ ;;
932
+ *)
933
+ warn "Unrecognized setting $check_level for option" \
934
+ "rebase.missingCommitsCheck. Ignoring."
935
+ ;;
936
+ esac
937
+
938
+ if test $raise_error = t
939
+ then
940
+ # Checkout before the first commit of the
941
+ # rebase: this way git rebase --continue
942
+ # will work correctly as it expects HEAD to be
943
+ # placed before the commit of the next action
944
+ checkout_onto
945
+
946
+ warn "You can fix this with 'git rebase --edit-todo'."
947
+ die "Or you can abort the rebase with 'git rebase --abort'."
948
+ fi
949
+}
950
+
951
# The whole contents of this file is run by dot-sourcing it from
952
# inside a shell function. It used to be that "return"s we see
953
# below were not inside any function, and expected to return
1188
has_action "$todo" ||
1189
return 2
1190
1191
+check_todo_list
1192
+
1193
expand_todo_ids
1194
1195
test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks
1196
1084
-GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name"
1085
-output git checkout $onto || die_abort "could not detach HEAD"
1086
-git update-ref ORIG_HEAD $orig_head
1197
+checkout_onto
1198
do_rest
1199
1200
}