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