Skip to content

Commit 42fa0cb

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f3a2fff commit 42fa0cb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

builtin/credential.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ int cmd_credential(int argc, const char **argv, const char *prefix)
1010
const char *op;
1111
struct credential c = CREDENTIAL_INIT;
1212

13-
op = argv[1];
14-
if (!op)
13+
if (argc != 2 || !strcmp(argv[1], "-h"))
1514
usage(usage_msg);
15+
op = argv[1];
1616

1717
if (credential_read(&c, stdin) < 0)
1818
die("unable to read credential from stdin");

0 commit comments

Comments
 (0)