Merge branch 'maint'
[gitweb.git] / git-mergetool.sh
index b52a7410bcb7b37dce0f4d6213dddedd2c1e42e7..2f8dc441c6d575323f2fad920ecdb7b20e1445e6 100755 (executable)
@@ -264,24 +264,46 @@ merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo fa
 
 last_status=0
 rollup_status=0
+rerere=false
+
+files_to_merge() {
+    if test "$rerere" = true
+    then
+       git rerere status
+    else
+       git ls-files -u | sed -e 's/^[^ ]*      //' | sort -u
+    fi
+}
+
 
 if test $# -eq 0 ; then
-    files=$(git ls-files -u | sed -e 's/^[^    ]*      //' | sort -u)
+    cd_to_toplevel
+
+    if test -e "$GIT_DIR/MERGE_RR"
+    then
+       rerere=true
+    fi
+
+    files=$(files_to_merge)
     if test -z "$files" ; then
        echo "No files need merging"
        exit 0
     fi
-    echo Merging the files: "$files"
-    git ls-files -u |
-    sed -e 's/^[^      ]*      //' |
-    sort -u |
+
+    # Save original stdin
+    exec 3<&0
+
+    printf "Merging:\n"
+    printf "$files\n"
+
+    files_to_merge |
     while IFS= read i
     do
        if test $last_status -ne 0; then
-           prompt_after_failed_merge < /dev/tty || exit 1
+           prompt_after_failed_merge <&3 || exit 1
        fi
        printf "\n"
-       merge_file "$i" < /dev/tty > /dev/tty
+       merge_file "$i" <&3
        last_status=$?
        if test $last_status -ne 0; then
            rollup_status=1