]> git.ipfire.org Git - thirdparty/git.git/commitdiff
am, rebase: teach quiet option
authorStephen Boyd <bebarino@gmail.com>
Tue, 16 Jun 2009 22:33:01 +0000 (15:33 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 18 Jun 2009 18:54:48 +0000 (11:54 -0700)
git-am and git-rebase are talkative scripts. Teach them to be quiet when
told, allowing them to speak only when they fail or experience errors.

The quiet option is maintained when git-am or git-rebase fails to apply
a patch. This means subsequent --resolved, --continue, --skip, --abort
invocations will be quiet if the original invocation was quiet.

Drop a handful of >&2 redirection; the rest of the program sends all the
info messages to stdout, not to stderr.

Signed-off-by: Stephen Boyd <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-am.txt
Documentation/git-rebase.txt
git-am.sh
git-rebase.sh
t/t3400-rebase.sh
t/t4150-am.sh

index 6d92cbee6475e29660d91a97683bf5843aacab38..32e689b2bf184464b0923c3bb88a209b9b28a022 100644 (file)
@@ -13,7 +13,7 @@ SYNOPSIS
         [--3way] [--interactive] [--committer-date-is-author-date]
         [--ignore-date]
         [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
-        [--reject]
+        [--reject] [-q | --quiet]
         [<mbox> | <Maildir>...]
 'git am' (--skip | --resolved | --abort)
 
@@ -39,6 +39,10 @@ OPTIONS
 --keep::
        Pass `-k` flag to 'git-mailinfo' (see linkgit:git-mailinfo[1]).
 
+-q::
+--quiet::
+       Be quiet. Only print error messages.
+
 -u::
 --utf8::
        Pass `-u` flag to 'git-mailinfo' (see linkgit:git-mailinfo[1]).
index 26f3b7b2b0daad0affb36e6514156520a693b164..db1b71d24846e4561d99bed095345eb9580b0632 100644 (file)
@@ -236,6 +236,10 @@ OPTIONS
        is used instead ('git-merge-recursive' when merging a single
        head, 'git-merge-octopus' otherwise).  This implies --merge.
 
+-q::
+--quiet::
+       Be quiet. Implies --no-stat.
+
 -v::
 --verbose::
        Be verbose. Implies --stat.
index e26c54a3e24265d26b6d7acb07d0bf89135bb4bc..58d4eb6d2dc2eaa99ae0c70a414813cd0ce43e43 100755 (executable)
--- 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
@@ -99,7 +100,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
@@ -115,7 +116,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
@@ -125,6 +126,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.
@@ -181,6 +186,8 @@ do
                committer_date_is_author_date=t ;;
        --ignore-date)
                ignore_date=t ;;
+       -q|--quiet)
+               GIT_QUIET=t ;;
        --)
                shift; break ;;
        *)
@@ -279,7 +286,7 @@ else
                exit 1
        }
 
-       # -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"
@@ -287,6 +294,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
@@ -327,6 +335,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
@@ -352,7 +364,7 @@ fi
 
 if test "$this" -gt "$last"
 then
-       echo Nothing to do.
+       say Nothing to do.
        rm -fr "$dotest"
        exit
 fi
@@ -498,7 +510,7 @@ do
                stop_here $this
        fi
 
-       printf 'Applying: %s\n' "$FIRSTLINE"
+       say "Applying: $FIRSTLINE"
 
        case "$resolved" in
        '')
@@ -541,7 +553,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
                    }
@@ -567,7 +579,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
index b83fd3f970161d9ca8a4212a0b335f784fc3ff84..84b5173f936f89ef7750cc9d5b9f6b041c8aef1f 100755 (executable)
@@ -3,7 +3,7 @@
 # Copyright (c) 2005 Junio C Hamano.
 #
 
-USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--onto <newbase>] [<upstream>|--root] [<branch>]'
+USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--onto <newbase>] [<upstream>|--root] [<branch>] [--quiet | -q]'
 LONG_USAGE='git-rebase replaces <branch> with a new branch of the
 same name.  When the --onto option is provided the new branch starts
 out with a HEAD equal to <newbase>, otherwise it is equal to <upstream>
