Skip to contentSkip to conversation

Teach shell scripts to be quiet

PATCH In review Stephen Boyd 3 participants 18 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

v3 cover Teach shell scripts to be quiet

The main goal of this series is to teach git-am and git-rebase to be quiet.

I was tempted to do a more clever say() which could take arbitrary printf arguments. I've decided it's not worth it, as just doing what Junio suggested and then adding an echo works well for most users of say().

stash is still left out, and I've noticed that rerere could probably be made quiet too, but that's for a later day.

I've included a test for the newline bug. If it's not wanted it can just be dropped.

Changes since v2:
- say uses printf instead of echo
- suppressing errors from git-apply under am -3 -q
- added a test for am -3 -q
- added a test for am where subjects have a literal newline
- am,rebase tests check both stdout and stderr
- rebase.sh::continue_merge() suppress the output of git rev-list

Changes since v1:
- introduction of say()
- migration of submodule and repack

Stephen Boyd (4):
t4150: test applying with a newline in subject
git-sh-setup: introduce say() for quiet options submodule, repack: migrate to git-sh-setup's say() am, rebase: teach quiet option

 Documentation/git-am.txt     |    6 +++++-
 Documentation/git-rebase.txt |    4 ++++
 git-am.sh                    |   26 ++++++++++++++++++++------
 git-rebase.sh                |   39 +++++++++++++++++++++++++++------------
 git-repack.sh                |   12 +++++-------
 git-sh-setup.sh              |   10 ++++++++++
 git-submodule.sh             |   24 ++++++------------------
 t/t3400-rebase.sh            |    7 +++++++
 t/t4150-am.sh                |   26 ++++++++++++++++++++++++++
 9 files changed, 110 insertions(+), 44 deletions(-)
#1 lore raw

PATCH v3 1/4 t4150: test applying with a newline in subject

Commit 4b7cc26 (git-am: use printf instead of echo on user-supplied strings, 2007-05-25) fixed a bug where subjects with newlines would cause git-am to echo multiple lines when it says "Applying: <subject>".

This test ensures that fix stays valid.

---
 t/t4150-am.sh |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
t/t4150-am.sh +8 -0
index d6ebbae..51c369a 100755
@@ -305,4 +305,12 @@ test_expect_success 'am into an unborn branch' '
 	test "z$result" = "z$(git rev-parse first^{tree})"
 '
 
+test_expect_success 'am newline in subject' '
+	git checkout first &&
+	test_tick &&
+	sed -e "s/second/second \\\n foo/" patch1 > patchnl &&
+	git am < patchnl > output.out 2>&1 &&
+	grep "^Applying: second \\\n foo$" output.out
+'
+
 test_done
Signature · 1 line
1.6.3.2.306.g4f4fa
#2 lore raw

PATCH v3 2/4 git-sh-setup: introduce say() for quiet options

Scripts should use say() when they want to output non-error messages. This function helps future script writers easily implement a quiet option by setting GIT_QUIET to enable suppression of non-error messages.

---
 git-sh-setup.sh |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
git-sh-setup.sh +10 -0
index 80acb7d..33513d2 100755
@@ -44,6 +44,16 @@ die() {
 	exit 1
 }
 
+GIT_QUIET=
+
+say () {
+	if test -z "$GIT_QUIET"
+	then
+		printf "%s" "$*"
+		echo
+	fi
+}
+
 if test -n "$OPTIONS_SPEC"; then
 	usage() {
 		"$0" -h
Signature · 1 line
1.6.3.2.306.g4f4fa
#3 lore raw

PATCH v3 3/4 submodule, repack: migrate to git-sh-setup's say()

Now that there is say() in git-sh-setup, these scripts don't need to use their own. Migrate them over by setting GIT_QUIET and removing their custom say() functions.

---
 git-repack.sh    |   12 +++++-------
 git-submodule.sh |   24 ++++++------------------
 2 files changed, 11 insertions(+), 25 deletions(-)
git-repack.sh +5 -7
index 0868734..efb527c 100755
@@ -24,7 +24,7 @@ SUBDIRECTORY_OK='Yes'
 . git-sh-setup
 
 no_update_info= all_into_one= remove_redundant= unpack_unreachable=
-local= quiet= no_reuse= extra=
+local= no_reuse= extra=
 while test $# != 0
 do
 	case "$1" in
@@ -33,7 +33,7 @@ do
 	-A)	all_into_one=t
 		unpack_unreachable=--unpack-unreachable ;;
 	-d)	remove_redundant=t ;;
