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