Merge branch 'jk/maint-reflog-bottom' into maint
[gitweb.git] / contrib / examples / git-merge.sh
index 410fa3c815680c3f9894b82bfa43545da91c75cb..7b922c39480c8b78d0687cbabac59672f9ae6ede 100755 (executable)
@@ -15,6 +15,8 @@ log                  add list of one-line log to merge commit message
 squash               create a single commit instead of doing a merge
 commit               perform a commit if the merge succeeds (default)
 ff                   allow fast-forward (default)
+ff-only              abort if fast-forward is not possible
+rerere-autoupdate    update index with any reused conflict resolution
 s,strategy=          merge strategy to use
 X=                   option for selected merge strategy
 m,message=           message to be used for the merge commit (if any)
@@ -45,12 +47,13 @@ use_strategies=
 xopt=
 
 allow_fast_forward=t
+fast_forward_only=
 allow_trivial_merge=t
-squash= no_commit= log_arg=
+squash= no_commit= log_arg= rr_arg=
 
 dropsave() {
        rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" \
-                "$GIT_DIR/MERGE_STASH" || exit 1
+                "$GIT_DIR/MERGE_STASH" "$GIT_DIR/MERGE_MODE" || exit 1
 }
 
 savestate() {
@@ -146,13 +149,15 @@ merge_name () {
        if found_ref=$(git rev-parse --symbolic-full-name --verify \
                                                        "$remote" 2>/dev/null)
        then
+               expanded=$(git check-ref-format --branch "$remote") ||
+                       exit
                if test "${found_ref#refs/heads/}" != "$found_ref"
                then
-                       echo "$rh               branch '$remote' of ."
+                       echo "$rh               branch '$expanded' of ."
                        return
                elif test "${found_ref#refs/remotes/}" != "$found_ref"
                then
-                       echo "$rh               remote branch '$remote' of ."
+                       echo "$rh               remote branch '$expanded' of ."
                        return
                fi
        fi
@@ -189,7 +194,15 @@ parse_config () {
                --no-ff)
                        test "$squash" != t ||
                                die "You cannot combine --squash with --no-ff."
+                       test "$fast_forward_only" != t ||
+                               die "You cannot combine --ff-only with --no-ff."
                        allow_fast_forward=f ;;
+               --ff-only)
+                       test "$allow_fast_forward" != f ||
+                               die "You cannot combine --ff-only with --no-ff."
+                       fast_forward_only=t ;;
+               --rerere-autoupdate|--no-rerere-autoupdate)
+                       rr_arg=$1 ;;
                -s|--strategy)
                        shift
                        case " $all_strategies " in
@@ -412,8 +425,8 @@ t,1,"$head",*)
        # We are not doing octopus, not fast-forward, and have only
        # one common.
        git update-index --refresh 2>/dev/null
-       case "$allow_trivial_merge" in
-       t)
+       case "$allow_trivial_merge,$fast_forward_only" in
+       t,)
                # See if it is really trivial.
                git var GIT_COMMITTER_IDENT >/dev/null || exit
                echo "Trying really trivial in-index merge..."
@@ -452,6 +465,11 @@ t,1,"$head",*)
        ;;
 esac
 
+if test "$fast_forward_only" = t
+then
+       die "Not possible to fast-forward, aborting."
+fi
+
 # We are going to make a new commit.
 git var GIT_COMMITTER_IDENT >/dev/null || exit
 
@@ -572,7 +590,15 @@ else
        do
                echo $remote
        done >"$GIT_DIR/MERGE_HEAD"
-       printf '%s\n' "$merge_msg" >"$GIT_DIR/MERGE_MSG"
+       printf '%s\n' "$merge_msg" >"$GIT_DIR/MERGE_MSG" ||
+               die "Could not write to $GIT_DIR/MERGE_MSG"
+       if test "$allow_fast_forward" != t
+       then
+               printf "%s" no-ff
+       else
+               :
+       fi >"$GIT_DIR/MERGE_MODE" ||
+               die "Could not write to $GIT_DIR/MERGE_MODE"
 fi
 
 if test "$merge_was_ok" = t
@@ -589,6 +615,6 @@ Conflicts:
                sed -e 's/^[^   ]*      /       /' |
                uniq
        } >>"$GIT_DIR/MERGE_MSG"
-       git rerere
+       git rerere $rr_arg
        die "Automatic merge failed; fix conflicts and then commit the result."
 fi