Revert "Convert git-annotate to use Git.pm"
[gitweb.git] / git-merge.sh
index af1f25b3c51d197ea5fd24b7623dfb591f867133..a9cfafb1dfba6e85834a33caf6b3c69910594bf6 100755 (executable)
@@ -3,8 +3,7 @@
 # Copyright (c) 2005 Junio C Hamano
 #
 
-
-USAGE='[-n] [--no-commit] [-s <strategy>]... <merge-message> <head> <remote>+'
+USAGE='[-n] [--no-commit] [--squash] [-s <strategy>]... <merge-message> <head> <remote>+'
 . git-sh-setup
 
 LF='
@@ -42,30 +41,68 @@ restorestate() {
        fi
 }
 
-finish () {
-       test '' = "$2" || echo "$2"
-       case "$merge_msg" in
+finish_up_to_date () {
+       case "$squash" in
+       t)
+               echo "$1 (nothing to squash)" ;;
        '')
-               echo "No merge message -- not updating HEAD"
+               echo "$1" ;;
+       esac
+       dropsave
+}
+
+squash_message () {
+       echo Squashed commit of the following:
+       echo
+       git-log --no-merges ^"$head" $remote
+}
+
+finish () {
+       if test '' = "$2"
+       then
+               rlogm="$rloga"
+       else
+               echo "$2"
+               rlogm="$rloga: $2"
+       fi
+       case "$squash" in
+       t)
+               echo "Squash commit -- not updating HEAD"
+               squash_message >"$GIT_DIR/SQUASH_MSG"
                ;;
-       *)
-               git-update-ref HEAD "$1" "$head" || exit 1
+       '')
+               case "$merge_msg" in
+               '')
+                       echo "No merge message -- not updating HEAD"
+                       ;;
+               *)
+                       git-update-ref -m "$rlogm" HEAD "$1" "$head" || exit 1
+                       ;;
+               esac
                ;;
        esac
-
-       case "$no_summary" in
+       case "$1" in
        '')
-               git-diff-tree -p --stat --summary -M "$head" "$1"
+               ;;
+       ?*)
+               case "$no_summary" in
+               '')
+                       git-diff-tree --stat --summary -M "$head" "$1"
+                       ;;
+               esac
                ;;
        esac
 }
 
+rloga=
 while case "$#" in 0) break ;; esac
 do
        case "$1" in
        -n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
                --no-summa|--no-summar|--no-summary)
                no_summary=t ;;
+       --sq|--squ|--squa|--squas|--squash)
+               squash=t no_commit=t ;;
        --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
                no_commit=t ;;
        -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
@@ -73,7 +110,7 @@ do
        -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
                case "$#,$1" in
                *,*=*)
-                       strategy=`expr "$1" : '-[^=]*=\(.*\)'` ;;
+                       strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;;
                1,*)
                        usage ;;
                *)
@@ -87,6 +124,9 @@ do
                        die "available strategies are: $all_strategies" ;;
                esac
                ;;
+       --reflog-action=*)
+               rloga=`expr "z$1" : 'z-[^=]*=\(.*\)'`
+               ;;
        -*)     usage ;;
        *)      break ;;
        esac
@@ -101,6 +141,7 @@ shift
 
 # All the rest are remote heads
 test "$#" = 0 && usage ;# we need at least one remote head.
+test "$rloga" = '' && rloga="merge: $@"
 
 remoteheads=
 for remote
@@ -152,8 +193,7 @@ f,*)
 ?,1,"$1",*)
        # If head can reach all the merge then we are up to date.
        # but first the most common case of merging one remote.
-       echo "Already up-to-date."
-       dropsave
+       finish_up_to_date "Already up-to-date."
        exit 0
        ;;
 ?,1,"$head",*)
@@ -205,8 +245,7 @@ f,*)
        done
        if test "$up_to_date" = t
        then
-               echo "Already up-to-date. Yeeah!"
-               dropsave
+               finish_up_to_date "Already up-to-date. Yeeah!"
                exit 0
        fi
        ;;
@@ -288,7 +327,7 @@ if test '' != "$result_tree"
 then
     parents=$(git-show-branch --independent "$head" "$@" | sed -e 's/^/-p /')
     result_commit=$(echo "$merge_msg" | git-commit-tree $result_tree $parents) || exit
-    finish "$result_commit" "Merge $result_commit, made by $wt_strategy."
+    finish "$result_commit" "Merge made by $wt_strategy."
     dropsave
     exit 0
 fi
@@ -310,11 +349,17 @@ case "$best_strategy" in
        git-merge-$best_strategy $common -- "$head_arg" "$@"
        ;;
 esac
-for remote
-do
-       echo $remote
-done >"$GIT_DIR/MERGE_HEAD"
-echo "$merge_msg" >"$GIT_DIR/MERGE_MSG"
+
+if test "$squash" = t
+then
+       finish
+else
+       for remote
+       do
+               echo $remote
+       done >"$GIT_DIR/MERGE_HEAD"
+       echo "$merge_msg" >"$GIT_DIR/MERGE_MSG"
+fi
 
 if test "$merge_was_ok" = t
 then