-	-q)	quiet=-q ;;
+	-q)	GIT_QUIET=-q ;;
 	-f)	no_reuse=--no-reuse-object ;;
 	-l)	local=--local ;;
 	--max-pack-size|--window|--window-memory|--depth)
@@ -80,13 +80,11 @@ case ",$all_into_one," in
 	;;
 esac
 
-args="$args $local $quiet $no_reuse$extra"
+args="$args $local $GIT_QUIET $no_reuse$extra"
 names=$(git pack-objects --honor-pack-keep --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
 	exit 1
 if [ -z "$names" ]; then
-	if test -z "$quiet"; then
-		echo Nothing new to pack.
-	fi
+	say Nothing new to pack.
 fi
 
 # Ok we have prepared all new packfiles.
@@ -176,7 +174,7 @@ then
 		  done
 		)
 	fi
-	git prune-packed $quiet
+	git prune-packed $GIT_QUIET
 fi
 
 case "$no_update_info" in
git-submodule.sh +6 -18
index 19a3a84..58d2fd2 100755
@@ -14,23 +14,11 @@ require_work_tree
 
 command=
 branch=
-quiet=
 reference=
 cached=
 nofetch=
 update=
 
-#
-# print stuff on stdout unless -q was specified
-#
-say()
-{
-	if test -z "$quiet"
-	then
-		echo "$@"
-	fi
-}
-
 # Resolve relative url by appending to parent's url
 resolve_relative_url ()
 {
@@ -137,7 +125,7 @@ cmd_add()
 			shift
 			;;
 		-q|--quiet)
-			quiet=1
+			GIT_QUIET=1
 			;;
 		--reference)
 			case "$2" in '') usage ;; esac
@@ -273,7 +261,7 @@ cmd_init()
 	do
 		case "$1" in
 		-q|--quiet)
-			quiet=1
+			GIT_QUIET=1
 			;;
 		--)
 			shift
@@ -333,7 +321,7 @@ cmd_update()
 		case "$1" in
 		-q|--quiet)
 			shift
-			quiet=1
+			GIT_QUIET=1
 			;;
 		-i|--init)
 			init=1
@@ -650,7 +638,7 @@ cmd_status()
 	do
 		case "$1" in
 		-q|--quiet)
-			quiet=1
+			GIT_QUIET=1
 			;;
 		--cached)
 			cached=1
@@ -704,7 +692,7 @@ cmd_sync()
 	do
 		case "$1" in
 		-q|--quiet)
-			quiet=1
+			GIT_QUIET=1
 			shift
 			;;
 		--)
@@ -759,7 +747,7 @@ do
 		command=$1
 		;;
 	-q|--quiet)
-		quiet=1
+		GIT_QUIET=1
 		;;
 	-b|--branch)
 		case "$2" in
Signature · 1 line
1.6.3.2.306.g4f4fa
#4 lore raw

PATCH v3 4/4 am, rebase: teach quiet option

git-rebase and git-am are talkative scripts. This option will quiet them and allow them to speak only when they fail or experience errors.

Note that git-am with 3way will output errors when applying, even though the 3way will usually be successfull. We suppress these errors from git-apply because they are not "true" errors until the 3way has been attempted.

Add a few tests for this new feature too.

---
 Documentation/git-am.txt     |    6 +++++-
 Documentation/git-rebase.txt |    4 ++++
 git-am.sh                    |   26 ++++++++++++++++++++------
 git-rebase.sh                |   39 +++++++++++++++++++++++++++------------
 t/t3400-rebase.sh            |    7 +++++++
 t/t4150-am.sh                |   18 ++++++++++++++++++
 6 files changed, 81 insertions(+), 19 deletions(-)
Documentation/git-am.txt +5 -1
index 6d92cbe..32e689b 100644
@@ -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]).
Documentation/git-rebase.txt +4 -0
index 26f3b7b..db1b71d 100644
@@ -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.
git-am.sh +20 -6
index 578780b..42b1bae 100755
@@ -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 ;;
 	*)
@@ -352,7 +359,7 @@ fi
 
 if test "$this" -gt "$last"
 then
