mirror of
https://github.com/git/git.git
synced 2024-11-01 14:57:52 +01:00
42fa0cbfe0
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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
31 lines
695 B
C
31 lines
695 B
C
#include "git-compat-util.h"
|
|
#include "credential.h"
|
|
#include "builtin.h"
|
|
|
|
static const char usage_msg[] =
|
|
"git credential [fill|approve|reject]";
|
|
|
|
int cmd_credential(int argc, const char **argv, const char *prefix)
|
|
{
|
|
const char *op;
|
|
struct credential c = CREDENTIAL_INIT;
|
|
|
|
if (argc != 2 || !strcmp(argv[1], "-h"))
|
|
usage(usage_msg);
|
|
op = argv[1];
|
|
|
|
if (credential_read(&c, stdin) < 0)
|
|
die("unable to read credential from stdin");
|
|
|
|
if (!strcmp(op, "fill")) {
|
|
credential_fill(&c);
|
|
credential_write(&c, stdout);
|
|
} else if (!strcmp(op, "approve")) {
|
|
credential_approve(&c);
|
|
} else if (!strcmp(op, "reject")) {
|
|
credential_reject(&c);
|
|
} else {
|
|
usage(usage_msg);
|
|
}
|
|
return 0;
|
|
}
|