Merge branch 'maint'
[git/mingw/j6t.git] / advice.c
blob9b420331926c6bf1aa371f973d6a96886f419b06
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_matching = 1;
6 int advice_push_already_exists = 1;
7 int advice_push_fetch_first = 1;
8 int advice_push_needs_force = 1;
9 int advice_status_hints = 1;
10 int advice_status_u_option = 1;
11 int advice_commit_before_merge = 1;
12 int advice_resolve_conflict = 1;
13 int advice_implicit_identity = 1;
14 int advice_detached_head = 1;
15 int advice_set_upstream_failure = 1;
16 int advice_object_name_warning = 1;
17 int advice_rm_hints = 1;
19 static struct {
20 const char *name;
21 int *preference;
22 } advice_config[] = {
23 { "pushupdaterejected", &advice_push_update_rejected },
24 { "pushnonffcurrent", &advice_push_non_ff_current },
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 },
36 { "objectnamewarning", &advice_object_name_warning },
37 { "rmhints", &advice_rm_hints },
39 /* make this an alias for backward compatibility */
40 { "pushnonfastforward", &advice_push_update_rejected }
43 void advise(const char *advice, ...)
45 struct strbuf buf = STRBUF_INIT;
46 va_list params;
47 const char *cp, *np;
49 va_start(params, advice);
50 strbuf_vaddf(&buf, advice, params);
51 va_end(params);
53 for (cp = buf.buf; *cp; cp = np) {
54 np = strchrnul(cp, '\n');
55 fprintf(stderr, _("hint: %.*s\n"), (int)(np - cp), cp);
56 if (*np)
57 np++;
59 strbuf_release(&buf);
62 int git_default_advice_config(const char *var, const char *value)
64 const char *k;
65 int i;
67 if (!skip_prefix(var, "advice.", &k))
68 return 0;
70 for (i = 0; i < ARRAY_SIZE(advice_config); i++) {
71 if (strcmp(k, advice_config[i].name))
72 continue;
73 *advice_config[i].preference = git_config_bool(var, value);
74 return 0;
77 return 0;
80 int error_resolve_conflict(const char *me)
82 error("%s is not possible because you have unmerged files.", me);
83 if (advice_resolve_conflict)
85 * Message used both when 'git commit' fails and when
86 * other commands doing a merge do.
88 advise(_("Fix them up in the work tree, and then use 'git add/rm <file>'\n"
89 "as appropriate to mark resolution and make a commit, or use\n"
90 "'git commit -a'."));
91 return -1;
94 void NORETURN die_resolve_conflict(const char *me)
96 error_resolve_conflict(me);
97 die("Exiting because of an unresolved conflict.");
100 void detach_advice(const char *new_name)
102 const char fmt[] =
103 "Note: checking out '%s'.\n\n"
104 "You are in 'detached HEAD' state. You can look around, make experimental\n"
105 "changes and commit them, and you can discard any commits you make in this\n"
106 "state without impacting any branches by performing another checkout.\n\n"
107 "If you want to create a new branch to retain commits you create, you may\n"
108 "do so (now or later) by using -b with the checkout command again. Example:\n\n"
109 " git checkout -b new_branch_name\n\n";
111 fprintf(stderr, fmt, new_name);