git p4 test: start p4d inside its db dir
[git/gitweb.git] / advice.c
blobd2879272802cb3477dd6b47a78098ffdc26dcb37
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_status_hints = 1;
9 int advice_commit_before_merge = 1;
10 int advice_resolve_conflict = 1;
11 int advice_implicit_identity = 1;
12 int advice_detached_head = 1;
14 static struct {
15 const char *name;
16 int *preference;
17 } advice_config[] = {
18 { "pushupdaterejected", &advice_push_update_rejected },
19 { "pushnonffcurrent", &advice_push_non_ff_current },
20 { "pushnonffdefault", &advice_push_non_ff_default },
21 { "pushnonffmatching", &advice_push_non_ff_matching },
22 { "pushalreadyexists", &advice_push_already_exists },
23 { "statushints", &advice_status_hints },
24 { "commitbeforemerge", &advice_commit_before_merge },
25 { "resolveconflict", &advice_resolve_conflict },
26 { "implicitidentity", &advice_implicit_identity },
27 { "detachedhead", &advice_detached_head },
29 /* make this an alias for backward compatibility */
30 { "pushnonfastforward", &advice_push_update_rejected }
33 void advise(const char *advice, ...)
35 struct strbuf buf = STRBUF_INIT;
36 va_list params;
37 const char *cp, *np;
39 va_start(params, advice);
40 strbuf_vaddf(&buf, advice, params);
41 va_end(params);
43 for (cp = buf.buf; *cp; cp = np) {
44 np = strchrnul(cp, '\n');
45 fprintf(stderr, _("hint: %.*s\n"), (int)(np - cp), cp);
46 if (*np)
47 np++;
49 strbuf_release(&buf);
52 int git_default_advice_config(const char *var, const char *value)
54 const char *k = skip_prefix(var, "advice.");
55 int i;
57 for (i = 0; i < ARRAY_SIZE(advice_config); i++) {
58 if (strcmp(k, advice_config[i].name))
59 continue;
60 *advice_config[i].preference = git_config_bool(var, value);
61 return 0;
64 return 0;
67 int error_resolve_conflict(const char *me)
69 error("'%s' is not possible because you have unmerged files.", me);
70 if (advice_resolve_conflict)
72 * Message used both when 'git commit' fails and when
73 * other commands doing a merge do.
75 advise(_("Fix them up in the work tree,\n"
76 "and then use 'git add/rm <file>' as\n"
77 "appropriate to mark resolution and make a commit,\n"
78 "or use 'git commit -a'."));
79 return -1;
82 void NORETURN die_resolve_conflict(const char *me)
84 error_resolve_conflict(me);
85 die("Exiting because of an unresolved conflict.");
88 void detach_advice(const char *new_name)
90 const char fmt[] =
91 "Note: checking out '%s'.\n\n"
92 "You are in 'detached HEAD' state. You can look around, make experimental\n"
93 "changes and commit them, and you can discard any commits you make in this\n"
94 "state without impacting any branches by performing another checkout.\n\n"
95 "If you want to create a new branch to retain commits you create, you may\n"
96 "do so (now or later) by using -b with the checkout command again. Example:\n\n"
97 " git checkout -b new_branch_name\n\n";
99 fprintf(stderr, fmt, new_name);