]>
Commit | Line | Data |
---|---|---|
75194438 JK |
1 | #include "cache.h" |
2 | ||
3 | int advice_push_nonfastforward = 1; | |
edf563fb | 4 | int advice_status_hints = 1; |
4c371f91 | 5 | int advice_commit_before_merge = 1; |
d38a30df | 6 | int advice_resolve_conflict = 1; |
b706fcfe | 7 | int advice_implicit_identity = 1; |
13be3e31 | 8 | int advice_detached_head = 1; |
75194438 JK |
9 | |
10 | static struct { | |
11 | const char *name; | |
12 | int *preference; | |
13 | } advice_config[] = { | |
14 | { "pushnonfastforward", &advice_push_nonfastforward }, | |
edf563fb | 15 | { "statushints", &advice_status_hints }, |
4c371f91 | 16 | { "commitbeforemerge", &advice_commit_before_merge }, |
d38a30df | 17 | { "resolveconflict", &advice_resolve_conflict }, |
b706fcfe | 18 | { "implicitidentity", &advice_implicit_identity }, |
13be3e31 | 19 | { "detachedhead", &advice_detached_head }, |
75194438 JK |
20 | }; |
21 | ||
38ef61cf RR |
22 | void advise(const char *advice, ...) |
23 | { | |
23cb5bf3 | 24 | struct strbuf buf = STRBUF_INIT; |
38ef61cf | 25 | va_list params; |
23cb5bf3 | 26 | const char *cp, *np; |
38ef61cf RR |
27 | |
28 | va_start(params, advice); | |
23cb5bf3 | 29 | strbuf_addf(&buf, advice, params); |
38ef61cf | 30 | va_end(params); |
23cb5bf3 JH |
31 | |
32 | for (cp = buf.buf; *cp; cp = np) { | |
33 | np = strchrnul(cp, '\n'); | |
34 | fprintf(stderr, _("hint: %.*s\n"), (int)(np - cp), cp); | |
35 | if (*np) | |
36 | np++; | |
37 | } | |
38 | strbuf_release(&buf); | |
38ef61cf RR |
39 | } |
40 | ||
75194438 JK |
41 | int git_default_advice_config(const char *var, const char *value) |
42 | { | |
43 | const char *k = skip_prefix(var, "advice."); | |
44 | int i; | |
45 | ||
46 | for (i = 0; i < ARRAY_SIZE(advice_config); i++) { | |
47 | if (strcmp(k, advice_config[i].name)) | |
48 | continue; | |
49 | *advice_config[i].preference = git_config_bool(var, value); | |
50 | return 0; | |
51 | } | |
52 | ||
53 | return 0; | |
54 | } | |
d38a30df | 55 | |
38ef61cf | 56 | int error_resolve_conflict(const char *me) |
d38a30df | 57 | { |
38ef61cf | 58 | error("'%s' is not possible because you have unmerged files.", me); |
23cb5bf3 | 59 | if (advice_resolve_conflict) |
d38a30df MM |
60 | /* |
61 | * Message used both when 'git commit' fails and when | |
62 | * other commands doing a merge do. | |
63 | */ | |
23cb5bf3 JH |
64 | advise(_("Fix them up in the work tree,\n" |
65 | "and then use 'git add/rm <file>' as\n" | |
66 | "appropriate to mark resolution and make a commit,\n" | |
67 | "or use 'git commit -a'.")); | |
38ef61cf RR |
68 | return -1; |
69 | } | |
70 | ||
71 | void NORETURN die_resolve_conflict(const char *me) | |
72 | { | |
73 | error_resolve_conflict(me); | |
74 | die("Exiting because of an unresolved conflict."); | |
d38a30df | 75 | } |
2857093b NTND |
76 | |
77 | void detach_advice(const char *new_name) | |
78 | { | |
79 | const char fmt[] = | |
80 | "Note: checking out '%s'.\n\n" | |
81 | "You are in 'detached HEAD' state. You can look around, make experimental\n" | |
82 | "changes and commit them, and you can discard any commits you make in this\n" | |
83 | "state without impacting any branches by performing another checkout.\n\n" | |
84 | "If you want to create a new branch to retain commits you create, you may\n" | |
85 | "do so (now or later) by using -b with the checkout command again. Example:\n\n" | |
86 | " git checkout -b new_branch_name\n\n"; | |
87 | ||
88 | fprintf(stderr, fmt, new_name); | |
89 | } |