i18n: make the translation of -u advice in one go
[git/git-svn.git] / advice.c
blob015011fe0dff7b01c42e13d3e53ceb1178cecfc9
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_status_u_option = 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 { "pushnonfastforward", &advice_push_nonfastforward },
19 { "pushnonffcurrent", &advice_push_non_ff_current },
20 { "pushnonffdefault", &advice_push_non_ff_default },
21 { "pushnonffmatching", &advice_push_non_ff_matching },
22 { "statushints", &advice_status_hints },
23 { "statusuoption", &advice_status_u_option },
24 { "commitbeforemerge", &advice_commit_before_merge },
25 { "resolveconflict", &advice_resolve_conflict },
26 { "implicitidentity", &advice_implicit_identity },
27 { "detachedhead", &advice_detached_head },
30 void advise(const char *advice, ...)
32 struct strbuf buf = STRBUF_INIT;
33 va_list params;
34 const char *cp, *np;
36 va_start(params, advice);
37 strbuf_vaddf(&buf, advice, params);
38 va_end(params);
40 for (cp = buf.buf; *cp; cp = np) {
41 np = strchrnul(cp, '\n');
42 fprintf(stderr, _("hint: %.*s\n"), (int)(np - cp), cp);
43 if (*np)
44 np++;
46 strbuf_release(&buf);
49 int git_default_advice_config(const char *var, const char *value)
51 const char *k = skip_prefix(var, "advice.");
52 int i;
54 for (i = 0; i < ARRAY_SIZE(advice_config); i++) {
55 if (strcmp(k, advice_config[i].name))
56 continue;
57 *advice_config[i].preference = git_config_bool(var, value);
58 return 0;
61 return 0;
64 int error_resolve_conflict(const char *me)
66 error("'%s' is not possible because you have unmerged files.", me);
67 if (advice_resolve_conflict)
69 * Message used both when 'git commit' fails and when
70 * other commands doing a merge do.
72 advise(_("Fix them up in the work tree,\n"
73 "and then use 'git add/rm <file>' as\n"
74 "appropriate to mark resolution and make a commit,\n"
75 "or use 'git commit -a'."));
76 return -1;
79 void NORETURN die_resolve_conflict(const char *me)
81 error_resolve_conflict(me);
82 die("Exiting because of an unresolved conflict.");
85 void detach_advice(const char *new_name)
87 const char fmt[] =
88 "Note: checking out '%s'.\n\n"
89 "You are in 'detached HEAD' state. You can look around, make experimental\n"
90 "changes and commit them, and you can discard any commits you make in this\n"
91 "state without impacting any branches by performing another checkout.\n\n"
92 "If you want to create a new branch to retain commits you create, you may\n"
93 "do so (now or later) by using -b with the checkout command again. Example:\n\n"
94 " git checkout -b new_branch_name\n\n";
96 fprintf(stderr, fmt, new_name);