]> git.ipfire.org Git - thirdparty/git.git/blame_incremental - advice.c
l10n: Update Swedish translation (2135t0f0u)
[thirdparty/git.git] / advice.c
... / ...
CommitLineData
1#include "cache.h"
2
3int advice_push_update_rejected = 1;
4int advice_push_non_ff_current = 1;
5int advice_push_non_ff_default = 1;
6int advice_push_non_ff_matching = 1;
7int advice_push_already_exists = 1;
8int advice_push_fetch_first = 1;
9int advice_push_needs_force = 1;
10int advice_status_hints = 1;
11int advice_status_u_option = 1;
12int advice_commit_before_merge = 1;
13int advice_resolve_conflict = 1;
14int advice_implicit_identity = 1;
15int advice_detached_head = 1;
16int advice_set_upstream_failure = 1;
17int advice_object_name_warning = 1;
18int advice_rm_hints = 1;
19
20static struct {
21 const char *name;
22 int *preference;
23} advice_config[] = {
24 { "pushupdaterejected", &advice_push_update_rejected },
25 { "pushnonffcurrent", &advice_push_non_ff_current },
26 { "pushnonffdefault", &advice_push_non_ff_default },
27 { "pushnonffmatching", &advice_push_non_ff_matching },
28 { "pushalreadyexists", &advice_push_already_exists },
29 { "pushfetchfirst", &advice_push_fetch_first },
30 { "pushneedsforce", &advice_push_needs_force },
31 { "statushints", &advice_status_hints },
32 { "statusuoption", &advice_status_u_option },
33 { "commitbeforemerge", &advice_commit_before_merge },
34 { "resolveconflict", &advice_resolve_conflict },
35 { "implicitidentity", &advice_implicit_identity },
36 { "detachedhead", &advice_detached_head },
37 { "setupstreamfailure", &advice_set_upstream_failure },
38 { "objectnamewarning", &advice_object_name_warning },
39 { "rmhints", &advice_rm_hints },
40
41 /* make this an alias for backward compatibility */
42 { "pushnonfastforward", &advice_push_update_rejected }
43};
44
45void advise(const char *advice, ...)
46{
47 struct strbuf buf = STRBUF_INIT;
48 va_list params;
49 const char *cp, *np;
50
51 va_start(params, advice);
52 strbuf_vaddf(&buf, advice, params);
53 va_end(params);
54
55 for (cp = buf.buf; *cp; cp = np) {
56 np = strchrnul(cp, '\n');
57 fprintf(stderr, _("hint: %.*s\n"), (int)(np - cp), cp);
58 if (*np)
59 np++;
60 }
61 strbuf_release(&buf);
62}
63
64int git_default_advice_config(const char *var, const char *value)
65{
66 const char *k = skip_prefix(var, "advice.");
67 int i;
68
69 for (i = 0; i < ARRAY_SIZE(advice_config); i++) {
70 if (strcmp(k, advice_config[i].name))
71 continue;
72 *advice_config[i].preference = git_config_bool(var, value);
73 return 0;
74 }
75
76 return 0;
77}
78
79int error_resolve_conflict(const char *me)
80{
81 error("'%s' is not possible because you have unmerged files.", me);
82 if (advice_resolve_conflict)
83 /*
84 * Message used both when 'git commit' fails and when
85 * other commands doing a merge do.
86 */
87 advise(_("Fix them up in the work tree,\n"
88 "and then use 'git add/rm <file>' as\n"
89 "appropriate to mark resolution and make a commit,\n"
90 "or use 'git commit -a'."));
91 return -1;
92}
93
94void NORETURN die_resolve_conflict(const char *me)
95{
96 error_resolve_conflict(me);
97 die("Exiting because of an unresolved conflict.");
98}
99
100void detach_advice(const char *new_name)
101{
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";
110
111 fprintf(stderr, fmt, new_name);
112}