]> git.ipfire.org Git - thirdparty/git.git/blame - advice.c
GIT-VERSION-GEN: support non-standard $GIT_DIR path
[thirdparty/git.git] / advice.c
CommitLineData
75194438
JK
1#include "cache.h"
2
3int advice_push_nonfastforward = 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[] = {
17 { "pushnonfastforward", &advice_push_nonfastforward },
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 },
75194438
JK
26};
27
38ef61cf
RR
28void advise(const char *advice, ...)
29{
23cb5bf3 30 struct strbuf buf = STRBUF_INIT;
38ef61cf 31 va_list params;
23cb5bf3 32 const char *cp, *np;
38ef61cf
RR
33
34 va_start(params, advice);
447b99c8 35 strbuf_vaddf(&buf, advice, params);
38ef61cf 36 va_end(params);
23cb5bf3
JH
37
38 for (cp = buf.buf; *cp; cp = np) {
39 np = strchrnul(cp, '\n');
40 fprintf(stderr, _("hint: %.*s\n"), (int)(np - cp), cp);
41 if (*np)
42 np++;
43 }
44 strbuf_release(&buf);
38ef61cf
RR
45}
46
75194438
JK
47int git_default_advice_config(const char *var, const char *value)
48{
49 const char *k = skip_prefix(var, "advice.");
50 int i;
51
52 for (i = 0; i < ARRAY_SIZE(advice_config); i++) {
53 if (strcmp(k, advice_config[i].name))
54 continue;
55 *advice_config[i].preference = git_config_bool(var, value);
56 return 0;
57 }
58
59 return 0;
60}
d38a30df 61
38ef61cf 62int error_resolve_conflict(const char *me)
d38a30df 63{
38ef61cf 64 error("'%s' is not possible because you have unmerged files.", me);
23cb5bf3 65 if (advice_resolve_conflict)
d38a30df
MM
66 /*
67 * Message used both when 'git commit' fails and when
68 * other commands doing a merge do.
69 */
23cb5bf3
JH
70 advise(_("Fix them up in the work tree,\n"
71 "and then use 'git add/rm <file>' as\n"
72 "appropriate to mark resolution and make a commit,\n"
73 "or use 'git commit -a'."));
38ef61cf
RR
74 return -1;
75}
76
77void NORETURN die_resolve_conflict(const char *me)
78{
79 error_resolve_conflict(me);
80 die("Exiting because of an unresolved conflict.");
d38a30df 81}
2857093b
NTND
82
83void detach_advice(const char *new_name)
84{
85 const char fmt[] =
86 "Note: checking out '%s'.\n\n"
87 "You are in 'detached HEAD' state. You can look around, make experimental\n"
88 "changes and commit them, and you can discard any commits you make in this\n"
89 "state without impacting any branches by performing another checkout.\n\n"
90 "If you want to create a new branch to retain commits you create, you may\n"
91 "do so (now or later) by using -b with the checkout command again. Example:\n\n"
92 " git checkout -b new_branch_name\n\n";
93
94 fprintf(stderr, fmt, new_name);
95}