The eleventh batch
[git/gitster.git] / builtin / credential.c
blob14c8c6608b2fbd7091a11c14537d08783d5c281d
1 #define USE_THE_REPOSITORY_VARIABLE
3 #include "git-compat-util.h"
4 #include "credential.h"
5 #include "builtin.h"
6 #include "config.h"
8 static const char usage_msg[] =
9 "git credential (fill|approve|reject)";
11 int cmd_credential(int argc,
12 const char **argv,
13 const char *prefix UNUSED,
14 struct repository *repo UNUSED)
16 const char *op;
17 struct credential c = CREDENTIAL_INIT;
19 git_config(git_default_config, NULL);
21 if (argc != 2 || !strcmp(argv[1], "-h"))
22 usage(usage_msg);
23 op = argv[1];
25 if (!strcmp(op, "capability")) {
26 credential_set_all_capabilities(&c, CREDENTIAL_OP_INITIAL);
27 credential_announce_capabilities(&c, stdout);
28 return 0;
31 if (credential_read(&c, stdin, CREDENTIAL_OP_INITIAL) < 0)
32 die("unable to read credential from stdin");
34 if (!strcmp(op, "fill")) {
35 credential_fill(&c, 0);
36 credential_next_state(&c);
37 credential_write(&c, stdout, CREDENTIAL_OP_RESPONSE);
38 } else if (!strcmp(op, "approve")) {
39 credential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);
40 credential_approve(&c);
41 } else if (!strcmp(op, "reject")) {
42 credential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);
43 credential_reject(&c);
44 } else {
45 usage(usage_msg);
48 credential_clear(&c);
49 return 0;