]> git.ipfire.org Git - thirdparty/git.git/blame - advice.c
i18n: i18n: diff: mark die messages for translation
[thirdparty/git.git] / advice.c
CommitLineData
75194438
JK
1#include "cache.h"
2
1184564e 3int advice_push_update_rejected = 1;
f25950f3 4int advice_push_non_ff_current = 1;
f25950f3 5int advice_push_non_ff_matching = 1;
b4505682 6int advice_push_already_exists = 1;
75e5c0dc
JH
7int advice_push_fetch_first = 1;
8int advice_push_needs_force = 1;
edf563fb 9int advice_status_hints = 1;
6a38ef2c 10int advice_status_u_option = 1;
4c371f91 11int advice_commit_before_merge = 1;
d38a30df 12int advice_resolve_conflict = 1;
b706fcfe 13int advice_implicit_identity = 1;
13be3e31 14int advice_detached_head = 1;
caa2036b 15int advice_set_upstream_failure = 1;
798c35fc 16int advice_object_name_warning = 1;
7e309446 17int advice_rm_hints = 1;
75194438
JK
18
19static struct {
20 const char *name;
21 int *preference;
22} advice_config[] = {
1184564e 23 { "pushupdaterejected", &advice_push_update_rejected },
f25950f3 24 { "pushnonffcurrent", &advice_push_non_ff_current },
f25950f3 25 { "pushnonffmatching", &advice_push_non_ff_matching },
b4505682 26 { "pushalreadyexists", &advice_push_already_exists },
75e5c0dc
JH
27 { "pushfetchfirst", &advice_push_fetch_first },
28 { "pushneedsforce", &advice_push_needs_force },
edf563fb 29 { "statushints", &advice_status_hints },
6a38ef2c 30 { "statusuoption", &advice_status_u_option },
4c371f91 31 { "commitbeforemerge", &advice_commit_before_merge },
d38a30df 32 { "resolveconflict", &advice_resolve_conflict },
b706fcfe 33 { "implicitidentity", &advice_implicit_identity },
13be3e31 34 { "detachedhead", &advice_detached_head },
caa2036b 35 { "setupstreamfailure", &advice_set_upstream_failure },
8dc84fdc 36 { "objectnamewarning", &advice_object_name_warning },
7e309446 37 { "rmhints", &advice_rm_hints },
1184564e
CR
38
39 /* make this an alias for backward compatibility */
40 { "pushnonfastforward", &advice_push_update_rejected }
75194438
JK
41};
42
38ef61cf
RR
43void advise(const char *advice, ...)
44{
23cb5bf3 45 struct strbuf buf = STRBUF_INIT;
38ef61cf 46 va_list params;
23cb5bf3 47 const char *cp, *np;
38ef61cf
RR
48
49 va_start(params, advice);
447b99c8 50 strbuf_vaddf(&buf, advice, params);
38ef61cf 51 va_end(params);
23cb5bf3
JH
52
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++;
58 }
59 strbuf_release(&buf);
38ef61cf
RR
60}
61
75194438
JK
62int git_default_advice_config(const char *var, const char *value)
63{
cf4fff57 64 const char *k;
75194438
JK
65 int i;
66
cf4fff57
JK
67 if (!skip_prefix(var, "advice.", &k))
68 return 0;
69
75194438
JK
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;
75 }
76
77 return 0;
78}
d38a30df 79
38ef61cf 80int error_resolve_conflict(const char *me)
d38a30df 81{
8785c425
VA
82 if (!strcmp(me, "cherry-pick"))
83 error(_("Cherry-picking is not possible because you have unmerged files."));
84 else if (!strcmp(me, "commit"))
85 error(_("Committing is not possible because you have unmerged files."));
86 else if (!strcmp(me, "merge"))
87 error(_("Merging is not possible because you have unmerged files."));
88 else if (!strcmp(me, "pull"))
89 error(_("Pulling is not possible because you have unmerged files."));
90 else if (!strcmp(me, "revert"))
91 error(_("Reverting is not possible because you have unmerged files."));
92 else
93 error(_("It is not possible to %s because you have unmerged files."),
94 me);
95
23cb5bf3 96 if (advice_resolve_conflict)
d38a30df
MM
97 /*
98 * Message used both when 'git commit' fails and when
99 * other commands doing a merge do.
100 */
c057b242 101 advise(_("Fix them up in the work tree, and then use 'git add/rm <file>'\n"
91e70e00 102 "as appropriate to mark resolution and make a commit."));
38ef61cf
RR
103 return -1;
104}
105
106void NORETURN die_resolve_conflict(const char *me)
107{
108 error_resolve_conflict(me);
8785c425 109 die(_("Exiting because of an unresolved conflict."));
d38a30df 110}
2857093b 111
4a4cf9e8
PT
112void NORETURN die_conclude_merge(void)
113{
114 error(_("You have not concluded your merge (MERGE_HEAD exists)."));
115 if (advice_resolve_conflict)
b7447679 116 advise(_("Please, commit your changes before merging."));
4a4cf9e8
PT
117 die(_("Exiting because of unfinished merge."));
118}
119
2857093b
NTND
120void detach_advice(const char *new_name)
121{
e9f3cec4
VA
122 const char *fmt =
123 _("Note: checking out '%s'.\n\n"
2857093b
NTND
124 "You are in 'detached HEAD' state. You can look around, make experimental\n"
125 "changes and commit them, and you can discard any commits you make in this\n"
126 "state without impacting any branches by performing another checkout.\n\n"
127 "If you want to create a new branch to retain commits you create, you may\n"
128 "do so (now or later) by using -b with the checkout command again. Example:\n\n"
e9f3cec4 129 " git checkout -b <new-branch-name>\n\n");
2857093b
NTND
130
131 fprintf(stderr, fmt, new_name);
132}