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