-	echo Nothing to do.
+	say Nothing to do.
 	rm -fr "$dotest"
 	exit
 fi
@@ -498,11 +505,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"'
+		if test "$threeway" = t && test -n "$GIT_QUIET"
+		then
+			eval 'git apply '"$git_apply_opt" \
+			' --index "$dotest/patch" > /dev/null 2>&1'
+		else
+			eval 'git apply '"$git_apply_opt" \
+			' --index "$dotest/patch"'
+		fi
 		apply_status=$?
 		;;
 	t)
@@ -534,7 +548,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
 		    }
git-rebase.sh +27 -12
index b83fd3f..a518505 100755
@@ -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
@@ -138,7 +147,7 @@ move_to_original_branch () {
 finish_rb_merge () {
 	move_to_original_branch
 	rm -r "$dotest"
-	echo "All done."
+	say All done.
 }
 
 is_interactive () {
@@ -221,7 +230,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 am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
+		git am --resolved $GIT_QUIET --3way --resolvemsg="$RESOLVEMSG" &&
 		move_to_original_branch
 		exit
 		;;
@@ -249,7 +258,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 am -3 --skip --resolvemsg="$RESOLVEMSG" &&
+		git am -3 --skip $GIT_QUIET --resolvemsg="$RESOLVEMSG" &&
 		move_to_original_branch
 		exit
 		;;
@@ -300,6 +309,12 @@ do
 	-v|--verbose)
 		verbose=t
 		diffstat=t
+		GIT_QUIET=
+		;;
+	-q|--quiet)
+		GIT_QUIET="-q"
+		verbose=
+		diffstat=
 		;;
 	--whitespace=*)
 		git_am_opt="$git_am_opt $1"
@@ -445,15 +460,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 >&2 "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 +486,7 @@ fi
 # we just fast forwarded.
 if test "$mb" = "$branch"
 then
-	echo >&2 "Fast-forwarded $branch_name to $onto_name."
+	say >&2 "Fast-forwarded $branch_name to $onto_name."
 	move_to_original_branch
 	exit 0
 fi
@@ -487,7 +502,7 @@ if test -z "$do_merge"
 then
 	git format-patch -k --stdout --full-index --ignore-if-in-upstream \
 		$root_flag "$revisions" |
-	git am $git_am_opt --rebasing --resolvemsg="$RESOLVEMSG" &&
+	git am $git_am_opt $GIT_QUIET --rebasing --resolvemsg="$RESOLVEMSG" &&
 	move_to_original_branch
 	ret=$?
 	test 0 != $ret -a -d "$GIT_DIR"/rebase-apply &&
t/t3400-rebase.sh +7 -0
index 7f62bfb..248944b 100755
@@ -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
t/t4150-am.sh +18 -0
index 51c369a..a12bf84 100755
@@ -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
Signature · 1 line
1.6.3.2.306.g4f4fa
#5 lore raw

Re: [PATCHv3 4/4] am, rebase: teach quiet option

Quoted 7 lines · Stephen Boyd

git-rebase and git-am are talkative scripts. This option will quiet them and allow them to speak only when they fail or experience errors.

Note that git-am with 3way will output errors when applying, even though the 3way will usually be successfull. We suppress these errors from git-apply because they are not "true" errors until the 3way has been attempted.

Thanks.

Quoted 4 lines
git-am.sh +0 -0
@@ -498,11 +505,18 @@ do
...
 	case "$resolved" in
 	'')

git-am.sh do · line 520

Quoted 10 lines
git-am.sh +8 -1
-		eval 'git apply '"$git_apply_opt"' --index "$dotest/patch"'
+		if test "$threeway" = t && test -n "$GIT_QUIET"
+		then
+			eval 'git apply '"$git_apply_opt" \
+			' --index "$dotest/patch" > /dev/null 2>&1'
+		else
+			eval 'git apply '"$git_apply_opt" \
+			' --index "$dotest/patch"'
+		fi
 		apply_status=$?

Hmm, this long conditional body looks ugly, and I suspect it is harder to maintain than necessary. Can we do something about it?

	# 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 && test -n "$GIT_QUIET"
	then
		squelch='>/dev/null 2>&1 '
	fi
        eval "git apply $squelch$git_apply_opt"' --index "$dotest/patch"'
