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

[PATCH] git-reset: add -q option to operate quietly

From
Gerrit Pape <pape@smarden.org>
Date
Nov 4, 2007, 09:37 UTC
Message-ID
<20071104093720.6950.qmail@e7d9732ff18748.315fe32.mid.smarden.org>

Many git commands have a -q option to suppress output to stdout, let's have it for git-reset too.

This was asked for by Joey Hess through
 http://bugs.debian.org/444933
Signed-off-by: Gerrit Pape <pape@smarden.org>
---
 Documentation/git-reset.txt |    7 +++++--
 builtin-reset.c             |   14 ++++++++++----
 2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/Documentation/git-reset.txt b/Documentation/git-reset.txt
index 87afa6f..050e4ea 100644
--- a/Documentation/git-reset.txt
+++ b/Documentation/git-reset.txt
@@ -8,8 +8,8 @@ git-reset - Reset current HEAD to the specified state
 SYNOPSIS
 --------
 [verse]
-'git-reset' [--mixed | --soft | --hard] [<commit>]
-'git-reset' [--mixed] <commit> [--] <paths>...
+'git-reset' [--mixed | --soft | --hard] [-q] [<commit>]
+'git-reset' [--mixed] [-q] <commit> [--] <paths>...
 
 DESCRIPTION
 -----------
@@ -45,6 +45,9 @@ OPTIONS
 	switched to. Any changes to tracked files in the working tree
 	since <commit> are lost.
 
+-q::
+	Be quiet, only report errors.
+
 <commit>::
 	Commit to make the current HEAD.
 
diff --git a/builtin-reset.c b/builtin-reset.c
index e1dc31e..dd301df 100644
--- a/builtin-reset.c
+++ b/builtin-reset.c
@@ -18,7 +18,7 @@
 #include "tree.h"
 
 static const char builtin_reset_usage[] =
-"git-reset [--mixed | --soft | --hard]  [<commit-ish>] [ [--] <paths>...]";
+"git-reset [--mixed | --soft | --hard] [-q] [<commit-ish>] [ [--] <paths>...]";
 
 static char *args_to_str(const char **argv)
 {
@@ -173,7 +173,7 @@ static const char *reset_type_names[] = { "mixed", "soft", "hard", NULL };
 
 int cmd_reset(int argc, const char **argv, const char *prefix)
 {
-	int i = 1, reset_type = NONE, update_ref_status = 0;
+	int i = 1, reset_type = NONE, update_ref_status = 0, quiet = 0;
 	const char *rev = "HEAD";
 	unsigned char sha1[20], *orig = NULL, sha1_orig[20],
 				*old_orig = NULL, sha1_old_orig[20];
@@ -185,7 +185,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 	reflog_action = args_to_str(argv);
 	setenv("GIT_REFLOG_ACTION", reflog_action, 0);
 
-	if (i < argc) {
+	while (i < argc) {
 		if (!strcmp(argv[i], "--mixed")) {
 			reset_type = MIXED;
 			i++;
@@ -198,6 +198,12 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 			reset_type = HARD;
 			i++;
 		}
+		else if (!strcmp(argv[i], "-q")) {
+			quiet = 1;
+			i++;
+		}
+		else
+			break;
 	}
 
 	if (i < argc && argv[i][0] != '-')
@@ -258,7 +264,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 
 	switch (reset_type) {
 	case HARD:
-		if (!update_ref_status)
+		if (!update_ref_status && !quiet)
 			print_new_head_line(commit);
 		break;
 	case SOFT: /* Nothing else to do. */
-- 
1.5.3.5
Message 1 of 1 in “git-reset: add -q option to operate quietly”
  1. git-reset: add -q option to operate quietlyGerrit Pape, Nov 4, 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.