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_reset_quiet_warning
= 1;
16 int advice_resolve_conflict
= 1;
17 int advice_implicit_identity
= 1;
18 int advice_detached_head
= 1;
19 int advice_set_upstream_failure
= 1;
20 int advice_object_name_warning
= 1;
21 int advice_amworkdir
= 1;
22 int advice_rm_hints
= 1;
23 int advice_add_embedded_repo
= 1;
24 int advice_ignored_hook
= 1;
25 int advice_waiting_for_editor
= 1;
26 int advice_graft_file_deprecated
= 1;
27 int advice_checkout_ambiguous_remote_branch_name
= 1;
29 static int advice_use_color
= -1;
30 static char advice_colors
[][COLOR_MAXLEN
] = {
32 GIT_COLOR_YELLOW
, /* HINT */
36 ADVICE_COLOR_RESET
= 0,
37 ADVICE_COLOR_HINT
= 1,
40 static int parse_advise_color_slot(const char *slot
)
42 if (!strcasecmp(slot
, "reset"))
43 return ADVICE_COLOR_RESET
;
44 if (!strcasecmp(slot
, "hint"))
45 return ADVICE_COLOR_HINT
;
49 static const char *advise_get_color(enum color_advice ix
)
51 if (want_color_stderr(advice_use_color
))
52 return advice_colors
[ix
];
60 { "pushUpdateRejected", &advice_push_update_rejected
},
61 { "pushNonFFCurrent", &advice_push_non_ff_current
},
62 { "pushNonFFMatching", &advice_push_non_ff_matching
},
63 { "pushAlreadyExists", &advice_push_already_exists
},
64 { "pushFetchFirst", &advice_push_fetch_first
},
65 { "pushNeedsForce", &advice_push_needs_force
},
66 { "statusHints", &advice_status_hints
},
67 { "statusUoption", &advice_status_u_option
},
68 { "commitBeforeMerge", &advice_commit_before_merge
},
69 { "resetQuiet", &advice_reset_quiet_warning
},
70 { "resolveConflict", &advice_resolve_conflict
},
71 { "implicitIdentity", &advice_implicit_identity
},
72 { "detachedHead", &advice_detached_head
},
73 { "setupStreamFailure", &advice_set_upstream_failure
},
74 { "objectNameWarning", &advice_object_name_warning
},
75 { "amWorkDir", &advice_amworkdir
},
76 { "rmHints", &advice_rm_hints
},
77 { "addEmbeddedRepo", &advice_add_embedded_repo
},
78 { "ignoredHook", &advice_ignored_hook
},
79 { "waitingForEditor", &advice_waiting_for_editor
},
80 { "graftFileDeprecated", &advice_graft_file_deprecated
},
81 { "checkoutAmbiguousRemoteBranchName", &advice_checkout_ambiguous_remote_branch_name
},
83 /* make this an alias for backward compatibility */
84 { "pushNonFastForward", &advice_push_update_rejected
}
87 void advise(const char *advice
, ...)
89 struct strbuf buf
= STRBUF_INIT
;
93 va_start(params
, advice
);
94 strbuf_vaddf(&buf
, advice
, params
);
97 for (cp
= buf
.buf
; *cp
; cp
= np
) {
98 np
= strchrnul(cp
, '\n');
99 fprintf(stderr
, _("%shint: %.*s%s\n"),
100 advise_get_color(ADVICE_COLOR_HINT
),
102 advise_get_color(ADVICE_COLOR_RESET
));
106 strbuf_release(&buf
);
109 int git_default_advice_config(const char *var
, const char *value
)
111 const char *k
, *slot_name
;
114 if (!strcmp(var
, "color.advice")) {
115 advice_use_color
= git_config_colorbool(var
, value
);
119 if (skip_prefix(var
, "color.advice.", &slot_name
)) {
120 int slot
= parse_advise_color_slot(slot_name
);
124 return config_error_nonbool(var
);
125 return color_parse(value
, advice_colors
[slot
]);
128 if (!skip_prefix(var
, "advice.", &k
))
131 for (i
= 0; i
< ARRAY_SIZE(advice_config
); i
++) {
132 if (strcasecmp(k
, advice_config
[i
].name
))
134 *advice_config
[i
].preference
= git_config_bool(var
, value
);
141 void list_config_advices(struct string_list
*list
, const char *prefix
)
145 for (i
= 0; i
< ARRAY_SIZE(advice_config
); i
++)
146 list_config_item(list
, prefix
, advice_config
[i
].name
);
149 int error_resolve_conflict(const char *me
)
151 if (!strcmp(me
, "cherry-pick"))
152 error(_("Cherry-picking is not possible because you have unmerged files."));
153 else if (!strcmp(me
, "commit"))
154 error(_("Committing is not possible because you have unmerged files."));
155 else if (!strcmp(me
, "merge"))
156 error(_("Merging is not possible because you have unmerged files."));
157 else if (!strcmp(me
, "pull"))
158 error(_("Pulling is not possible because you have unmerged files."));
159 else if (!strcmp(me
, "revert"))
160 error(_("Reverting is not possible because you have unmerged files."));
162 error(_("It is not possible to %s because you have unmerged files."),
165 if (advice_resolve_conflict
)
167 * Message used both when 'git commit' fails and when
168 * other commands doing a merge do.
170 advise(_("Fix them up in the work tree, and then use 'git add/rm <file>'\n"
171 "as appropriate to mark resolution and make a commit."));
175 void NORETURN
die_resolve_conflict(const char *me
)
177 error_resolve_conflict(me
);
178 die(_("Exiting because of an unresolved conflict."));
181 void NORETURN
die_conclude_merge(void)
183 error(_("You have not concluded your merge (MERGE_HEAD exists)."));
184 if (advice_resolve_conflict
)
185 advise(_("Please, commit your changes before merging."));
186 die(_("Exiting because of unfinished merge."));
189 void detach_advice(const char *new_name
)
192 _("Note: checking out '%s'.\n\n"
193 "You are in 'detached HEAD' state. You can look around, make experimental\n"
194 "changes and commit them, and you can discard any commits you make in this\n"
195 "state without impacting any branches by performing another checkout.\n\n"
196 "If you want to create a new branch to retain commits you create, you may\n"
197 "do so (now or later) by using -b with the checkout command again. Example:\n\n"
198 " git checkout -b <new-branch-name>\n\n");
200 fprintf(stderr
, fmt
, new_name
);