Quoted 11 lines
git-rebase.sh +4 -2
@@ -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

git-rebase.sh continue_merge () { · line 79

Quoted 10 lines
git-rebase.sh +8 -1
+		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/^[^ ]* //'

This is very good, because a straightforward translation is what we want in this particular patch.

We however would want to update this using

	git show -s --oneline

or something, perhaps even with a custom --format='...', in a follow-up patch. This "rev-list --pretty=oneline" piped to sed looks very much antiquated.

git-rebase.sh then · line 464

Quoted 7 lines
git-rebase.sh +1 -1
@@ -445,15 +460,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 >&2 "Current branch $branch_name is up to date."
 		exit 0

Ah, I was blind.

While sending non-error messages to stderr is justifiable, I do not think this one is, because all the other progress-y message in this program we reviewed so far go to stdout. I think we should drop >&2 here.

git-rebase.sh fi · line 489

Quoted 6 lines
git-rebase.sh +1 -1
@@ -471,7 +486,7 @@ fi
 # we just fast forwarded.
 if test "$mb" = "$branch"
 then
-	echo >&2 "Fast-forwarded $branch_name to $onto_name."
+	say >&2 "Fast-forwarded $branch_name to $onto_name."

Ditto.

There is one more thing to think about in git-am, which I do not think you addressed. Consider this scenario.

(1) Tell am to run quietly, feeding a four-patch series.

$ git am -q -3 mbox

(2) The first patch applies cleanly; the second one does not apply, even with -3, and leaves conflict (you did the right thing not to squelch the message when this happens).

(3) You fix it up, and save the result from your editor, and tell it to continue.

$ git am --resolved

Now, should the second invocation be also quiet, or talkative as default?

Note that the third and fourth patch are applied with -3 option in effect, even though you did not say -3 when you restarted "am" with --resolved (cf. ll.280-340 in git-am.sh).

#6 lore raw

Re: [PATCHv3 4/4] am, rebase: teach quiet option

Quoted 12 lines · Junio C Hamano

Hmm, this long conditional body looks ugly, and I suspect it is harder to maintain than necessary. Can we do something about it?

	# 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 && test -n "$GIT_QUIET"
	then
		squelch='>/dev/null 2>&1 '
	fi
        eval "git apply $squelch$git_apply_opt"' --index "$dotest/patch"'

Thanks. I thought there would be a nicer way but I didn't know it.

Quoted 5 lines

Ah, I was blind.

While sending non-error messages to stderr is justifiable, I do not think this one is, because all the other progress-y message in this program we reviewed so far go to stdout. I think we should drop >&2 here.

Will do, gotta fixup some tests for that though...

Quoted 14 lines

There is one more thing to think about in git-am, which I do not think you addressed. Consider this scenario.

(1) Tell am to run quietly, feeding a four-patch series.

$ git am -q -3 mbox

(2) The first patch applies cleanly; the second one does not apply, even with -3, and leaves conflict (you did the right thing not to squelch the message when this happens).

(3) You fix it up, and save the result from your editor, and tell it to continue.

Quoted 7 lines

$ git am --resolved

Now, should the second invocation be also quiet, or talkative as default?

Note that the third and fourth patch are applied with -3 option in effect, even though you did not say -3 when you restarted "am" with --resolved (cf. ll.280-340 in git-am.sh).

Thanks for bringing this up. I gave this some thought before I sent the series out but I was secretly hoping nobody would care :-) I think it's more correct and maybe even more consistent to keep the quiet option enabled.

Seeing as this series is going for round 4 I'll make sure to include this as well.

#7 lore raw

Re: [PATCHv3 3/4] submodule, repack: migrate to git-sh-setup's say()

In reply to Stephen Boyd
Quoted 3 lines · Stephen Boyd

Now that there is say() in git-sh-setup, these scripts don't need to use their own. Migrate them over by setting GIT_QUIET and removing their custom say() functions.

This is not exactly a very nice style.

The contract between the callers of say() and its implementation is that it does not matter what value is set to GIT_QUIET. The only thing that matters is if it is set to empty string or not. And ...

git-repack.sh do · line 36

Quoted 6 lines
git-repack.sh +1 -1
@@ -33,7 +33,7 @@ do
 	-A)	all_into_one=t
 		unpack_unreachable=--unpack-unreachable ;;
 	-d)	remove_redundant=t ;;
