Merge branch 'master' of git://git.kernel.org/pub/scm/git/git
[git/jnareb-git.git] / advice.c
bloba8deee6e6419a1e867e06e90a70300cd2e01b556
1 #include "cache.h"
3 int advice_push_update_rejected = 1;
4 int advice_push_non_ff_current = 1;
5 int advice_push_non_ff_default = 1;
6 int advice_push_non_ff_matching = 1;
7 int advice_push_already_exists = 1;
8 int advice_push_fetch_first = 1;
9 int advice_push_needs_force = 1;
10 int advice_status_hints = 1;
11 int advice_status_u_option = 1;
12 int advice_commit_before_merge = 1;
13 int advice_resolve_conflict = 1;
14 int advice_implicit_identity = 1;
15 int advice_detached_head = 1;
16 int advice_set_upstream_failure = 1;
18 static struct {
19 const char *name;
20 int *preference;
21 } advice_config[] = {
22 { "pushupdaterejected", &advice_push_update_rejected },
23 { "pushnonffcurrent", &advice_push_non_ff_current },
24 { "pushnonffdefault", &advice_push_non_ff_default },
25 { "pushnonffmatching", &advice_push_non_ff_matching },
26 { "pushalreadyexists", &advice_push_already_exists },
27 { "pushfetchfirst", &advice_push_fetch_first },
28 { "pushneedsforce", &advice_push_needs_force },
29 { "statushints", &advice_status_hints },
30 { "statusuoption", &advice_status_u_option },
31 { "commitbeforemerge", &advice_commit_before_merge },
32 { "resolveconflict", &advice_resolve_conflict },
33 { "implicitidentity", &advice_implicit_identity },
34 { "detachedhead", &advice_detached_head },
35 { "setupstreamfailure", &advice_set_upstream_failure },
37 /* make this an alias for backward compatibility */
38 { "pushnonfastforward", &advice_push_update_rejected }
41 void advise(const char *advice, ...)
43 struct strbuf buf = STRBUF_INIT;
44 va_list params;
45 const char *cp, *np;
47 va_start(params, advice);
48 strbuf_vaddf(&buf, advice, params);
49 va_end(params);
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++;
57 strbuf_release(&buf);
60 int git_default_advice_config(const char *var, const char *value)
62 const char *k = skip_prefix(var, "advice.");
63 int i;
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;
72 return 0;
75 int error_resolve_conflict(const char *me)
77 error("'%s' is not possible because you have unmerged files.", me);
78 if (advice_resolve_conflict)
80 * Message used both when 'git commit' fails and when
81 * other commands doing a merge do.
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'."));
87 return -1;
90 void NORETURN die_resolve_conflict(const char *me)
92 error_resolve_conflict(me);
93 die("Exiting because of an unresolved conflict.");
96 void detach_advice(const char *new_name)
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";
107 fprintf(stderr, fmt, new_name);