Merge branch 'bc/commit-complete-lines-given-via-m-option' into maint
[git/mingw/j6t.git] / advice.c
blob3bc86260b8a2a809a379c91627f919ef0a529aa1
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;
17 static struct {
18 const char *name;
19 int *preference;
20 } advice_config[] = {
21 { "pushupdaterejected", &advice_push_update_rejected },
22 { "pushnonffcurrent", &advice_push_non_ff_current },
23 { "pushnonffdefault", &advice_push_non_ff_default },
24 { "pushnonffmatching", &advice_push_non_ff_matching },
25 { "pushalreadyexists", &advice_push_already_exists },
26 { "pushfetchfirst", &advice_push_fetch_first },
27 { "pushneedsforce", &advice_push_needs_force },
28 { "statushints", &advice_status_hints },
29 { "statusuoption", &advice_status_u_option },
30 { "commitbeforemerge", &advice_commit_before_merge },
31 { "resolveconflict", &advice_resolve_conflict },
32 { "implicitidentity", &advice_implicit_identity },
33 { "detachedhead", &advice_detached_head },
35 /* make this an alias for backward compatibility */
36 { "pushnonfastforward", &advice_push_update_rejected }
39 void advise(const char *advice, ...)
41 struct strbuf buf = STRBUF_INIT;
42 va_list params;
43 const char *cp, *np;
45 va_start(params, advice);
46 strbuf_vaddf(&buf, advice, params);
47 va_end(params);
49 for (cp = buf.buf; *cp; cp = np) {
50 np = strchrnul(cp, '\n');
51 fprintf(stderr, _("hint: %.*s\n"), (int)(np - cp), cp);
52 if (*np)
53 np++;
55 strbuf_release(&buf);
58 int git_default_advice_config(const char *var, const char *value)
60 const char *k = skip_prefix(var, "advice.");
61 int i;
63 for (i = 0; i < ARRAY_SIZE(advice_config); i++) {
64 if (strcmp(k, advice_config[i].name))
65 continue;
66 *advice_config[i].preference = git_config_bool(var, value);
67 return 0;
70 return 0;
73 int error_resolve_conflict(const char *me)
75 error("'%s' is not possible because you have unmerged files.", me);
76 if (advice_resolve_conflict)
78 * Message used both when 'git commit' fails and when
79 * other commands doing a merge do.
81 advise(_("Fix them up in the work tree,\n"
82 "and then use 'git add/rm <file>' as\n"
83 "appropriate to mark resolution and make a commit,\n"
84 "or use 'git commit -a'."));
85 return -1;
88 void NORETURN die_resolve_conflict(const char *me)
90 error_resolve_conflict(me);
91 die("Exiting because of an unresolved conflict.");
94 void detach_advice(const char *new_name)
96 const char fmt[] =
97 "Note: checking out '%s'.\n\n"
98 "You are in 'detached HEAD' state. You can look around, make experimental\n"
99 "changes and commit them, and you can discard any commits you make in this\n"
100 "state without impacting any branches by performing another checkout.\n\n"
101 "If you want to create a new branch to retain commits you create, you may\n"
102 "do so (now or later) by using -b with the checkout command again. Example:\n\n"
103 " git checkout -b new_branch_name\n\n";
105 fprintf(stderr, fmt, new_name);