@@ -72,11 +72,20 @@ continue_merge () {
                        echo "directly, but instead do one of the following: "
                        die "$RESOLVEMSG"
                fi
-               printf "Committed: %0${prec}d " $msgnum
+               if test -z "$GIT_QUIET"
+               then
+                       printf "Committed: %0${prec}d " $msgnum
+               fi
        else
-               printf "Already applied: %0${prec}d " $msgnum
+               if test -z "$GIT_QUIET"
+               then
+                       printf "Already applied: %0${prec}d " $msgnum
+               fi
+       fi
+       if test -z "$GIT_QUIET"
+       then
+               git rev-list --pretty=oneline -1 "$cmt" | sed -e 's/^[^ ]* //'
        fi
-       git rev-list --pretty=oneline -1 "$cmt" | sed -e 's/^[^ ]* //'
 
        prev_head=`git rev-parse HEAD^0`
        # save the resulting commit so we can read-tree on it later
@@ -97,6 +106,10 @@ call_merge () {
        eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
        eval GITHEAD_$hd='$(cat "$dotest/onto_name")'
        export GITHEAD_$cmt GITHEAD_$hd
+       if test -n "$GIT_QUIET"
+       then
+               export GIT_MERGE_VERBOSITY=1
+       fi
        git-merge-$strategy "$cmt^" -- "$hd" "$cmt"
        rv=$?
        case "$rv" in
@@ -138,7 +151,7 @@ move_to_original_branch () {
 finish_rb_merge () {
        move_to_original_branch
        rm -r "$dotest"
-       echo "All done."
+       say All done.
 }
 
 is_interactive () {
@@ -209,6 +222,7 @@ do
                        end=$(cat "$dotest/end")
                        msgnum=$(cat "$dotest/msgnum")
                        onto=$(cat "$dotest/onto")
+                       GIT_QUIET=$(cat "$dotest/quiet")
                        continue_merge
                        while test "$msgnum" -le "$end"
                        do
@@ -221,6 +235,7 @@ do
                head_name=$(cat "$GIT_DIR"/rebase-apply/head-name) &&
                onto=$(cat "$GIT_DIR"/rebase-apply/onto) &&
                orig_head=$(cat "$GIT_DIR"/rebase-apply/orig-head) &&
+               GIT_QUIET=$(cat "$GIT_DIR"/rebase-apply/quiet)
                git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
                move_to_original_branch
                exit
@@ -238,6 +253,7 @@ do
                        msgnum=$(cat "$dotest/msgnum")
                        msgnum=$(($msgnum + 1))
                        onto=$(cat "$dotest/onto")
+                       GIT_QUIET=$(cat "$dotest/quiet")
                        while test "$msgnum" -le "$end"
                        do
                                call_merge "$msgnum"
@@ -249,6 +265,7 @@ do
                head_name=$(cat "$GIT_DIR"/rebase-apply/head-name) &&
                onto=$(cat "$GIT_DIR"/rebase-apply/onto) &&
                orig_head=$(cat "$GIT_DIR"/rebase-apply/orig-head) &&
+               GIT_QUIET=$(cat "$GIT_DIR"/rebase-apply/quiet)
                git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
                move_to_original_branch
                exit
@@ -260,9 +277,11 @@ do
                git rerere clear
                if test -d "$dotest"
                then
+                       GIT_QUIET=$(cat "$dotest/quiet")
                        move_to_original_branch
                else
                        dotest="$GIT_DIR"/rebase-apply
+                       GIT_QUIET=$(cat "$dotest/quiet")
                        move_to_original_branch
                fi
                git reset --hard $(cat "$dotest/orig-head")
@@ -300,6 +319,13 @@ do
        -v|--verbose)
                verbose=t
                diffstat=t
+               GIT_QUIET=
+               ;;
+       -q|--quiet)
+               GIT_QUIET=t
+               git_am_opt="$git_am_opt -q"
+               verbose=
+               diffstat=
                ;;
        --whitespace=*)
                git_am_opt="$git_am_opt $1"
@@ -445,15 +471,15 @@ then
        then
                # Lazily switch to the target branch if needed...
                test -z "$switch_to" || git checkout "$switch_to"
-               echo >&2 "Current branch $branch_name is up to date."
+               say "Current branch $branch_name is up to date."
                exit 0
        else
-               echo "Current branch $branch_name is up to date, rebase forced."
+               say "Current branch $branch_name is up to date, rebase forced."
        fi
 fi
 
 # Detach HEAD and reset the tree
-echo "First, rewinding head to replay your work on top of it..."
+say "First, rewinding head to replay your work on top of it..."
 git checkout -q "$onto^0" || die "could not detach HEAD"
 git update-ref ORIG_HEAD $branch
 
@@ -471,7 +497,7 @@ fi
 # we just fast forwarded.
 if test "$mb" = "$branch"
 then
-       echo >&2 "Fast-forwarded $branch_name to $onto_name."
+       say "Fast-forwarded $branch_name to $onto_name."
        move_to_original_branch
        exit 0
 fi
@@ -493,7 +519,8 @@ then
        test 0 != $ret -a -d "$GIT_DIR"/rebase-apply &&
                echo $head_name > "$GIT_DIR"/rebase-apply/head-name &&
                echo $onto > "$GIT_DIR"/rebase-apply/onto &&
-               echo $orig_head > "$GIT_DIR"/rebase-apply/orig-head
+               echo $orig_head > "$GIT_DIR"/rebase-apply/orig-head &&
+               echo "$GIT_QUIET" > "$GIT_DIR"/rebase-apply/quiet
        exit $ret
 fi
 
@@ -507,6 +534,7 @@ prev_head=$orig_head
 echo "$prev_head" > "$dotest/prev_head"
 echo "$orig_head" > "$dotest/orig-head"
 echo "$head_name" > "$dotest/head-name"
+echo "$GIT_QUIET" > "$dotest/quiet"
 
 msgnum=0
 for cmt in `git rev-list --reverse --no-merges "$revisions"`
index 7f62bfb9ddbc4b28017be529d73c7ece29424fec..c5c29ccc4f372723fc77c1af0d7cb7879b92729f 100755 (executable)
@@ -54,8 +54,8 @@ test_expect_success 'rebase against master' '
      git rebase master'
 
 test_expect_success 'rebase against master twice' '
-     git rebase master 2>err &&
-     grep "Current branch my-topic-branch is up to date" err
+     git rebase master >out &&
+     grep "Current branch my-topic-branch is up to date" out
 '
 
 test_expect_success 'rebase against master twice with --force' '
@@ -65,14 +65,14 @@ test_expect_success 'rebase against master twice with --force' '
 
 test_expect_success 'rebase against master twice from another branch' '
      git checkout my-topic-branch^ &&
-     git rebase master my-topic-branch 2>err &&
-     grep "Current branch my-topic-branch is up to date" err
+     git rebase master my-topic-branch >out &&
+     grep "Current branch my-topic-branch is up to date" out
 '
 
 test_expect_success 'rebase fast-forward to master' '
      git checkout my-topic-branch^ &&
-     git rebase my-topic-branch 2>err &&
-     grep "Fast-forwarded HEAD to my-topic-branch" err
+     git rebase my-topic-branch >out &&
+     grep "Fast-forwarded HEAD to my-topic-branch" out
 '
 
 test_expect_success \
@@ -126,4 +126,11 @@ test_expect_success 'Show verbose error when HEAD could not be detached' '
      grep "Untracked working tree file .B. would be overwritten" output.err
 '
 
+test_expect_success 'rebase -q is quiet' '
+     rm B &&
+     git checkout -b quiet topic &&
+     git rebase -q master > output.out 2>&1 &&
+     test ! -s output.out
+'
+
 test_done
index 51c369ad1428330b917ffe50ba9963d59be650ea..a12bf846231d18b2a815151d1a0e1ab3d5f491d1 100755 (executable)
@@ -180,6 +180,17 @@ test_expect_success 'am -3 falls back to 3-way merge' '
        test -z "$(git diff lorem)"
 '
 
+test_expect_success 'am -3 -q is quiet' '
+       git reset master2 --hard &&
+       sed -n -e "3,\$p" msg >file &&
+       head -n 9 msg >>file &&
+       git add file &&
+       test_tick &&
+       git commit -m "copied stuff" &&
+       git am -3 -q lorem-move.patch > output.out 2>&1 &&
+       ! test -s output.out
+'
+
 test_expect_success 'am pauses on conflict' '
        git checkout lorem2^^ &&
        test_must_fail git am lorem-move.patch &&
@@ -313,4 +324,11 @@ test_expect_success 'am newline in subject' '
        grep "^Applying: second \\\n foo$" output.out
 '
 
+test_expect_success 'am -q is quiet' '
+       git checkout first &&
+       test_tick &&
+       git am -q < patch1 > output.out 2>&1 &&
+       ! test -s output.out
+'
+
 test_done