summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keeping <john@keeping.me.uk>2014-02-17 08:46:20 +0000
committerJunio C Hamano <gitster@pobox.com>2014-02-18 16:03:37 -0800
commitb5448a90c97a06c72dd7420fa63fd5de974f411b (patch)
tree550d83b931d972de3e09bf4adc204547ac71448a
parent7bbc4e8fdb33e0a8e42e77cc05460d4c4f615f4d (diff)
downloadgit-jk/rev-parse-resolve-git-dir.tar.gz
rev-parse: fix --resolve-git-dir argument handlingjk/rev-parse-resolve-git-dir
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. Reported-by: Daniel Hahler <genml+git-2014@thequod.de> Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/rev-parse.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index c4b768ffda..7ca031154c 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -715,9 +715,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;
}