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