path: root/builtin/credential.c
diff options
authorJeff King <>2017-05-30 05:12:33 (GMT)
committerJunio C Hamano <>2017-05-30 05:45:03 (GMT)
commit42fa0cbfe02bfb5f3e11d6d04f0205e1650f2e39 (patch)
tree6de5592aaf7afd32ce581c52780014558c9b6648 /builtin/credential.c
parentf3a2fffe06d13b216cbc18acba5a46b8a00ae326 (diff)
credential: handle invalid arguments earlier
The git-credential command only takes one argument: the operation to perform. If we don't have one, we complain immediately. But if we have one that we don't recognize, we don't notice until after we've read the credential from stdin. This is likely to confuse a user invoking "git credential -h", as the program will hang waiting for their input before showing anything. Let's detect this case early. Likewise, we never noticed when there are extra arguments beyond the one we're expecting. Let's catch this with the same conditional. Note that we don't need to handle "--help" similarly, because the git wrapper does this before even calling cmd_credential(). Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/credential.c')
1 files changed, 2 insertions, 2 deletions
diff --git a/builtin/credential.c b/builtin/credential.c
index 0412fa0..879acfb 100644
--- a/builtin/credential.c
+++ b/builtin/credential.c
@@ -10,9 +10,9 @@ int cmd_credential(int argc, const char **argv, const char *prefix)
const char *op;
struct credential c = CREDENTIAL_INIT;
- op = argv[1];
- if (!op)
+ if (argc != 2 || !strcmp(argv[1], "-h"))
+ op = argv[1];
if (credential_read(&c, stdin) < 0)
die("unable to read credential from stdin");