-	-q)	quiet=-q ;;
+	-q)	GIT_QUIET=-q ;;

... this one takes advantage of it to set GIT_QUIET to -q, so that it can be directly passed to another command that happens to use -q as "quiet" option, like this ...

git-repack.sh then · line 178

Quoted 3 lines
git-repack.sh +1 -1
-	git prune-packed $quiet
+	git prune-packed $GIT_QUIET
 fi

... while the other one does not have a callout to command that takes -q at all, and does this ...

git-submodule.sh cmd_add() · line 128

Quoted 3 lines
git-submodule.sh +1 -1
 		-q|--quiet)
-			quiet=1
+			GIT_QUIET=1

If the convention is "GIT_QUIET, when set to non-empty string, squelches the output", then I think the callers should be more consistent and the call to prune-packed should say something like this, which is admittedly a roundabout way:

	git prune-packed ${GIT_QUIET:+-q}

for consistency (and then what you set to GIT_QUIET in the first hunk I quoted does not matter anymore---it can even be t or 1 or whatever).

I think this does not matter too much, because I suspect that in the longer term scripted Porcelains are going away, but still...

#8 lore raw

Re: [PATCHv3 3/4] submodule, repack: migrate to git-sh-setup's say()

Quoted 1 line · Junio C Hamano

This is not exactly a very nice style.

I had a feeling ;-)

Quoted 5 lines

If the convention is "GIT_QUIET, when set to non-empty string, squelches the output", then I think the callers should be more consistent and the call to prune-packed should say something like this, which is admittedly a roundabout way:

Quoted 7 lines
	git prune-packed ${GIT_QUIET:+-q}

for consistency (and then what you set to GIT_QUIET in the first hunk I quoted does not matter anymore---it can even be t or 1 or whatever).

I think this does not matter too much, because I suspect that in the longer term scripted Porcelains are going away, but still...

I think this is fine. At least it's more explicit and localized. I'll do the same for git-am

#9 lore raw

Re: [PATCHv3 3/4] submodule, repack: migrate to git-sh-setup's say()

In reply to Junio C Hamano
Quoted 6 lines · Junio C Hamano

...
If the convention is "GIT_QUIET, when set to non-empty string, squelches the output", then I think the callers should be more consistent and the call to prune-packed should say something like this, which is admittedly a roundabout way:

Quoted 7 lines
	git prune-packed ${GIT_QUIET:+-q}

for consistency (and then what you set to GIT_QUIET in the first hunk I quoted does not matter anymore---it can even be t or 1 or whatever).

I think this does not matter too much, because I suspect that in the longer term scripted Porcelains are going away, but still...

What I meant was that my _style_ comment does not matter too much. The addition of "quiet" _is_ a worthwhile thing to do, I think.

#10 lore raw

Re: [PATCHv3 2/4] git-sh-setup: introduce say() for quiet options

In reply to Stephen Boyd

