]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git-am.sh
fmt-merge-msg: add '--(no-)log' options and 'merge.log' config variable
[thirdparty/git.git] / git-am.sh
index 65c634f77af98b3598bfb50583de05f0cf5d6eb4..ac5c388060789e559f80d61d6eae1db926b66ad4 100755 (executable)
--- a/git-am.sh
+++ b/git-am.sh
@@ -2,29 +2,33 @@
 #
 # Copyright (c) 2005, 2006 Junio C Hamano
 
+SUBDIRECTORY_OK=Yes
 OPTIONS_KEEPDASHDASH=
 OPTIONS_SPEC="\
 git-am [options] <mbox>|<Maildir>...
 git-am [options] --resolved
 git-am [options] --skip
 --
-d,dotest=       use <dir> and not .dotest
+d,dotest=       (removed -- do not use)
 i,interactive   run interactively
 b,binary        pass --allo-binary-replacement to git-apply
 3,3way          allow fall back on 3way merging if needed
 s,signoff       add a Signed-off-by line to the commit message
 u,utf8          recode into utf8 (default)
-k,keep          pass -k flagg to git-mailinfo
+k,keep          pass -k flag to git-mailinfo
 whitespace=     pass it through git-apply
 C=              pass it through git-apply
 p=              pass it through git-apply
 resolvemsg=     override error message when patch failure occurs
 r,resolved      to be used after a patch failure
-skip            skip the current patch"
+skip            skip the current patch
+rebasing        (internal use for git-rebase)"
 
 . git-sh-setup
+prefix=$(git rev-parse --show-prefix)
 set_reflog_action am
 require_work_tree
+cd_to_toplevel
 
 git var GIT_COMMITTER_IDENT >/dev/null || exit
 
@@ -47,10 +51,6 @@ stop_here_user_resolve () {
     then
         cmdline="$cmdline -3"
     fi
-    if test '.dotest' != "$dotest"
-    then
-        cmdline="$cmdline -d=$dotest"
-    fi
     echo "When you have resolved this problem run \"$cmdline --resolved\"."
     echo "If you would prefer to skip this patch, instead run \"$cmdline --skip\"."
 
@@ -122,7 +122,8 @@ reread_subject () {
 }
 
 prec=4
-dotest=.dotest sign= utf8=t keep= skip= interactive= resolved= binary=
+dotest=".dotest"
+sign= utf8=t keep= skip= interactive= resolved= binary= rebasing=
 resolvemsg= resume=
 git_apply_opt=
 
@@ -147,8 +148,11 @@ do
                resolved=t ;;
        --skip)
                skip=t ;;
+       --rebasing)
+               rebasing=t threeway=t keep=t binary=t ;;
        -d|--dotest)
-               shift; dotest=$1;;
+               die "-d option is no longer supported.  Do not use."
+               ;;
        --resolvemsg)
                shift; resolvemsg=$1 ;;
        --whitespace)
@@ -184,7 +188,7 @@ then
        0,)
                # No file input but without resume parameters; catch
                # user error to feed us a patch from standard input
-               # when there is already .dotest.  This is somewhat
+               # when there is already $dotest.  This is somewhat
                # unreliable -- stdin could be /dev/null for example
                # and the caller did not intend to feed us a patch but
                # wanted to continue unattended.
@@ -204,6 +208,24 @@ else
        # Start afresh.
        mkdir -p "$dotest" || exit
 
+       if test -n "$prefix" && test $# != 0
+       then
+               first=t
+               for arg
+               do
+                       test -n "$first" && {
+                               set x
+                               first=
+                       }
+                       case "$arg" in
+                       /*)
+                               set "$@" "$arg" ;;
+                       *)
+                               set "$@" "$prefix$arg" ;;
+                       esac
+               done
+               shift
+       fi
        git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" ||  {
                rm -fr "$dotest"
                exit 1
@@ -218,6 +240,12 @@ else
        echo "$utf8" >"$dotest/utf8"
        echo "$keep" >"$dotest/keep"
        echo 1 >"$dotest/next"
+       if test -n "$rebasing"
+       then
+               : >"$dotest/rebasing"
+       else
+               : >"$dotest/applying"
+       fi
 fi
 
 case "$resolved" in
@@ -329,7 +357,7 @@ do
                LAST_SIGNED_OFF_BY=`
                    sed -ne '/^Signed-off-by: /p' \
                    "$dotest/msg-clean" |
-                   tail -n 1
+                   sed -ne '$p'
                `
                ADD_SIGNOFF=`
                    test "$LAST_SIGNED_OFF_BY" = "$SIGNOFF" || {
@@ -469,9 +497,9 @@ do
                "$GIT_DIR"/hooks/post-applypatch
        fi
 
-       git gc --auto
-
        go_next
 done
 
+git gc --auto
+
 rm -fr "$dotest"