Jeff King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 1 | #include "cache.h" |
| 2 | |
| 3 | int advice_push_nonfastforward = 1; |
Jeff King | edf563f | 2009-09-09 07:43:03 -0400 | [diff] [blame] | 4 | int advice_status_hints = 1; |
Matthieu Moy | 4c371f9 | 2009-11-22 23:26:17 +0100 | [diff] [blame] | 5 | int advice_commit_before_merge = 1; |
Matthieu Moy | d38a30d | 2010-01-12 10:54:44 +0100 | [diff] [blame] | 6 | int advice_resolve_conflict = 1; |
Jeff King | b706fcf | 2010-01-13 15:17:08 -0500 | [diff] [blame] | 7 | int advice_implicit_identity = 1; |
Junio C Hamano | 13be3e3 | 2010-01-29 22:03:24 -0800 | [diff] [blame] | 8 | int advice_detached_head = 1; |
Jeff King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 9 | |
| 10 | static struct { |
| 11 | const char *name; |
| 12 | int *preference; |
| 13 | } advice_config[] = { |
| 14 | { "pushnonfastforward", &advice_push_nonfastforward }, |
Jeff King | edf563f | 2009-09-09 07:43:03 -0400 | [diff] [blame] | 15 | { "statushints", &advice_status_hints }, |
Matthieu Moy | 4c371f9 | 2009-11-22 23:26:17 +0100 | [diff] [blame] | 16 | { "commitbeforemerge", &advice_commit_before_merge }, |
Matthieu Moy | d38a30d | 2010-01-12 10:54:44 +0100 | [diff] [blame] | 17 | { "resolveconflict", &advice_resolve_conflict }, |
Jeff King | b706fcf | 2010-01-13 15:17:08 -0500 | [diff] [blame] | 18 | { "implicitidentity", &advice_implicit_identity }, |
Junio C Hamano | 13be3e3 | 2010-01-29 22:03:24 -0800 | [diff] [blame] | 19 | { "detachedhead", &advice_detached_head }, |
Jeff King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 20 | }; |
| 21 | |
Ramkumar Ramachandra | 38ef61c | 2011-08-04 16:08:59 +0530 | [diff] [blame] | 22 | void 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 King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 31 | int 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 Moy | d38a30d | 2010-01-12 10:54:44 +0100 | [diff] [blame] | 45 | |
Ramkumar Ramachandra | 38ef61c | 2011-08-04 16:08:59 +0530 | [diff] [blame] | 46 | int error_resolve_conflict(const char *me) |
Matthieu Moy | d38a30d | 2010-01-12 10:54:44 +0100 | [diff] [blame] | 47 | { |
Ramkumar Ramachandra | 38ef61c | 2011-08-04 16:08:59 +0530 | [diff] [blame] | 48 | error("'%s' is not possible because you have unmerged files.", me); |
| 49 | if (advice_resolve_conflict) { |
Matthieu Moy | d38a30d | 2010-01-12 10:54:44 +0100 | [diff] [blame] | 50 | /* |
| 51 | * Message used both when 'git commit' fails and when |
| 52 | * other commands doing a merge do. |
| 53 | */ |
Ramkumar Ramachandra | 38ef61c | 2011-08-04 16:08:59 +0530 | [diff] [blame] | 54 | 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 | |
| 62 | void NORETURN die_resolve_conflict(const char *me) |
| 63 | { |
| 64 | error_resolve_conflict(me); |
| 65 | die("Exiting because of an unresolved conflict."); |
Matthieu Moy | d38a30d | 2010-01-12 10:54:44 +0100 | [diff] [blame] | 66 | } |