]> asedeno.scripts.mit.edu Git - git.git/blobdiff - git-am.sh
Merge branch 'ks/maint-mailinfo-folded'
[git.git] / git-am.sh
index 1bf70d47779aeddd281895bc5523ed66a549da99..b598b4332a6224bb5c8363afdcff7cb9a3f3dbcd 100755 (executable)
--- a/git-am.sh
+++ b/git-am.sh
@@ -8,21 +8,22 @@ OPTIONS_SPEC="\
 git am [options] [<mbox>|<Maildir>...]
 git am [options] (--resolved | --skip | --abort)
 --
-d,dotest=       (removed -- do not use)
 i,interactive   run interactively
-b,binary        (historical option -- no-op)
+b,binary*       (historical option -- no-op)
 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 flag to git-mailinfo
 whitespace=     pass it through git-apply
+directory=      pass it through git-apply
 C=              pass it through git-apply
 p=              pass it through git-apply
+reject          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
 abort           restore the original branch and abort the patching operation.
-rebasing        (internal use for git-rebase)"
+rebasing*       (internal use for git-rebase)"
 
 . git-sh-setup
 prefix=$(git rev-parse --show-prefix)
@@ -33,6 +34,14 @@ cd_to_toplevel
 git var GIT_COMMITTER_IDENT >/dev/null ||
        die "You need to set your committer info first"
 
+sq () {
+       for sqarg
+       do
+               printf "%s" "$sqarg" |
+               sed -e 's/'\''/'\''\\'\'''\''/g' -e 's/.*/ '\''&'\''/'
+       done
+}
+
 stop_here () {
     echo "$1" >"$dotest/next"
     exit 1
@@ -121,7 +130,7 @@ It does not apply to blobs recorded in its index."
 
 prec=4
 dotest="$GIT_DIR/rebase-apply"
-sign= utf8=t keep= skip= interactive= resolved= rebasing= abort= ws=
+sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
 resolvemsg= resume=
 git_apply_opt=
 
@@ -155,10 +164,12 @@ do
                ;;
        --resolvemsg)
                shift; resolvemsg=$1 ;;
-       --whitespace)
-               ws="--whitespace=$2"; shift ;;
+       --whitespace|--directory)
+               git_apply_opt="$git_apply_opt $(sq "$1=$2")"; shift ;;
        -C|-p)
-               git_apply_opt="$git_apply_opt $1$2"; shift ;;
+               git_apply_opt="$git_apply_opt $(sq "$1$2")"; shift ;;
+       --reject)
+               git_apply_opt="$git_apply_opt $1" ;;
        --)
                shift; break ;;
        *)
@@ -192,7 +203,7 @@ then
                # unreliable -- stdin could be /dev/null for example
                # and the caller did not intend to feed us a patch but
                # wanted to continue unattended.
-               tty -s
+               test -t 0
                ;;
        *)
                false
@@ -247,10 +258,11 @@ else
                exit 1
        }
 
-       # -s, -u, -k and --whitespace flags are kept for the
-       # resuming session after a patch failure.
-       # -3 and -i can and must be given when resuming.
-       echo " $ws" >"$dotest/whitespace"
+       # -s, -u, -k, --whitespace, -3, -C and -p flags are kept
+       # for the resuming session after a patch failure.
+       # -i can and must be given when resuming.
+       echo " $git_apply_opt" >"$dotest/apply-opt"
+       echo "$threeway" >"$dotest/threeway"
        echo "$sign" >"$dotest/sign"
        echo "$utf8" >"$dotest/utf8"
        echo "$keep" >"$dotest/keep"
@@ -267,10 +279,7 @@ fi
 case "$resolved" in
 '')
        files=$(git diff-index --cached --name-only HEAD --) || exit
-       if [ "$files" ]; then
-          echo "Dirty index: cannot apply patches (dirty: $files)" >&2
-          exit 1
-       fi
+       test "$files" && die "Dirty index: cannot apply patches (dirty: $files)"
 esac
 
 if test "$(cat "$dotest/utf8")" = t
@@ -283,7 +292,11 @@ if test "$(cat "$dotest/keep")" = t
 then
        keep=-k
 fi
-ws=$(cat "$dotest/whitespace")
+if test "$(cat "$dotest/threeway")" = t
+then
+       threeway=t
+fi
+git_apply_opt=$(cat "$dotest/apply-opt")
 if test "$(cat "$dotest/sign")" = t
 then
        SIGNOFF=`git var GIT_COMMITTER_IDENT | sed -e '
@@ -454,7 +467,7 @@ do
 
        case "$resolved" in
        '')
-               git apply $git_apply_opt $ws --index "$dotest/patch"
+               eval 'git apply '"$git_apply_opt"' --index "$dotest/patch"'
                apply_status=$?
                ;;
        t)
@@ -496,7 +509,7 @@ do
        fi
        if test $apply_status != 0
        then
-               echo Patch failed at $msgnum.
+               printf 'Patch failed at %s %s\n' "$msgnum" "$FIRSTLINE"
                stop_here_user_resolve $this
        fi