sparse-checkout: free sparse_filename after use
[git.git] / builtin / credential.c
blobb72e76dd9a610f866b45f635f45bbf5b1ac45744
1 #include "git-compat-util.h"
2 #include "credential.h"
3 #include "builtin.h"
4 #include "config.h"
6 static const char usage_msg[] =
7 "git credential (fill|approve|reject)";
9 int cmd_credential(int argc, const char **argv, const char *prefix UNUSED)
11 const char *op;
12 struct credential c = CREDENTIAL_INIT;
14 git_config(git_default_config, NULL);
16 if (argc != 2 || !strcmp(argv[1], "-h"))
17 usage(usage_msg);
18 op = argv[1];
20 if (!strcmp(op, "capability")) {
21 credential_set_all_capabilities(&c, CREDENTIAL_OP_INITIAL);
22 credential_announce_capabilities(&c, stdout);
23 return 0;
26 if (credential_read(&c, stdin, CREDENTIAL_OP_INITIAL) < 0)
27 die("unable to read credential from stdin");
29 if (!strcmp(op, "fill")) {
30 credential_fill(&c, 0);
31 credential_next_state(&c);
32 credential_write(&c, stdout, CREDENTIAL_OP_RESPONSE);
33 } else if (!strcmp(op, "approve")) {
34 credential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);
35 credential_approve(&c);
36 } else if (!strcmp(op, "reject")) {
37 credential_set_all_capabilities(&c, CREDENTIAL_OP_HELPER);
38 credential_reject(&c);
39 } else {
40 usage(usage_msg);
43 credential_clear(&c);
44 return 0;