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 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>
Stephen Boyd committed
Jun 16, 2009 at 15:33 UTC
0e987a12fc1d481d81ad9c56f4714efb08667213
6 files changed
+97
-24
Documentation/git-am.txt
+5
-1
@@ -13,7 +13,7 @@ SYNOPSIS
13
[--3way] [--interactive] [--committer-date-is-author-date]
14
[--ignore-date]
15
[--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>]
16
- [--reject]
16
+ [--reject] [-q | --quiet]
17
[<mbox> | <Maildir>...]
18
'git am' (--skip | --resolved | --abort)
19
@@ -39,6 +39,10 @@ OPTIONS
39
--keep::
40
Pass `-k` flag to 'git-mailinfo' (see linkgit:git-mailinfo[1]).
41
42
+-q::
43
+--quiet::
44
+ Be quiet. Only print error messages.
45
+
46
-u::
47
--utf8::
48
Pass `-u` flag to 'git-mailinfo' (see linkgit:git-mailinfo[1]).
Documentation/git-rebase.txt
+4
@@ -236,6 +236,10 @@ OPTIONS
236
is used instead ('git-merge-recursive' when merging a single
237
head, 'git-merge-octopus' otherwise). This implies --merge.
238
239
+-q::
240
+--quiet::
241
+ Be quiet. Implies --no-stat.
242
+
243
-v::
244
--verbose::
245
Be verbose. Implies --stat.
git-am.sh
+19
-7
@@ -11,6 +11,7 @@ git am [options] (--resolved | --skip | --abort)
11
i,interactive run interactively
12
b,binary* (historical option -- no-op)
13
3,3way allow fall back on 3way merging if needed
14
+q,quiet be quiet
15
s,signoff add a Signed-off-by line to the commit message
16
u,utf8 recode into utf8 (default)
17
k,keep pass -k flag to git-mailinfo
@@ -99,7 +100,7 @@ fall_back_3way () {
100
git write-tree >"$dotest/patch-merge-base+" ||
101
cannot_fallback "Repository lacks necessary blobs to fall back on 3-way merge."
102
102
- echo Using index info to reconstruct a base tree...
103
+ say Using index info to reconstruct a base tree...
104
if GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
105
git apply --cached <"$dotest/patch"
106
then
@@ -115,7 +116,7 @@ It does not apply to blobs recorded in its index."
116
orig_tree=$(cat "$dotest/patch-merge-base") &&
117
rm -fr "$dotest"/patch-merge-* || exit 1
118
118
- echo Falling back to patching base and 3-way merge...
119
+ say Falling back to patching base and 3-way merge...
120
121
# This is not so wrong. Depending on which base we picked,
122
# 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."
126
127
eval GITHEAD_$his_tree='"$FIRSTLINE"'
128
export GITHEAD_$his_tree
129
+ if test -n "$GIT_QUIET"
130
+ then
131
+ export GIT_MERGE_VERBOSITY=0
132
+ fi
133
git-merge-recursive $orig_tree -- HEAD $his_tree || {
134
git rerere
135
echo Failed to merge in the changes.
@@ -181,6 +186,8 @@ do
186
committer_date_is_author_date=t ;;
187
--ignore-date)
188
ignore_date=t ;;
189
+ -q|--quiet)
190
+ GIT_QUIET=t ;;
191
--)
192
shift; break ;;
193
*)
@@ -279,7 +286,7 @@ else
286
exit 1
287
}
288
282
- # -s, -u, -k, --whitespace, -3, -C and -p flags are kept
289
+ # -s, -u, -k, --whitespace, -3, -C, -q and -p flags are kept
290
# for the resuming session after a patch failure.
291
# -i can and must be given when resuming.
292
echo " $git_apply_opt" >"$dotest/apply-opt"
@@ -287,6 +294,7 @@ else
294
echo "$sign" >"$dotest/sign"
295
echo "$utf8" >"$dotest/utf8"
296
echo "$keep" >"$dotest/keep"
297
+ echo "$GIT_QUIET" >"$dotest/quiet"
298
echo 1 >"$dotest/next"
299
if test -n "$rebasing"
300
then
@@ -327,6 +335,10 @@ if test "$(cat "$dotest/keep")" = t
335
then
336
keep=-k
337
fi
338
+if test "$(cat "$dotest/quiet")" = t
339
+then
340
+ GIT_QUIET=t
341
+fi
342
if test "$(cat "$dotest/threeway")" = t
343
then
344
threeway=t
@@ -352,7 +364,7 @@ fi
364
365
if test "$this" -gt "$last"
366
then
355
- echo Nothing to do.
367
+ say Nothing to do.
368
rm -fr "$dotest"
369
exit
370
fi
@@ -498,7 +510,7 @@ do
510
stop_here $this
511
fi
512
501
- printf 'Applying: %s\n' "$FIRSTLINE"
513
+ say "Applying: $FIRSTLINE"
514
515
case "$resolved" in
516
'')
@@ -541,7 +553,7 @@ do
553
# Applying the patch to an earlier tree and merging the
554
# result may have produced the same tree as ours.
555
git diff-index --quiet --cached HEAD -- && {
544
- echo No changes -- Patch already applied.
556
+ say No changes -- Patch already applied.
557
go_next
558
continue
559
}
@@ -567,7 +579,7 @@ do
579
GIT_AUTHOR_DATE=
580
fi
581
parent=$(git rev-parse --verify -q HEAD) ||
570
- echo >&2 "applying to an empty history"
582
+ say >&2 "applying to an empty history"
583
584
if test -n "$committer_date_is_author_date"
585
then
git-rebase.sh
+38
-10
@@ -3,7 +3,7 @@
3
# Copyright (c) 2005 Junio C Hamano.
4
#
5
6
-USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--onto <newbase>] [<upstream>|--root] [<branch>]'
6
+USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--onto <newbase>] [<upstream>|--root] [<branch>] [--quiet | -q]'
7
LONG_USAGE='git-rebase replaces <branch> with a new branch of the
8
same name. When the --onto option is provided the new branch starts
9
out with a HEAD equal to <newbase>, otherwise it is equal to <upstream>
@@ -72,11 +72,20 @@ continue_merge () {
72
echo "directly, but instead do one of the following: "
73
die "$RESOLVEMSG"
74
fi
75
- printf "Committed: %0${prec}d " $msgnum
75
+ if test -z "$GIT_QUIET"
76
+ then
77
+ printf "Committed: %0${prec}d " $msgnum
78
+ fi
79
else
77
- printf "Already applied: %0${prec}d " $msgnum
80
+ if test -z "$GIT_QUIET"
81
+ then
82
+ printf "Already applied: %0${prec}d " $msgnum
83
+ fi
84
+ fi
85
+ if test -z "$GIT_QUIET"
86
+ then
87
+ git rev-list --pretty=oneline -1 "$cmt" | sed -e 's/^[^ ]* //'
88
fi
79
- git rev-list --pretty=oneline -1 "$cmt" | sed -e 's/^[^ ]* //'
89
90
prev_head=`git rev-parse HEAD^0`
91
# save the resulting commit so we can read-tree on it later
@@ -97,6 +106,10 @@ call_merge () {
106
eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
107
eval GITHEAD_$hd='$(cat "$dotest/onto_name")'
108
export GITHEAD_$cmt GITHEAD_$hd
109
+ if test -n "$GIT_QUIET"
110
+ then
111
+ export GIT_MERGE_VERBOSITY=1
112
+ fi
113
git-merge-$strategy "$cmt^" -- "$hd" "$cmt"
114
rv=$?
115
case "$rv" in
@@ -138,7 +151,7 @@ move_to_original_branch () {
151
finish_rb_merge () {
152
move_to_original_branch
153
rm -r "$dotest"
141
- echo "All done."
154
+ say All done.
155
}
156
157
is_interactive () {
@@ -209,6 +222,7 @@ do
222
end=$(cat "$dotest/end")
223
msgnum=$(cat "$dotest/msgnum")
224
onto=$(cat "$dotest/onto")
225
+ GIT_QUIET=$(cat "$dotest/quiet")
226
continue_merge
227
while test "$msgnum" -le "$end"
228
do
@@ -221,6 +235,7 @@ do
235
head_name=$(cat "$GIT_DIR"/rebase-apply/head-name) &&
236
onto=$(cat "$GIT_DIR"/rebase-apply/onto) &&
237
orig_head=$(cat "$GIT_DIR"/rebase-apply/orig-head) &&
238
+ GIT_QUIET=$(cat "$GIT_DIR"/rebase-apply/quiet)
239
git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
240
move_to_original_branch
241
exit
@@ -238,6 +253,7 @@ do
253
msgnum=$(cat "$dotest/msgnum")
254
msgnum=$(($msgnum + 1))
255
onto=$(cat "$dotest/onto")
256
+ GIT_QUIET=$(cat "$dotest/quiet")
257
while test "$msgnum" -le "$end"
258
do
259
call_merge "$msgnum"
@@ -249,6 +265,7 @@ do
265
head_name=$(cat "$GIT_DIR"/rebase-apply/head-name) &&
266
onto=$(cat "$GIT_DIR"/rebase-apply/onto) &&
267
orig_head=$(cat "$GIT_DIR"/rebase-apply/orig-head) &&
268
+ GIT_QUIET=$(cat "$GIT_DIR"/rebase-apply/quiet)
269
git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
270
move_to_original_branch
271
exit
@@ -260,9 +277,11 @@ do
277
git rerere clear
278
if test -d "$dotest"
279
then
280
+ GIT_QUIET=$(cat "$dotest/quiet")
281
move_to_original_branch
282
else
283
dotest="$GIT_DIR"/rebase-apply
284
+ GIT_QUIET=$(cat "$dotest/quiet")
285
move_to_original_branch
286
fi
287
git reset --hard $(cat "$dotest/orig-head")
@@ -300,6 +319,13 @@ do
319
-v|--verbose)
320
verbose=t
321
diffstat=t
322
+ GIT_QUIET=
323
+ ;;
324
+ -q|--quiet)
325
+ GIT_QUIET=t
326
+ git_am_opt="$git_am_opt -q"
327
+ verbose=
328
+ diffstat=
329
;;
330
--whitespace=*)
331
git_am_opt="$git_am_opt $1"
@@ -445,15 +471,15 @@ then
471
then
472
# Lazily switch to the target branch if needed...
473
test -z "$switch_to" || git checkout "$switch_to"
448
- echo >&2 "Current branch $branch_name is up to date."
474
+ say "Current branch $branch_name is up to date."
475
exit 0
476
else
451
- echo "Current branch $branch_name is up to date, rebase forced."
477
+ say "Current branch $branch_name is up to date, rebase forced."
478
fi
479
fi
480
481
# Detach HEAD and reset the tree
456
-echo "First, rewinding head to replay your work on top of it..."
482
+say "First, rewinding head to replay your work on top of it..."
483
git checkout -q "$onto^0" || die "could not detach HEAD"
484
git update-ref ORIG_HEAD $branch
485
@@ -471,7 +497,7 @@ fi
497
# we just fast forwarded.
498
if test "$mb" = "$branch"
499
then
474
- echo >&2 "Fast-forwarded $branch_name to $onto_name."
500
+ say "Fast-forwarded $branch_name to $onto_name."
501
move_to_original_branch
502
exit 0
503
fi
@@ -493,7 +519,8 @@ then
519
test 0 != $ret -a -d "$GIT_DIR"/rebase-apply &&
520
echo $head_name > "$GIT_DIR"/rebase-apply/head-name &&
521
echo $onto > "$GIT_DIR"/rebase-apply/onto &&
496
- echo $orig_head > "$GIT_DIR"/rebase-apply/orig-head
522
+ echo $orig_head > "$GIT_DIR"/rebase-apply/orig-head &&
523
+ echo "$GIT_QUIET" > "$GIT_DIR"/rebase-apply/quiet
524
exit $ret
525
fi
526
@@ -507,6 +534,7 @@ prev_head=$orig_head
534
echo "$prev_head" > "$dotest/prev_head"
535
echo "$orig_head" > "$dotest/orig-head"
536
echo "$head_name" > "$dotest/head-name"
537
+echo "$GIT_QUIET" > "$dotest/quiet"
538
539
msgnum=0
540
for cmt in `git rev-list --reverse --no-merges "$revisions"`
t/t3400-rebase.sh
+13
-6
@@ -54,8 +54,8 @@ test_expect_success 'rebase against master' '
54
git rebase master'
55
56
test_expect_success 'rebase against master twice' '
57
- git rebase master 2>err &&
58
- grep "Current branch my-topic-branch is up to date" err
57
+ git rebase master >out &&
58
+ grep "Current branch my-topic-branch is up to date" out
59
'
60
61
test_expect_success 'rebase against master twice with --force' '
@@ -65,14 +65,14 @@ test_expect_success 'rebase against master twice with --force' '
65
66
test_expect_success 'rebase against master twice from another branch' '
67
git checkout my-topic-branch^ &&
68
- git rebase master my-topic-branch 2>err &&
69
- grep "Current branch my-topic-branch is up to date" err
68
+ git rebase master my-topic-branch >out &&
69
+ grep "Current branch my-topic-branch is up to date" out
70
'
71
72
test_expect_success 'rebase fast-forward to master' '
73
git checkout my-topic-branch^ &&
74
- git rebase my-topic-branch 2>err &&
75
- grep "Fast-forwarded HEAD to my-topic-branch" err
74
+ git rebase my-topic-branch >out &&
75
+ grep "Fast-forwarded HEAD to my-topic-branch" out
76
'
77
78
test_expect_success \
@@ -126,4 +126,11 @@ test_expect_success 'Show verbose error when HEAD could not be detached' '
126
grep "Untracked working tree file .B. would be overwritten" output.err
127
'
128
129
+test_expect_success 'rebase -q is quiet' '
130
+ rm B &&
131
+ git checkout -b quiet topic &&
132
+ git rebase -q master > output.out 2>&1 &&
133
+ test ! -s output.out
134
+'
135
+
136
test_done
t/t4150-am.sh
+18
@@ -180,6 +180,17 @@ test_expect_success 'am -3 falls back to 3-way merge' '
180
test -z "$(git diff lorem)"
181
'
182
183
+test_expect_success 'am -3 -q is quiet' '
184
+ git reset master2 --hard &&
185
+ sed -n -e "3,\$p" msg >file &&
186
+ head -n 9 msg >>file &&
187
+ git add file &&
188
+ test_tick &&
189
+ git commit -m "copied stuff" &&
190
+ git am -3 -q lorem-move.patch > output.out 2>&1 &&
191
+ ! test -s output.out
192
+'
193
+
194
test_expect_success 'am pauses on conflict' '
195
git checkout lorem2^^ &&
196
test_must_fail git am lorem-move.patch &&
@@ -313,4 +324,11 @@ test_expect_success 'am newline in subject' '
324
grep "^Applying: second \\\n foo$" output.out
325
'
326
327
+test_expect_success 'am -q is quiet' '
328
+ git checkout first &&
329
+ test_tick &&
330
+ git am -q < patch1 > output.out 2>&1 &&
331
+ ! test -s output.out
332
+'
333
+
334
test_done