git-sh-setup.sh die() { · line 53

Quoted 5 lines · Stephen Boyd
git-sh-setup.sh +5 -0
+say () {
+	if test -z "$GIT_QUIET"
+	then
+		printf "%s" "$*"
+		echo

You can squash these two lines into

		printf '%s\n' "$*"

-- Hannes

#11 lore raw

v4 cover Teach shell scripts to be quiet

In reply to Stephen Boyd

The main goal of this series is to teach git-am and git-rebase to be quiet.

This series feels very improved. I'm pretty confident in the first three patches. I've split off the suppressing errors from git-apply in git-am into its own patch this time around. It felt more like an independent change.

I've tried to make sure I maintained GIT_QUIET after failing to apply, but I'd appreciate if others could look over that to make sure.

Changes since v3:
- simplify say()
- say "applying to an empty history" in am.sh
- quiet merge in rebase.sh::call_merge()
- drop >&2 in a couple places in rebase.sh
- maintain GIT_QUIET when git-am or git-rebase fails
- fixup style issues with repack.sh
- add to git_am_opt instead of hijacking GIT_QUIET in rebase.sh

Changes since v2:
- say uses printf instead of echo
- suppressing errors from git-apply under am -3 -q
- added a test for am -3 -q
- added a test for am where subjects have a literal newline
- am,rebase tests check both stdout and stderr
- rebase.sh::continue_merge() suppress the output of git rev-list

Changes since v1:
- introduction of say()
- migration of submodule and repack

Stephen Boyd (5):
t4150: test applying with a newline in subject
am: suppress apply errors when using 3-way
git-sh-setup: introduce say() for quiet options submodule, repack: migrate to git-sh-setup's say() am, rebase: teach quiet option

 Documentation/git-am.txt     |    6 ++++-
 Documentation/git-rebase.txt |    4 +++
 git-am.sh                    |   35 +++++++++++++++++++++++-------
 git-rebase.sh                |   48 +++++++++++++++++++++++++++++++++--------
 git-repack.sh                |   12 ++++------
 git-sh-setup.sh              |    9 +++++++
 git-submodule.sh             |   24 +++++---------------
 t/t3400-rebase.sh            |   19 +++++++++++-----
 t/t4150-am.sh                |   26 ++++++++++++++++++++++
 9 files changed, 133 insertions(+), 50 deletions(-)
#12 lore raw

PATCH v4 1/5 t4150: test applying with a newline in subject

Commit 4b7cc26 (git-am: use printf instead of echo on user-supplied strings, 2007-05-25) fixed a bug where subjects with newlines would cause git-am to echo multiple lines when it says "Applying: <subject>".

This test ensures that fix stays valid.

---

Nothing new here.

 t/t4150-am.sh |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
t/t4150-am.sh +8 -0
index d6ebbae..51c369a 100755
@@ -305,4 +305,12 @@ test_expect_success 'am into an unborn branch' '
 	test "z$result" = "z$(git rev-parse first^{tree})"
 '
 
+test_expect_success 'am newline in subject' '
+	git checkout first &&
+	test_tick &&
+	sed -e "s/second/second \\\n foo/" patch1 > patchnl &&
+	git am < patchnl > output.out 2>&1 &&
+	grep "^Applying: second \\\n foo$" output.out
+'
+
 test_done
Signature · 1 line
1.6.3.2.306.g4f4fa
#13 lore raw

PATCH v4 2/5 am: suppress apply errors when using 3-way

git-am with 3-way outputs errors when applying, even though the 3-way will usually be successful. We suppress these errors from git-apply because they are not "true" errors until the 3-way has been attempted.

---

Seems to me like we should always suppress these errors if we're falling back to 3-way. So I've removed the test for GIT_QUIET and pushed this earlier in the series.

 git-am.sh |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
git-am.sh +8 -1
index 578780b..e26c54a 100755
@@ -502,7 +502,14 @@ do
 
 	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)
Signature · 1 line
1.6.3.2.306.g4f4fa
#14 lore raw

PATCH v4 3/5 git-sh-setup: introduce say() for quiet options

Scripts should use say() when they want to output non-error messages. This function helps future script writers easily implement a quiet option by setting GIT_QUIET to enable suppression of non-error messages.

---
 git-sh-setup.sh |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
git-sh-setup.sh +9 -0
index 80acb7d..c41c2f7 100755
@@ -44,6 +44,15 @@ die() {
 	exit 1
 }
 
+GIT_QUIET=
+
+say () {
+	if test -z "$GIT_QUIET"
+	then
+		printf '%s\n' "$*"
+	fi
+}
+
 if test -n "$OPTIONS_SPEC"; then
 	usage() {
 		"$0" -h
Signature · 1 line
1.6.3.2.306.g4f4fa
#15 lore raw

PATCH v4 4/5 submodule, repack: migrate to git-sh-setup's say()

Now that there is say() in git-sh-setup, these scripts don't need to use their own. Migrate them over by setting GIT_QUIET and removing their custom say() functions.

---

This has the style fixups.

 git-repack.sh    |   12 +++++-------
 git-submodule.sh |   24 ++++++------------------
 2 files changed, 11 insertions(+), 25 deletions(-)
git-repack.sh +5 -7
index 0868734..1bf2394 100755
@@ -24,7 +24,7 @@ SUBDIRECTORY_OK='Yes'
 . git-sh-setup
 
 no_update_info= all_into_one= remove_redundant= unpack_unreachable=
-local= quiet= no_reuse= extra=
+local= no_reuse= extra=
 while test $# != 0
 do
 	case "$1" in
@@ -33,7 +33,7 @@ do
 	-A)	all_into_one=t
 		unpack_unreachable=--unpack-unreachable ;;
 	-d)	remove_redundant=t ;;
