6 int advice_push_update_rejected = 1;
7 int advice_push_non_ff_current = 1;
8 int advice_push_non_ff_matching = 1;
9 int advice_push_already_exists = 1;
10 int advice_push_fetch_first = 1;
11 int advice_push_needs_force = 1;
12 int advice_status_hints = 1;
13 int advice_status_u_option = 1;
14 int advice_commit_before_merge = 1;
15 int advice_resolve_conflict = 1;
16 int advice_implicit_identity = 1;
17 int advice_detached_head = 1;
18 int advice_set_upstream_failure = 1;
19 int advice_object_name_warning = 1;
20 int advice_rm_hints = 1;
21 int advice_add_embedded_repo = 1;
22 int advice_ignored_hook = 1;
23 int advice_waiting_for_editor = 1;
24 int advice_graft_file_deprecated = 1;
26 static int advice_use_color = -1;
27 static char advice_colors[][COLOR_MAXLEN] = {
29 GIT_COLOR_YELLOW, /* HINT */
33 ADVICE_COLOR_RESET = 0,
34 ADVICE_COLOR_HINT = 1,
37 static int parse_advise_color_slot(const char *slot)
39 if (!strcasecmp(slot, "reset"))
40 return ADVICE_COLOR_RESET;
41 if (!strcasecmp(slot, "hint"))
42 return ADVICE_COLOR_HINT;
46 static const char *advise_get_color(enum color_advice ix)
48 if (want_color_stderr(advice_use_color))
49 return advice_colors[ix];
57 { "pushUpdateRejected", &advice_push_update_rejected },
58 { "pushNonFFCurrent", &advice_push_non_ff_current },
59 { "pushNonFFMatching", &advice_push_non_ff_matching },
60 { "pushAlreadyExists", &advice_push_already_exists },
61 { "pushFetchFirst", &advice_push_fetch_first },
62 { "pushNeedsForce", &advice_push_needs_force },
63 { "statusHints", &advice_status_hints },
64 { "statusUoption", &advice_status_u_option },
65 { "commitBeforeMerge", &advice_commit_before_merge },
66 { "resolveConflict", &advice_resolve_conflict },
67 { "implicitIdentity", &advice_implicit_identity },
68 { "detachedHead", &advice_detached_head },
69 { "setupStreamFailure", &advice_set_upstream_failure },
70 { "objectNameWarning", &advice_object_name_warning },
71 { "rmHints", &advice_rm_hints },
72 { "addEmbeddedRepo", &advice_add_embedded_repo },
73 { "ignoredHook", &advice_ignored_hook },
74 { "waitingForEditor", &advice_waiting_for_editor },
75 { "graftFileDeprecated", &advice_graft_file_deprecated },
77 /* make this an alias for backward compatibility */
78 { "pushNonFastForward", &advice_push_update_rejected }
81 void advise(const char *advice, ...)
83 struct strbuf buf = STRBUF_INIT;
87 va_start(params, advice);
88 strbuf_vaddf(&buf, advice, params);
91 for (cp = buf.buf; *cp; cp = np) {
92 np = strchrnul(cp, '\n');
93 fprintf(stderr, _("%shint: %.*s%s\n"),
94 advise_get_color(ADVICE_COLOR_HINT),
96 advise_get_color(ADVICE_COLOR_RESET));
100 strbuf_release(&buf);
103 int git_default_advice_config(const char *var, const char *value)
105 const char *k, *slot_name;
108 if (!strcmp(var, "color.advice")) {
109 advice_use_color = git_config_colorbool(var, value);
113 if (skip_prefix(var, "color.advice.", &slot_name)) {
114 int slot = parse_advise_color_slot(slot_name);
118 return config_error_nonbool(var);
119 return color_parse(value, advice_colors[slot]);
122 if (!skip_prefix(var, "advice.", &k))
125 for (i = 0; i < ARRAY_SIZE(advice_config); i++) {
126 if (strcasecmp(k, advice_config[i].name))
128 *advice_config[i].preference = git_config_bool(var, value);
135 void list_config_advices(struct string_list *list, const char *prefix)
139 for (i = 0; i < ARRAY_SIZE(advice_config); i++)
140 list_config_item(list, prefix, advice_config[i].name);
143 int error_resolve_conflict(const char *me)
145 if (!strcmp(me, "cherry-pick"))
146 error(_("Cherry-picking is not possible because you have unmerged files."));
147 else if (!strcmp(me, "commit"))
148 error(_("Committing is not possible because you have unmerged files."));
149 else if (!strcmp(me, "merge"))
150 error(_("Merging is not possible because you have unmerged files."));
151 else if (!strcmp(me, "pull"))
152 error(_("Pulling is not possible because you have unmerged files."));
153 else if (!strcmp(me, "revert"))
154 error(_("Reverting is not possible because you have unmerged files."));
156 error(_("It is not possible to %s because you have unmerged files."),
159 if (advice_resolve_conflict)
161 * Message used both when 'git commit' fails and when
162 * other commands doing a merge do.
164 advise(_("Fix them up in the work tree, and then use 'git add/rm <file>'\n"
165 "as appropriate to mark resolution and make a commit."));
169 void NORETURN die_resolve_conflict(const char *me)
171 error_resolve_conflict(me);
172 die(_("Exiting because of an unresolved conflict."));
175 void NORETURN die_conclude_merge(void)
177 error(_("You have not concluded your merge (MERGE_HEAD exists)."));
178 if (advice_resolve_conflict)
179 advise(_("Please, commit your changes before merging."));
180 die(_("Exiting because of unfinished merge."));
183 void detach_advice(const char *new_name)
186 _("Note: checking out '%s'.\n\n"
187 "You are in 'detached HEAD' state. You can look around, make experimental\n"
188 "changes and commit them, and you can discard any commits you make in this\n"
189 "state without impacting any branches by performing another checkout.\n\n"
190 "If you want to create a new branch to retain commits you create, you may\n"
191 "do so (now or later) by using -b with the checkout command again. Example:\n\n"
192 " git checkout -b <new-branch-name>\n\n");
194 fprintf(stderr, fmt, new_name);