git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] add a quiet option to git-checkout

From
Nicolas Pitre <nico@cam.org>
Date
Feb 1, 2007, 17:31 UTC
Message-ID
<Pine.LNX.4.64.0702011230320.3021@xanadu.home>

Those new messages are certainly nice, but there might be cases where they are simply unwelcome, like when git-commit is used within scripts.

Signed-off-by: Nicolas Pitre <nico@cam.org>
---
 Documentation/git-checkout.txt |    5 ++++-
 git-checkout.sh                |   23 ++++++++++++++---------
 2 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
index 4ea2b31..55c9289 100644
--- a/Documentation/git-checkout.txt
+++ b/Documentation/git-checkout.txt
@@ -8,7 +8,7 @@ git-checkout - Checkout and switch to a branch
 SYNOPSIS
 --------
 [verse]
-'git-checkout' [-f] [-b <new_branch> [-l]] [-m] [<branch>]
+'git-checkout' [-q] [-f] [-b <new_branch> [-l]] [-m] [<branch>]
 'git-checkout' [<tree-ish>] <paths>...
 
 DESCRIPTION
@@ -33,6 +33,9 @@ working tree.
 
 OPTIONS
 -------
+-q::
+	Quiet, supress feedback messages.
+
 -f::
 	Force a re-read of everything.
 
diff --git a/git-checkout.sh b/git-checkout.sh
index 97c26ad..99a81f5 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-USAGE='[-f] [-b <new_branch>] [-m] [<branch>] [<paths>...]'
+USAGE='[-q] [-f] [-b <new_branch>] [-m] [<branch>] [<paths>...]'
 SUBDIRECTORY_OK=Sometimes
 . git-sh-setup
 require_work_tree
@@ -15,6 +15,7 @@ branch=
 newbranch=
 newbranch_log=
 merge=
+quiet=
 LF='
 '
 while [ "$#" != "0" ]; do
@@ -40,6 +41,9 @@ while [ "$#" != "0" ]; do
 	-m)
 		merge=1
 		;;
+	"-q")
+		quiet=1
+		;;
 	--)
 		break
 		;;
@@ -153,7 +157,7 @@ detach_warn=
 if test -z "$branch$newbranch" && test "$new" != "$old"
 then
 	detached="$new"
-	if test -n "$oldbranch"
+	if test -n "$oldbranch" && test -z "$quiet"
 	then
 		detach_warn="Note: moving to \"$new_name\" which isn't a local branch
 If you want to create a new branch from this checkout, you may do so
@@ -180,8 +184,11 @@ fi
 
 if [ "X$old" = X ]
 then
-	echo >&2 "warning: You appear to be on a branch yet to be born."
-	echo >&2 "warning: Forcing checkout of $new_name."
+	if test -z "$quiet"
+	then
+		echo >&2 "warning: You appear to be on a branch yet to be born."
+		echo >&2 "warning: Forcing checkout of $new_name."
+	fi
 	force=1
 fi
 
@@ -226,7 +233,7 @@ else
 	exit 0
     )
     saved_err=$?
-    if test "$saved_err" = 0
+    if test "$saved_err" = 0 && test -z "$quiet"
     then
 	git diff-index --name-status "$new"
     fi
@@ -251,11 +258,9 @@ if [ "$?" -eq 0 ]; then
 	if test -n "$branch"
 	then
 		GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD "refs/heads/$branch"
-		if test -n "$newbranch"
+		if test -z "$quiet"
 		then
-			echo >&2 "Switched to a new branch \"$branch\""
-		else
-			echo >&2 "Switched to branch \"$branch\""
+			echo >&2 "Switched to${newbranch:+ a new} branch \"$branch\""
 		fi
 	elif test -n "$detached"
 	then
-- 
1.5.0.rc2.131.g4b01-dirty
Message 1 of 1 in “add a quiet option to git-checkout”
  1. 2/3 add a quiet option to git-checkoutNicolas Pitre, Feb 1, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.