Thread (4 messages) flat view 4 messages, 1 author, 2016-06-15
DORMANTno replies

[PATCH] Add a quiet option to git merge

From: Iustin Pop <hidden>
Date: 2016-06-15 22:44:21
Subsystem: documentation, the rest · Maintainers: Jonathan Corbet, Linus Torvalds

Currently it's not possible to do quiet merges in case of no changes
because git merge always outputs the 'Already up to date' message.

This small patch adds a quiet option to git merge that in this case will
skip the output of this message. It also adds a test for this new
option.

Signed-off-by: Iustin Pop <redacted>
---
 This new version has a test too for this option but I'm not sure if
 it's the right place to add it.

 Documentation/git-merge.txt     |    2 +-
 Documentation/merge-options.txt |    4 ++++
 git-merge.sh                    |   19 +++++++++++++------
 t/t7600-merge.sh                |    5 +++++
 4 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt
index c136b10..0c4cd19 100644
--- a/Documentation/git-merge.txt
+++ b/Documentation/git-merge.txt
@@ -9,7 +9,7 @@ git-merge - Join two or more development histories together
 SYNOPSIS
 --------
 [verse]
-'git-merge' [-n] [--summary] [--no-commit] [--squash] [-s <strategy>]...
+'git-merge' [-n] [-q] [--summary] [--no-commit] [--squash] [-s <strategy>]...
 	[-m <msg>] <remote> <remote>...
 'git-merge' <msg> HEAD <remote>...
 
diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt
index 9f1fc82..dbedf40 100644
--- a/Documentation/merge-options.txt
+++ b/Documentation/merge-options.txt
@@ -5,6 +5,10 @@
 -n, \--no-summary::
 	Do not show diffstat at the end of the merge.
 
+-q, \--quiet::
+	Supress the 'Already up to date' message if no merge is
+	needed.
+
 --no-commit::
 	Perform the merge but pretend the merge failed and do
 	not autocommit, to give the user a chance to inspect and
diff --git a/git-merge.sh b/git-merge.sh
index 7dbbb1d..625457e 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -15,6 +15,7 @@ commit               perform a commit if the merge sucesses (default)
 ff                   allow fast forward (default)
 s,strategy=          merge strategy to use
 m,message=           message to be used for the merge commit (if any)
+q,quiet              suppress some default messages
 "
 
 SUBDIRECTORY_OK=Yes
@@ -38,6 +39,7 @@ use_strategies=
 allow_fast_forward=t
 allow_trivial_merge=t
 squash= no_commit=
+quiet=
 
 dropsave() {
 	rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" \
@@ -59,12 +61,15 @@ restorestate() {
 }
 
 finish_up_to_date () {
-	case "$squash" in
-	t)
-		echo "$1 (nothing to squash)" ;;
-	'')
-		echo "$1" ;;
-	esac
+	if test -z "$quiet"
+	then
+		case "$squash" in
+		t)
+			echo "$1 (nothing to squash)" ;;
+		'')
+			echo "$1" ;;
+		esac
+	fi
 	dropsave
 }
 
@@ -182,6 +187,8 @@ parse_config () {
 			merge_msg="$1"
 			have_message=t
 			;;
+		-q|--quiet)
+			quiet=t ;;
 		--)
 			shift
 			break ;;
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index 5d16628..cb7e2e4 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -247,6 +247,11 @@ test_expect_success 'test option parsing' '
 	then
 		echo "[OOPS] missing commit references accepted"
 		false
+	fi &&
+	if ! git merge --quiet c1
+	then
+		echo "[OOPS] quiet not accepted"
+		false
 	fi
 '
 
-- 
1.5.4.3
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help