Code

clean up pathspec matching
[git.git] / git-rebase--interactive.sh
index 1172e47571dfe1d6dd088381d63045fd5eae3db3..8ed2244819d0950ddf1ffaa151b4d46bdc8b6db4 100755 (executable)
@@ -115,9 +115,18 @@ mark_action_done () {
 }
 
 make_patch () {
-       parent_sha1=$(git rev-parse --verify "$1"^) ||
-               die "Cannot get patch for $1^"
-       git diff-tree -p "$parent_sha1".."$1" > "$DOTEST"/patch
+       sha1_and_parents="$(git rev-list --parents -1 "$1")"
+       case "$sha1_and_parents" in
+       ?*' '?*' '?*)
+               git diff --cc $sha1_and_parents
+               ;;
+       ?*' '?*)
+               git diff-tree -p "$1^!"
+               ;;
+       *)
+               echo "Root commit"
+               ;;
+       esac > "$DOTEST"/patch
        test -f "$DOTEST"/message ||
                git cat-file commit "$1" | sed "1,/^$/d" > "$DOTEST"/message
        test -f "$DOTEST"/author-script ||
@@ -256,9 +265,8 @@ pick_one_preserving_merges () {
                                output git merge $STRATEGY -m "$msg" \
                                        $new_parents
                        then
-                               git rerere
                                printf "%s\n" "$msg" > "$GIT_DIR"/MERGE_MSG
-                               die Error redoing merge $sha1
+                               die_with_patch $sha1 "Error redoing merge $sha1"
                        fi
                        ;;
                *)
@@ -341,7 +349,7 @@ do_next () {
        squash|s)
                comment_for_reflog squash
 
-               has_action "$DONE" ||
+               test -f "$DONE" && has_action "$DONE" ||
                        die "Cannot 'squash' without a previous commit"
 
                mark_action_done