-	-q)	quiet=-q ;;
+	-q)	GIT_QUIET=t ;;
 	-f)	no_reuse=--no-reuse-object ;;
 	-l)	local=--local ;;
 	--max-pack-size|--window|--window-memory|--depth)
@@ -80,13 +80,11 @@ case ",$all_into_one," in
 	;;
 esac
 
-args="$args $local $quiet $no_reuse$extra"
+args="$args $local ${GIT_QUIET:+-q} $no_reuse$extra"
 names=$(git pack-objects --honor-pack-keep --non-empty --all --reflog $args </dev/null "$PACKTMP") ||
 	exit 1
 if [ -z "$names" ]; then
-	if test -z "$quiet"; then
-		echo Nothing new to pack.
-	fi
+	say Nothing new to pack.
 fi
 
 # Ok we have prepared all new packfiles.
@@ -176,7 +174,7 @@ then
 		  done
 		)
 	fi
-	git prune-packed $quiet
+	git prune-packed ${GIT_QUIET:+-q}
 fi
 
 case "$no_update_info" in
git-submodule.sh +6 -18
index 19a3a84..58d2fd2 100755
@@ -14,23 +14,11 @@ require_work_tree
 
 command=
 branch=
-quiet=
 reference=
 cached=
 nofetch=
 update=
 
-#
-# print stuff on stdout unless -q was specified
-#
-say()
-{
-	if test -z "$quiet"
-	then
-		echo "$@"
-	fi
-}
-
 # Resolve relative url by appending to parent's url
 resolve_relative_url ()
 {
@@ -137,7 +125,7 @@ cmd_add()
 			shift
 			;;
 		-q|--quiet)
-			quiet=1
+			GIT_QUIET=1
 			;;
 		--reference)
 			case "$2" in '') usage ;; esac
@@ -273,7 +261,7 @@ cmd_init()
 	do
 		case "$1" in
 		-q|--quiet)
-			quiet=1
+			GIT_QUIET=1
 			;;
 		--)
 			shift
@@ -333,7 +321,7 @@ cmd_update()
 		case "$1" in
 		-q|--quiet)
 			shift
-			quiet=1
+			GIT_QUIET=1
 			;;
 		-i|--init)
 			init=1
@@ -650,7 +638,7 @@ cmd_status()
 	do
 		case "$1" in
 		-q|--quiet)
-			quiet=1
+			GIT_QUIET=1
 			;;
 		--cached)
 			cached=1
@@ -704,7 +692,7 @@ cmd_sync()
 	do
 		case "$1" in
 		-q|--quiet)
-			quiet=1
+			GIT_QUIET=1
 			shift
 			;;
 		--)
@@ -759,7 +747,7 @@ do
 		command=$1
 		;;
 	-q|--quiet)
-		quiet=1
+		GIT_QUIET=1
 		;;
 	-b|--branch)
 		case "$2" in
Signature · 1 line
1.6.3.2.306.g4f4fa
#16 lore raw

PATCH v4 5/5 am, rebase: teach quiet option

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 couple >&2 statements because Junio has deemed them unnecessary.

---

Copied from cover letter for convenience:
- say "applying to an empty history" in am.sh
- quiet merge in rebase.sh::call_merge()
- drop >&2 in a couple places in rebase.sh
- maintain GIT_QUIET when git-am or git-rebase fails
- add to git_am_opt instead of hijacking GIT_QUIET in rebase.sh

I chose GIT_MERGE_VERBOSITY=1 in rebase because the resolvemsg says "correct the above error", and GIT_MERGE_VERBOSITY=0 prints nothing. I think this might be a bug, either in the documentation or in merge-recursive. At least setting it to 1 prints "CONFLICT (content): ..."

This behavior was observed by passing -q to rebase in t3407.

 Documentation/git-am.txt     |    6 ++++-
 Documentation/git-rebase.txt |    4 +++
 git-am.sh                    |   26 ++++++++++++++++------
 git-rebase.sh                |   48 +++++++++++++++++++++++++++++++++--------
 t/t3400-rebase.sh            |   19 +++++++++++-----
 t/t4150-am.sh                |   18 +++++++++++++++
 6 files changed, 97 insertions(+), 24 deletions(-)
