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