Jeff King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 1 | #include "cache.h" |
| 2 | |
Chris Rorvick | 1184564 | 2012-12-02 21:27:50 -0600 | [diff] [blame] | 3 | int advice_push_update_rejected = 1; |
Christopher Tiwald | f25950f | 2012-03-20 00:31:33 -0400 | [diff] [blame] | 4 | int advice_push_non_ff_current = 1; |
| 5 | int advice_push_non_ff_default = 1; |
| 6 | int advice_push_non_ff_matching = 1; |
Chris Rorvick | b450568 | 2012-12-02 21:27:51 -0600 | [diff] [blame] | 7 | int advice_push_already_exists = 1; |
Junio C Hamano | 75e5c0d | 2013-01-23 13:55:30 -0800 | [diff] [blame] | 8 | int advice_push_fetch_first = 1; |
| 9 | int advice_push_needs_force = 1; |
Jeff King | edf563f | 2009-09-09 07:43:03 -0400 | [diff] [blame] | 10 | int advice_status_hints = 1; |
Nguyễn Thái Ngọc Duy | 6a38ef2 | 2013-03-13 19:59:16 +0700 | [diff] [blame] | 11 | int advice_status_u_option = 1; |
Matthieu Moy | 4c371f9 | 2009-11-22 23:26:17 +0100 | [diff] [blame] | 12 | int advice_commit_before_merge = 1; |
Matthieu Moy | d38a30d | 2010-01-12 10:54:44 +0100 | [diff] [blame] | 13 | int advice_resolve_conflict = 1; |
Jeff King | b706fcf | 2010-01-13 15:17:08 -0500 | [diff] [blame] | 14 | int advice_implicit_identity = 1; |
Junio C Hamano | 13be3e3 | 2010-01-29 22:03:24 -0800 | [diff] [blame] | 15 | int advice_detached_head = 1; |
Jeff King | caa2036 | 2013-04-02 15:05:12 -0400 | [diff] [blame] | 16 | int advice_set_upstream_failure = 1; |
Jeff King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 17 | |
| 18 | static struct { |
| 19 | const char *name; |
| 20 | int *preference; |
| 21 | } advice_config[] = { |
Chris Rorvick | 1184564 | 2012-12-02 21:27:50 -0600 | [diff] [blame] | 22 | { "pushupdaterejected", &advice_push_update_rejected }, |
Christopher Tiwald | f25950f | 2012-03-20 00:31:33 -0400 | [diff] [blame] | 23 | { "pushnonffcurrent", &advice_push_non_ff_current }, |
| 24 | { "pushnonffdefault", &advice_push_non_ff_default }, |
| 25 | { "pushnonffmatching", &advice_push_non_ff_matching }, |
Chris Rorvick | b450568 | 2012-12-02 21:27:51 -0600 | [diff] [blame] | 26 | { "pushalreadyexists", &advice_push_already_exists }, |
Junio C Hamano | 75e5c0d | 2013-01-23 13:55:30 -0800 | [diff] [blame] | 27 | { "pushfetchfirst", &advice_push_fetch_first }, |
| 28 | { "pushneedsforce", &advice_push_needs_force }, |
Jeff King | edf563f | 2009-09-09 07:43:03 -0400 | [diff] [blame] | 29 | { "statushints", &advice_status_hints }, |
Nguyễn Thái Ngọc Duy | 6a38ef2 | 2013-03-13 19:59:16 +0700 | [diff] [blame] | 30 | { "statusuoption", &advice_status_u_option }, |
Matthieu Moy | 4c371f9 | 2009-11-22 23:26:17 +0100 | [diff] [blame] | 31 | { "commitbeforemerge", &advice_commit_before_merge }, |
Matthieu Moy | d38a30d | 2010-01-12 10:54:44 +0100 | [diff] [blame] | 32 | { "resolveconflict", &advice_resolve_conflict }, |
Jeff King | b706fcf | 2010-01-13 15:17:08 -0500 | [diff] [blame] | 33 | { "implicitidentity", &advice_implicit_identity }, |
Junio C Hamano | 13be3e3 | 2010-01-29 22:03:24 -0800 | [diff] [blame] | 34 | { "detachedhead", &advice_detached_head }, |
Jeff King | caa2036 | 2013-04-02 15:05:12 -0400 | [diff] [blame] | 35 | { "setupstreamfailure", &advice_set_upstream_failure }, |
Chris Rorvick | 1184564 | 2012-12-02 21:27:50 -0600 | [diff] [blame] | 36 | |
| 37 | /* make this an alias for backward compatibility */ |
| 38 | { "pushnonfastforward", &advice_push_update_rejected } |
Jeff King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 39 | }; |
| 40 | |
Ramkumar Ramachandra | 38ef61c | 2011-08-04 16:08:59 +0530 | [diff] [blame] | 41 | void advise(const char *advice, ...) |
| 42 | { |
Junio C Hamano | 23cb5bf | 2011-12-22 11:21:26 -0800 | [diff] [blame] | 43 | struct strbuf buf = STRBUF_INIT; |
Ramkumar Ramachandra | 38ef61c | 2011-08-04 16:08:59 +0530 | [diff] [blame] | 44 | va_list params; |
Junio C Hamano | 23cb5bf | 2011-12-22 11:21:26 -0800 | [diff] [blame] | 45 | const char *cp, *np; |
Ramkumar Ramachandra | 38ef61c | 2011-08-04 16:08:59 +0530 | [diff] [blame] | 46 | |
| 47 | va_start(params, advice); |
Jeff King | 447b99c | 2012-07-23 14:48:57 -0400 | [diff] [blame] | 48 | strbuf_vaddf(&buf, advice, params); |
Ramkumar Ramachandra | 38ef61c | 2011-08-04 16:08:59 +0530 | [diff] [blame] | 49 | va_end(params); |
Junio C Hamano | 23cb5bf | 2011-12-22 11:21:26 -0800 | [diff] [blame] | 50 | |
| 51 | for (cp = buf.buf; *cp; cp = np) { |
| 52 | np = strchrnul(cp, '\n'); |
| 53 | fprintf(stderr, _("hint: %.*s\n"), (int)(np - cp), cp); |
| 54 | if (*np) |
| 55 | np++; |
| 56 | } |
| 57 | strbuf_release(&buf); |
Ramkumar Ramachandra | 38ef61c | 2011-08-04 16:08:59 +0530 | [diff] [blame] | 58 | } |
| 59 | |
Jeff King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 60 | int git_default_advice_config(const char *var, const char *value) |
| 61 | { |
| 62 | const char *k = skip_prefix(var, "advice."); |
| 63 | int i; |
| 64 | |
| 65 | for (i = 0; i < ARRAY_SIZE(advice_config); i++) { |
| 66 | if (strcmp(k, advice_config[i].name)) |
| 67 | continue; |
| 68 | *advice_config[i].preference = git_config_bool(var, value); |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | return 0; |
| 73 | } |
Matthieu Moy | d38a30d | 2010-01-12 10:54:44 +0100 | [diff] [blame] | 74 | |
Ramkumar Ramachandra | 38ef61c | 2011-08-04 16:08:59 +0530 | [diff] [blame] | 75 | int error_resolve_conflict(const char *me) |
Matthieu Moy | d38a30d | 2010-01-12 10:54:44 +0100 | [diff] [blame] | 76 | { |
Ramkumar Ramachandra | 38ef61c | 2011-08-04 16:08:59 +0530 | [diff] [blame] | 77 | error("'%s' is not possible because you have unmerged files.", me); |
Junio C Hamano | 23cb5bf | 2011-12-22 11:21:26 -0800 | [diff] [blame] | 78 | if (advice_resolve_conflict) |
Matthieu Moy | d38a30d | 2010-01-12 10:54:44 +0100 | [diff] [blame] | 79 | /* |
| 80 | * Message used both when 'git commit' fails and when |
| 81 | * other commands doing a merge do. |
| 82 | */ |
Junio C Hamano | 23cb5bf | 2011-12-22 11:21:26 -0800 | [diff] [blame] | 83 | advise(_("Fix them up in the work tree,\n" |
| 84 | "and then use 'git add/rm <file>' as\n" |
| 85 | "appropriate to mark resolution and make a commit,\n" |
| 86 | "or use 'git commit -a'.")); |
Ramkumar Ramachandra | 38ef61c | 2011-08-04 16:08:59 +0530 | [diff] [blame] | 87 | return -1; |
| 88 | } |
| 89 | |
| 90 | void NORETURN die_resolve_conflict(const char *me) |
| 91 | { |
| 92 | error_resolve_conflict(me); |
| 93 | die("Exiting because of an unresolved conflict."); |
Matthieu Moy | d38a30d | 2010-01-12 10:54:44 +0100 | [diff] [blame] | 94 | } |
Nguyễn Thái Ngọc Duy | 2857093 | 2012-01-16 16:46:16 +0700 | [diff] [blame] | 95 | |
| 96 | void detach_advice(const char *new_name) |
| 97 | { |
| 98 | const char fmt[] = |
| 99 | "Note: checking out '%s'.\n\n" |
| 100 | "You are in 'detached HEAD' state. You can look around, make experimental\n" |
| 101 | "changes and commit them, and you can discard any commits you make in this\n" |
| 102 | "state without impacting any branches by performing another checkout.\n\n" |
| 103 | "If you want to create a new branch to retain commits you create, you may\n" |
| 104 | "do so (now or later) by using -b with the checkout command again. Example:\n\n" |
| 105 | " git checkout -b new_branch_name\n\n"; |
| 106 | |
| 107 | fprintf(stderr, fmt, new_name); |
| 108 | } |