Documentation/git-am.txt +5 -1
index 6d92cbe..32e689b 100644
@@ -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]).
Documentation/git-rebase.txt +4 -0
index 26f3b7b..db1b71d 100644
@@ -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.
git-am.sh +19 -7
index e26c54a..58d4eb6 100755
@@ -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
git-rebase.sh +38 -10

143 lines not on this page · raw message

t/t3400-rebase.sh +13 -6
index 7f62bfb..c5c29cc 100755
@@ -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
t/t4150-am.sh +18 -0
index 51c369a..a12bf84 100755
@@ -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
Signature · 1 line
1.6.3.2.306.g4f4fa
#17 lore raw

[PATCHv4 6/5] stash: teach quiet option

Teach stash pop, apply, save, and drop to be quiet when told. By using the quiet option (-q), these actions will be silent unless errors are encountered.

---
 Documentation/git-stash.txt |   15 ++++----
 git-stash.sh                |   78 +++++++++++++++++++++++++++++++++---------
 t/t3903-stash.sh            |   23 +++++++++++++
 3 files changed, 92 insertions(+), 24 deletions(-)
Documentation/git-stash.txt +8 -7
index a42d4c8..1c64a02 100644
@@ -9,10 +9,11 @@ SYNOPSIS
 --------
 [verse]
 'git stash' list [<options>]
-'git stash' ( show | drop ) [<stash>]
-'git stash' ( pop | apply ) [--index] [<stash>]
+'git stash' show [<stash>]
+'git stash' drop [-q|--quiet] [<stash>]
+'git stash' ( pop | apply ) [--index] [-q|--quiet] [<stash>]
 'git stash' branch <branchname> [<stash>]
-'git stash' [save [--keep-index] [<message>]]
+'git stash' [save [--keep-index] [-q|--quiet] [<message>]]
 'git stash' clear
 'git stash' create
 
@@ -41,7 +42,7 @@ is also possible).
 OPTIONS
 -------
 
-save [--keep-index] [<message>]::
+save [--keep-index] [-q|--quiet] [<message>]::
 
 	Save your local modifications to a new 'stash', and run `git reset
 	--hard` to revert them.  This is the default action when no
@@ -75,7 +76,7 @@ show [<stash>]::
 	it will accept any format known to 'git-diff' (e.g., `git stash show
 	-p stash@\{1}` to view the second most recent stash in patch form).
 
-pop [<stash>]::
+pop [--index] [-q|--quiet] [<stash>]::
 
 	Remove a single stashed state from the stash list and apply it
 	on top of the current working tree state, i.e., do the inverse
@@ -93,7 +94,7 @@ longer apply the changes as they were originally).
 +
 When no `<stash>` is given, `stash@\{0}` is assumed.
 
-apply [--index] [<stash>]::
+apply [--index] [-q|--quiet] [<stash>]::
 
 	Like `pop`, but do not remove the state from the stash list.
 
@@ -115,7 +116,7 @@ clear::
 	Remove all the stashed states. Note that those states will then
 	be subject to pruning, and may be difficult or impossible to recover.
 
-drop [<stash>]::
+drop [-q|--quiet] [<stash>]::
 
 	Remove a single stashed state from the stash list. When no `<stash>`
 	is given, it removes the latest one. i.e. `stash@\{0}`
git-stash.sh +61 -17

142 lines not on this page · raw message

t/t3903-stash.sh +23 -0
index 7484cbe..7a3fb67 100755
@@ -177,4 +177,27 @@ test_expect_success 'stash branch' '
 	test 0 = $(git stash list | wc -l)
 '
 
+test_expect_success 'apply -q is quiet' '
+	echo foo > file &&
+	git stash &&
+	git stash apply -q > output.out 2>&1 &&
+	test ! -s output.out
+'
+
+test_expect_success 'save -q is quiet' '
+	git stash save --quiet > output.out 2>&1 &&
+	test ! -s output.out
+'
+
+test_expect_success 'pop -q is quiet' '
+	git stash pop -q > output.out 2>&1 &&
+	test ! -s output.out
+'
+
+test_expect_success 'drop -q is quiet' '
+	git stash &&
+	git stash drop -q > output.out 2>&1 &&
+	test ! -s output.out
+'
+
 test_done
Signature · 1 line
1.6.3.2.306.g4f4fa