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

[RFC PATCH] Make rev-parse -q and --is-* quiet

From
EAErlend Aasland <erlend-a@innova.no>
Date
Mar 13, 2020, 12:13 UTC
Message-ID
<4B2A0C64-FD4A-457C-A7CF-5B680AF38BC9@innova.no>

If rev-parse is called with both -q and an --is-* option, the result is provided as the return code of the command, iso. printed to stdout.

This simplifies using these queries in shell scripts: git rev-parse --is-bare-repository && do_stuff git rev-parse --is-shallow-repository && do_stuff

Signed-off-by: Erlend E. Aasland <erlend.aasland@innova.no>
---
builtin/rev-parse.c | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 7a00da8203..5a8b404ec7 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -874,24 +874,31 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
				continue;
			}
			if (!strcmp(arg, "--is-inside-git-dir")) {
-				printf("%s\n", is_inside_git_dir() ? "true"
-						: "false");
+				int is_set = is_inside_git_dir();
+				if (quiet)
+					return is_set ? 0 : 1;
+				printf("%s\n", is_set ? "true" : "false");
				continue;
			}
			if (!strcmp(arg, "--is-inside-work-tree")) {
-				printf("%s\n", is_inside_work_tree() ? "true"
-						: "false");
+				int is_set = is_inside_work_tree();
+				if (quiet)
+					return is_set ? 0 : 1;
+				printf("%s\n", is_set ? "true" : "false");
				continue;
			}
			if (!strcmp(arg, "--is-bare-repository")) {
-				printf("%s\n", is_bare_repository() ? "true"
-						: "false");
+				int is_set = is_bare_repository();
+				if (quiet)
+					return is_set ? 0 : 1;
+				printf("%s\n", is_set ? "true" : "false");
				continue;
			}
			if (!strcmp(arg, "--is-shallow-repository")) {
-				printf("%s\n",
-						is_repository_shallow(the_repository) ? "true"
-						: "false");
+				int is_set = is_repository_shallow(the_repository);
+				if (quiet)
+					return is_set ? 0 : 1;
+				printf("%s\n", is_set ? "true" : "false");
				continue;
			}
			if (!strcmp(arg, "--shared-index-path")) {
-- 
2.25.1
Next: Jeff King
Message 1 of 2 in “Make rev-parse -q and --is-* quiet”
  1. Make rev-parse -q and --is-* quietErlend Aasland, Mar 13, 2020
  2. Jeff KingMar 13, 2020

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.