git.txt: update description of the configuration mechanism
[git/mingw/4msysgit.git] / advice.c
blobedfbd4a6fb01a6905671d6d842d22c4869fad729
1 #include "cache.h"
3 int advice_push_nonfastforward = 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_status_hints = 1;
8 int advice_commit_before_merge = 1;
9 int advice_resolve_conflict = 1;
10 int advice_implicit_identity = 1;
11 int advice_detached_head = 1;
13 static struct {
14 const char *name;
15 int *preference;
16 } advice_config[] = {
17 { "pushnonfastforward", &advice_push_nonfastforward },
18 { "pushnonffcurrent", &advice_push_non_ff_current },
19 { "pushnonffdefault", &advice_push_non_ff_default },
20 { "pushnonffmatching", &advice_push_non_ff_matching },
21 { "statushints", &advice_status_hints },
22 { "commitbeforemerge", &advice_commit_before_merge },
23 { "resolveconflict", &advice_resolve_conflict },
24 { "implicitidentity", &advice_implicit_identity },
25 { "detachedhead", &advice_detached_head },
28 void advise(const char *advice, ...)
30 struct strbuf buf = STRBUF_INIT;
31 va_list params;
32 const char *cp, *np;
34 va_start(params, advice);
35 strbuf_vaddf(&buf, advice, params);
36 va_end(params);
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++;
44 strbuf_release(&buf);
47 int git_default_advice_config(const char *var, const char *value)
49 const char *k = skip_prefix(var, "advice.");
50 int i;
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;
59 return 0;
62 int error_resolve_conflict(const char *me)
64 error("'%s' is not possible because you have unmerged files.", me);
65 if (advice_resolve_conflict)
67 * Message used both when 'git commit' fails and when
68 * other commands doing a merge do.
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'."));
74 return -1;
77 void NORETURN die_resolve_conflict(const char *me)
79 error_resolve_conflict(me);
80 die("Exiting because of an unresolved conflict.");
83 void detach_advice(const char *new_name)
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";
94 fprintf(stderr, fmt, new_name);