X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-am.sh;h=d64d9975358a6b9a18596c45b13434463903a344;hb=58b1ef2f0fce75ebf4fbf88e5bdf76a0afaeacce;hp=0ff1f577a33ccc96adfbb14fa35adfeee9e309f5;hpb=c574e683b587ee3c302317e4fa9c83cd4605cd82;p=git.git diff --git a/git-am.sh b/git-am.sh index 0ff1f577a..d64d99753 100755 --- a/git-am.sh +++ b/git-am.sh @@ -11,6 +11,7 @@ git am [options] (--resolved | --skip | --abort) i,interactive run interactively b,binary* (historical option -- no-op) 3,3way allow fall back on 3way merging if needed +q,quiet be quiet 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 @@ -100,7 +101,7 @@ fall_back_3way () { git write-tree >"$dotest/patch-merge-base+" || cannot_fallback "Repository lacks necessary blobs to fall back on 3-way merge." - echo Using index info to reconstruct a base tree... + say Using index info to reconstruct a base tree... if GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \ git apply --cached <"$dotest/patch" then @@ -116,7 +117,7 @@ It does not apply to blobs recorded in its index." orig_tree=$(cat "$dotest/patch-merge-base") && rm -fr "$dotest"/patch-merge-* || exit 1 - echo Falling back to patching base and 3-way merge... + say Falling back to patching base and 3-way merge... # This is not so wrong. Depending on which base we picked, # orig_tree may be wildly different from ours, but his_tree @@ -126,6 +127,10 @@ It does not apply to blobs recorded in its index." eval GITHEAD_$his_tree='"$FIRSTLINE"' export GITHEAD_$his_tree + if test -n "$GIT_QUIET" + then + export GIT_MERGE_VERBOSITY=0 + fi git-merge-recursive $orig_tree -- HEAD $his_tree || { git rerere echo Failed to merge in the changes. @@ -134,6 +139,12 @@ It does not apply to blobs recorded in its index." unset GITHEAD_$his_tree } +clean_abort () { + test $# = 0 || echo >&2 "$@" + rm -fr "$dotest" + exit 1 +} + patch_format= check_patch_format () { @@ -180,22 +191,19 @@ check_patch_format () { esac ;; esac - } < "$1" + } < "$1" || clean_abort } split_patches () { case "$patch_format" in mbox) - git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || { - rm -fr "$dotest" - exit 1 - } + git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || + clean_abort ;; stgit-series) if test $# -ne 1 then - echo "Only one StGIT patch series can be applied at once" - exit 1 + clean_abort "Only one StGIT patch series can be applied at once" fi series_dir=`dirname "$1"` series_file="$1" @@ -210,7 +218,7 @@ split_patches () { shift # remove the arg coming from the first-line comment shift - } < "$series_file" + } < "$series_file" || clean_abort # set the patch format appropriately patch_format=stgit # now handle the actual StGIT patches @@ -239,18 +247,14 @@ split_patches () { print "Subject: ", $_ ; $subject = 1; } - ' < "$stgit" > "$dotest/$msgnum" || { - echo "Failed to import $patch_format patch $stgit" - exit 1 - } + ' < "$stgit" > "$dotest/$msgnum" || clean_abort done echo "$this" > "$dotest/last" this= msgnum= ;; *) - echo "Patch format $patch_format is not supported." - exit 1 + clean_abort "Patch format $patch_format is not supported." ;; esac } @@ -305,6 +309,8 @@ do committer_date_is_author_date=t ;; --ignore-date) ignore_date=t ;; + -q|--quiet) + GIT_QUIET=t ;; --) shift; break ;; *) @@ -403,7 +409,7 @@ else split_patches "$@" - # -s, -u, -k, --whitespace, -3, -C and -p flags are kept + # -s, -u, -k, --whitespace, -3, -C, -q 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" @@ -411,6 +417,7 @@ else echo "$sign" >"$dotest/sign" echo "$utf8" >"$dotest/utf8" echo "$keep" >"$dotest/keep" + echo "$GIT_QUIET" >"$dotest/quiet" echo 1 >"$dotest/next" if test -n "$rebasing" then @@ -451,6 +458,10 @@ if test "$(cat "$dotest/keep")" = t then keep=-k fi +if test "$(cat "$dotest/quiet")" = t +then + GIT_QUIET=t +fi if test "$(cat "$dotest/threeway")" = t then threeway=t @@ -476,7 +487,7 @@ fi if test "$this" -gt "$last" then - echo Nothing to do. + say Nothing to do. rm -fr "$dotest" exit fi @@ -622,11 +633,18 @@ do stop_here $this fi - printf 'Applying: %s\n' "$FIRSTLINE" + say "Applying: $FIRSTLINE" case "$resolved" in '') - eval 'git apply '"$git_apply_opt"' --index "$dotest/patch"' + # When we are allowed to fall back to 3-way later, don't give + # false errors during the initial attempt. + squelch= + if test "$threeway" = t + then + squelch='>/dev/null 2>&1 ' + fi + eval "git apply $squelch$git_apply_opt"' --index "$dotest/patch"' apply_status=$? ;; t) @@ -658,7 +676,7 @@ do # Applying the patch to an earlier tree and merging the # result may have produced the same tree as ours. git diff-index --quiet --cached HEAD -- && { - echo No changes -- Patch already applied. + say No changes -- Patch already applied. go_next continue } @@ -684,7 +702,7 @@ do GIT_AUTHOR_DATE= fi parent=$(git rev-parse --verify -q HEAD) || - echo >&2 "applying to an empty history" + say >&2 "applying to an empty history" if test -n "$committer_date_is_author_date" then