Skip to contentSkip to conversation

Output from "rev-parse --resolve-git-dir" changed: two lines (prints original argument)

PATCH In review Daniel Hahler 3 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

I have noticed that the output from "git rev-parse --resolve-git-dir" changed.

While it used to only print the resolved git dir, it now prints the argument passed to it itself:

    % git rev-parse --resolve-git-dir .git
    /path/to/root/.git/modules/vim/bundle/reporoot
    .git

This is with Git version 1.8.5.3, but also happens with master.

You can use "--flags" to avoid this ("git rev-parse --flags --resolve-git-dir .git"), but it is unclear from the documentation if that's the intended beahviour.

It seems like the "--resolve-git-dir" subcommand needs to consume the argument passed to it.

Regards,
Daniel.

Signature · 1 line
http://daniel.hahler.de/
#1 lore raw

PATCH 1/1 rev-parse: fix --resolve-git-dir argument handling

There are two problems here:

1) If no argument is provided, then the command segfaults
2) The argument is not consumed, so there will be excess output

Fix both of these in one go by restructuring the handler for this option.

---
 builtin/rev-parse.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
builtin/rev-parse.c +5 -2
index aaeb611..645cc4a 100644
@@ -738,9 +738,12 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 				continue;
 			}
 			if (!strcmp(arg, "--resolve-git-dir")) {
-				const char *gitdir = resolve_gitdir(argv[i+1]);
+				const char *gitdir;
+				if (++i >= argc)
+					die("--resolve-git-dir requires an argument");
+				gitdir = resolve_gitdir(argv[i]);
 				if (!gitdir)
-					die("not a gitdir '%s'", argv[i+1]);
+					die("not a gitdir '%s'", argv[i]);
 				puts(gitdir);
 				continue;
 			}
Signature · 1 line
1.9.0.6.g037df60.dirty
#2 lore raw

Re: [PATCH] rev-parse: fix --resolve-git-dir argument handling

Quoted 11 lines · John Keeping

There are two problems here:

1) If no argument is provided, then the command segfaults
2) The argument is not consumed, so there will be excess output

Fix both of these in one go by restructuring the handler for this option.

---

Looks sensible; thanks.

Quoted 22 lines
 builtin/rev-parse.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
builtin/rev-parse.c +5 -2
index aaeb611..645cc4a 100644
@@ -738,9 +738,12 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 				continue;
 			}
 			if (!strcmp(arg, "--resolve-git-dir")) {
-				const char *gitdir = resolve_gitdir(argv[i+1]);
+				const char *gitdir;
+				if (++i >= argc)
+					die("--resolve-git-dir requires an argument");
+				gitdir = resolve_gitdir(argv[i]);
 				if (!gitdir)
-					die("not a gitdir '%s'", argv[i+1]);
+					die("not a gitdir '%s'", argv[i]);
 				puts(gitdir);
 				continue;
 			}
#3 lore raw

Re: [PATCH] rev-parse: fix --resolve-git-dir argument handling

Quoted 7 lines · Junio C Hamano
Quoted 5 lines · John Keeping

There are two problems here:

1) If no argument is provided, then the command segfaults
2) The argument is not consumed, so there will be excess output

Quoted 8 lines
Quoted 6 lines

Fix both of these in one go by restructuring the handler for this option.

---

Looks sensible; thanks.

Ehh, I spoke too fast. Don't we already have this queued as a43219f2 (rev-parse: check i before using argv[i] against argc, 2014-01-28)?

#4 lore raw

Re: [PATCH] rev-parse: fix --resolve-git-dir argument handling

Quoted 12 lines · Junio C Hamano
Quoted 10 lines · Junio C Hamano
Quoted 8 lines · John Keeping

There are two problems here:

1) If no argument is provided, then the command segfaults
2) The argument is not consumed, so there will be excess output

Fix both of these in one go by restructuring the handler for this option.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

---

Looks sensible; thanks.

Ehh, I spoke too fast. Don't we already have this queued as a43219f2 (rev-parse: check i before using argv[i] against argc, 2014-01-28)?

Yes, and it catches more cases than mine. I only checked against master and had missed that when it went past on the list.