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

[PATCH v2 1/2] rev-parse: remove restrictions on some options

From
John Keeping <john@keeping.me.uk>
Date
Jul 21, 2013, 12:49 UTC
Message-ID
<f1f8ff52a8b8dc70803bba0eb8fb7f9f82ddfd5b.1374410829.git.john@keeping.me.uk>
In-Reply-To
<cover.1374410829.git.john@keeping.me.uk>

The "--local-env-vars" and "--resolve-git-dir" arguments to git-rev-parse are currently only handled if they appear first on the command line (in the case of "--local-env-vars", only if it is the only argument). While it may not make sense to use these options when any others are specified, there is no reason for this restriction and it might confuse users if these arguments appear to be ignored.

There is no need for any documentation change here as the restrictions on these options are not documented.

Signed-off-by: John Keeping <john@keeping.me.uk>
---
 builtin/rev-parse.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index de894c7..c9aa28f 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -486,21 +486,6 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 	if (argc > 1 && !strcmp("--sq-quote", argv[1]))
 		return cmd_sq_quote(argc - 2, argv + 2);
 
-	if (argc == 2 && !strcmp("--local-env-vars", argv[1])) {
-		int i;
-		for (i = 0; local_repo_env[i]; i++)
-			printf("%s\n", local_repo_env[i]);
-		return 0;
-	}
-
-	if (argc > 2 && !strcmp(argv[1], "--resolve-git-dir")) {
-		const char *gitdir = resolve_gitdir(argv[2]);
-		if (!gitdir)
-			die("not a gitdir '%s'", argv[2]);
-		puts(gitdir);
-		return 0;
-	}
-
 	if (argc > 1 && !strcmp("-h", argv[1]))
 		usage(builtin_rev_parse_usage);
 
@@ -661,6 +646,12 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 				for_each_remote_ref(show_reference, NULL);
 				continue;
 			}
+			if (!strcmp(arg, "--local-env-vars")) {
+				int i;
+				for (i = 0; local_repo_env[i]; i++)
+					printf("%s\n", local_repo_env[i]);
+				continue;
+			}
 			if (!strcmp(arg, "--show-toplevel")) {
 				const char *work_tree = get_git_work_tree();
 				if (work_tree)
@@ -711,6 +702,13 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 				printf("%s%s.git\n", cwd, len && cwd[len-1] != '/' ? "/" : "");
 				continue;
 			}
+			if (!strcmp(arg, "--resolve-git-dir")) {
+				const char *gitdir = resolve_gitdir(argv[i+1]);
+				if (!gitdir)
+					die("not a gitdir '%s'", argv[i+1]);
+				puts(gitdir);
+				continue;
+			}
 			if (!strcmp(arg, "--is-inside-git-dir")) {
 				printf("%s\n", is_inside_git_dir() ? "true"
 						: "false");
-- 
1.8.3.3.972.gc83849e.dirty
Previous: John KeepingNext: John Keeping
Message 4 of 6 in “rev-parse(1): logically group options”
  1. rev-parse(1): logically group optionsJohn Keeping, Jul 18, 2013
  2. Junio C HamanoJul 19, 2013
  3. 0/2 Improvements to rev-parse option handlingJohn Keeping, Jul 21, 2013
  4. 1/2 rev-parse: remove restrictions on some optionsJohn Keeping, Jul 21, 2013
  5. 2/2 rev-parse(1): logically group optionsJohn Keeping, Jul 21, 2013
  6. Junio C HamanoJul 22, 2013

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.