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