blob: e02e632df380a8e9772d9cd9b1282204c56a7d4e [file] [log] [blame]
Jeff King75194432009-09-09 07:38:58 -04001#include "cache.h"
2
3int advice_push_nonfastforward = 1;
Jeff Kingedf563f2009-09-09 07:43:03 -04004int advice_status_hints = 1;
Matthieu Moy4c371f92009-11-22 23:26:17 +01005int advice_commit_before_merge = 1;
Matthieu Moyd38a30d2010-01-12 10:54:44 +01006int advice_resolve_conflict = 1;
Jeff Kingb706fcf2010-01-13 15:17:08 -05007int advice_implicit_identity = 1;
Junio C Hamano13be3e32010-01-29 22:03:24 -08008int advice_detached_head = 1;
Jeff King75194432009-09-09 07:38:58 -04009
10static struct {
11 const char *name;
12 int *preference;
13} advice_config[] = {
14 { "pushnonfastforward", &advice_push_nonfastforward },
Jeff Kingedf563f2009-09-09 07:43:03 -040015 { "statushints", &advice_status_hints },
Matthieu Moy4c371f92009-11-22 23:26:17 +010016 { "commitbeforemerge", &advice_commit_before_merge },
Matthieu Moyd38a30d2010-01-12 10:54:44 +010017 { "resolveconflict", &advice_resolve_conflict },
Jeff Kingb706fcf2010-01-13 15:17:08 -050018 { "implicitidentity", &advice_implicit_identity },
Junio C Hamano13be3e32010-01-29 22:03:24 -080019 { "detachedhead", &advice_detached_head },
Jeff King75194432009-09-09 07:38:58 -040020};
21
Ramkumar Ramachandra38ef61c2011-08-04 16:08:59 +053022void advise(const char *advice, ...)
23{
24 va_list params;
25
26 va_start(params, advice);
27 vreportf("hint: ", advice, params);
28 va_end(params);
29}
30
Jeff King75194432009-09-09 07:38:58 -040031int git_default_advice_config(const char *var, const char *value)
32{
33 const char *k = skip_prefix(var, "advice.");
34 int i;
35
36 for (i = 0; i < ARRAY_SIZE(advice_config); i++) {
37 if (strcmp(k, advice_config[i].name))
38 continue;
39 *advice_config[i].preference = git_config_bool(var, value);
40 return 0;
41 }
42
43 return 0;
44}
Matthieu Moyd38a30d2010-01-12 10:54:44 +010045
Ramkumar Ramachandra38ef61c2011-08-04 16:08:59 +053046int error_resolve_conflict(const char *me)
Matthieu Moyd38a30d2010-01-12 10:54:44 +010047{
Ramkumar Ramachandra38ef61c2011-08-04 16:08:59 +053048 error("'%s' is not possible because you have unmerged files.", me);
49 if (advice_resolve_conflict) {
Matthieu Moyd38a30d2010-01-12 10:54:44 +010050 /*
51 * Message used both when 'git commit' fails and when
52 * other commands doing a merge do.
53 */
Ramkumar Ramachandra38ef61c2011-08-04 16:08:59 +053054 advise("Fix them up in the work tree,");
55 advise("and then use 'git add/rm <file>' as");
56 advise("appropriate to mark resolution and make a commit,");
57 advise("or use 'git commit -a'.");
58 }
59 return -1;
60}
61
62void NORETURN die_resolve_conflict(const char *me)
63{
64 error_resolve_conflict(me);
65 die("Exiting because of an unresolved conflict.");
Matthieu Moyd38a30d2010-01-12 10:54:44 +010066}