Jeff King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 1 | #include "cache.h" |
Brandon Williams | b2141fc | 2017-06-14 11:07:36 -0700 | [diff] [blame] | 2 | #include "config.h" |
Ryan Dammrose | 960786e | 2018-04-21 12:10:00 +0200 | [diff] [blame] | 3 | #include "color.h" |
Nguyễn Thái Ngọc Duy | 3ac68a9 | 2018-05-26 15:55:24 +0200 | [diff] [blame] | 4 | #include "help.h" |
Matheus Tavares | a20f704 | 2021-04-08 17:41:27 -0300 | [diff] [blame] | 5 | #include "string-list.h" |
Jeff King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 6 | |
Derrick Stolee | 377444b | 2019-06-18 13:25:27 -0700 | [diff] [blame] | 7 | int advice_fetch_show_forced_updates = 1; |
Chris Rorvick | 1184564 | 2012-12-02 21:27:50 -0600 | [diff] [blame] | 8 | int advice_push_update_rejected = 1; |
Christopher Tiwald | f25950f | 2012-03-20 00:31:33 -0400 | [diff] [blame] | 9 | int advice_push_non_ff_current = 1; |
Christopher Tiwald | f25950f | 2012-03-20 00:31:33 -0400 | [diff] [blame] | 10 | int advice_push_non_ff_matching = 1; |
Chris Rorvick | b450568 | 2012-12-02 21:27:51 -0600 | [diff] [blame] | 11 | int advice_push_already_exists = 1; |
Junio C Hamano | 75e5c0d | 2013-01-23 13:55:30 -0800 | [diff] [blame] | 12 | int advice_push_fetch_first = 1; |
| 13 | int advice_push_needs_force = 1; |
Ævar Arnfjörð Bjarmason | dd8dd30 | 2018-11-13 19:52:43 +0000 | [diff] [blame] | 14 | int advice_push_unqualified_ref_name = 1; |
Srinidhi Kaushik | 3b990aa | 2020-10-03 17:40:45 +0530 | [diff] [blame] | 15 | int advice_push_ref_needs_update = 1; |
Jeff King | edf563f | 2009-09-09 07:43:03 -0400 | [diff] [blame] | 16 | int advice_status_hints = 1; |
Nguyễn Thái Ngọc Duy | 6a38ef2 | 2013-03-13 19:59:16 +0700 | [diff] [blame] | 17 | int advice_status_u_option = 1; |
Jeff Hostetler | 0a53561 | 2019-06-18 13:21:27 -0700 | [diff] [blame] | 18 | int advice_status_ahead_behind_warning = 1; |
Matthieu Moy | 4c371f9 | 2009-11-22 23:26:17 +0100 | [diff] [blame] | 19 | int advice_commit_before_merge = 1; |
Ben Peart | 649bf3a | 2018-10-23 15:04:23 -0400 | [diff] [blame] | 20 | int advice_reset_quiet_warning = 1; |
Matthieu Moy | d38a30d | 2010-01-12 10:54:44 +0100 | [diff] [blame] | 21 | int advice_resolve_conflict = 1; |
Rohit Ashiwal | 6a1f904 | 2019-07-02 14:41:25 +0530 | [diff] [blame] | 22 | int advice_sequencer_in_use = 1; |
Jeff King | b706fcf | 2010-01-13 15:17:08 -0500 | [diff] [blame] | 23 | int advice_implicit_identity = 1; |
Junio C Hamano | 13be3e3 | 2010-01-29 22:03:24 -0800 | [diff] [blame] | 24 | int advice_detached_head = 1; |
Jeff King | caa2036 | 2013-04-02 15:05:12 -0400 | [diff] [blame] | 25 | int advice_set_upstream_failure = 1; |
Nguyễn Thái Ngọc Duy | 798c35f | 2013-05-29 19:12:42 +0700 | [diff] [blame] | 26 | int advice_object_name_warning = 1; |
Nguyễn Thái Ngọc Duy | 431bb23 | 2018-05-26 15:55:27 +0200 | [diff] [blame] | 27 | int advice_amworkdir = 1; |
Mathieu Lienard--Mayor | 7e30944 | 2013-06-12 10:06:44 +0200 | [diff] [blame] | 28 | int advice_rm_hints = 1; |
Jeff King | 5321399 | 2017-06-14 06:58:22 -0400 | [diff] [blame] | 29 | int advice_add_embedded_repo = 1; |
Damien Marié | f805a00 | 2017-10-06 08:07:55 +0000 | [diff] [blame] | 30 | int advice_ignored_hook = 1; |
Lars Schneider | abfb04d | 2017-12-07 16:16:41 +0100 | [diff] [blame] | 31 | int advice_waiting_for_editor = 1; |
Johannes Schindelin | f9f99b3 | 2018-04-29 00:44:44 +0200 | [diff] [blame] | 32 | int advice_graft_file_deprecated = 1; |
Ævar Arnfjörð Bjarmason | ad8d510 | 2018-06-05 14:40:48 +0000 | [diff] [blame] | 33 | int advice_checkout_ambiguous_remote_branch_name = 1; |
Jonathan Tan | 4f3e57e | 2019-12-02 11:57:52 -0800 | [diff] [blame] | 34 | int advice_submodule_alternate_error_strategy_die = 1; |
Heba Waly | 887a0fd | 2020-02-06 23:57:30 +1300 | [diff] [blame] | 35 | int advice_add_ignored_file = 1; |
| 36 | int advice_add_empty_pathspec = 1; |
Jeff King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 37 | |
Ryan Dammrose | 960786e | 2018-04-21 12:10:00 +0200 | [diff] [blame] | 38 | static int advice_use_color = -1; |
| 39 | static char advice_colors[][COLOR_MAXLEN] = { |
| 40 | GIT_COLOR_RESET, |
| 41 | GIT_COLOR_YELLOW, /* HINT */ |
| 42 | }; |
| 43 | |
| 44 | enum color_advice { |
| 45 | ADVICE_COLOR_RESET = 0, |
| 46 | ADVICE_COLOR_HINT = 1, |
| 47 | }; |
| 48 | |
| 49 | static int parse_advise_color_slot(const char *slot) |
| 50 | { |
| 51 | if (!strcasecmp(slot, "reset")) |
| 52 | return ADVICE_COLOR_RESET; |
| 53 | if (!strcasecmp(slot, "hint")) |
| 54 | return ADVICE_COLOR_HINT; |
| 55 | return -1; |
| 56 | } |
| 57 | |
| 58 | static const char *advise_get_color(enum color_advice ix) |
| 59 | { |
| 60 | if (want_color_stderr(advice_use_color)) |
| 61 | return advice_colors[ix]; |
| 62 | return ""; |
| 63 | } |
| 64 | |
Jeff King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 65 | static struct { |
| 66 | const char *name; |
| 67 | int *preference; |
| 68 | } advice_config[] = { |
Derrick Stolee | 377444b | 2019-06-18 13:25:27 -0700 | [diff] [blame] | 69 | { "fetchShowForcedUpdates", &advice_fetch_show_forced_updates }, |
Nguyễn Thái Ngọc Duy | fb6fbff | 2018-05-26 15:55:26 +0200 | [diff] [blame] | 70 | { "pushUpdateRejected", &advice_push_update_rejected }, |
| 71 | { "pushNonFFCurrent", &advice_push_non_ff_current }, |
| 72 | { "pushNonFFMatching", &advice_push_non_ff_matching }, |
| 73 | { "pushAlreadyExists", &advice_push_already_exists }, |
| 74 | { "pushFetchFirst", &advice_push_fetch_first }, |
| 75 | { "pushNeedsForce", &advice_push_needs_force }, |
Ævar Arnfjörð Bjarmason | dd8dd30 | 2018-11-13 19:52:43 +0000 | [diff] [blame] | 76 | { "pushUnqualifiedRefName", &advice_push_unqualified_ref_name }, |
Srinidhi Kaushik | 3b990aa | 2020-10-03 17:40:45 +0530 | [diff] [blame] | 77 | { "pushRefNeedsUpdate", &advice_push_ref_needs_update }, |
Nguyễn Thái Ngọc Duy | fb6fbff | 2018-05-26 15:55:26 +0200 | [diff] [blame] | 78 | { "statusHints", &advice_status_hints }, |
| 79 | { "statusUoption", &advice_status_u_option }, |
Jeff Hostetler | 0a53561 | 2019-06-18 13:21:27 -0700 | [diff] [blame] | 80 | { "statusAheadBehindWarning", &advice_status_ahead_behind_warning }, |
Nguyễn Thái Ngọc Duy | fb6fbff | 2018-05-26 15:55:26 +0200 | [diff] [blame] | 81 | { "commitBeforeMerge", &advice_commit_before_merge }, |
Ben Peart | 649bf3a | 2018-10-23 15:04:23 -0400 | [diff] [blame] | 82 | { "resetQuiet", &advice_reset_quiet_warning }, |
Nguyễn Thái Ngọc Duy | fb6fbff | 2018-05-26 15:55:26 +0200 | [diff] [blame] | 83 | { "resolveConflict", &advice_resolve_conflict }, |
Rohit Ashiwal | 6a1f904 | 2019-07-02 14:41:25 +0530 | [diff] [blame] | 84 | { "sequencerInUse", &advice_sequencer_in_use }, |
Nguyễn Thái Ngọc Duy | fb6fbff | 2018-05-26 15:55:26 +0200 | [diff] [blame] | 85 | { "implicitIdentity", &advice_implicit_identity }, |
| 86 | { "detachedHead", &advice_detached_head }, |
Heba Waly | fef0c76 | 2020-03-02 20:01:58 +0000 | [diff] [blame] | 87 | { "setUpstreamFailure", &advice_set_upstream_failure }, |
Nguyễn Thái Ngọc Duy | fb6fbff | 2018-05-26 15:55:26 +0200 | [diff] [blame] | 88 | { "objectNameWarning", &advice_object_name_warning }, |
Nguyễn Thái Ngọc Duy | 431bb23 | 2018-05-26 15:55:27 +0200 | [diff] [blame] | 89 | { "amWorkDir", &advice_amworkdir }, |
Nguyễn Thái Ngọc Duy | fb6fbff | 2018-05-26 15:55:26 +0200 | [diff] [blame] | 90 | { "rmHints", &advice_rm_hints }, |
| 91 | { "addEmbeddedRepo", &advice_add_embedded_repo }, |
| 92 | { "ignoredHook", &advice_ignored_hook }, |
| 93 | { "waitingForEditor", &advice_waiting_for_editor }, |
| 94 | { "graftFileDeprecated", &advice_graft_file_deprecated }, |
Junio C Hamano | 50858ed | 2018-08-02 15:30:41 -0700 | [diff] [blame] | 95 | { "checkoutAmbiguousRemoteBranchName", &advice_checkout_ambiguous_remote_branch_name }, |
Jonathan Tan | 4f3e57e | 2019-12-02 11:57:52 -0800 | [diff] [blame] | 96 | { "submoduleAlternateErrorStrategyDie", &advice_submodule_alternate_error_strategy_die }, |
Heba Waly | 887a0fd | 2020-02-06 23:57:30 +1300 | [diff] [blame] | 97 | { "addIgnoredFile", &advice_add_ignored_file }, |
| 98 | { "addEmptyPathspec", &advice_add_empty_pathspec }, |
Chris Rorvick | 1184564 | 2012-12-02 21:27:50 -0600 | [diff] [blame] | 99 | |
| 100 | /* make this an alias for backward compatibility */ |
Nguyễn Thái Ngọc Duy | fb6fbff | 2018-05-26 15:55:26 +0200 | [diff] [blame] | 101 | { "pushNonFastForward", &advice_push_update_rejected } |
Jeff King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 102 | }; |
| 103 | |
Heba Waly | b3b18d1 | 2020-03-02 20:01:59 +0000 | [diff] [blame] | 104 | static struct { |
| 105 | const char *key; |
| 106 | int enabled; |
| 107 | } advice_setting[] = { |
| 108 | [ADVICE_ADD_EMBEDDED_REPO] = { "addEmbeddedRepo", 1 }, |
| 109 | [ADVICE_AM_WORK_DIR] = { "amWorkDir", 1 }, |
| 110 | [ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] = { "checkoutAmbiguousRemoteBranchName", 1 }, |
| 111 | [ADVICE_COMMIT_BEFORE_MERGE] = { "commitBeforeMerge", 1 }, |
| 112 | [ADVICE_DETACHED_HEAD] = { "detachedHead", 1 }, |
| 113 | [ADVICE_FETCH_SHOW_FORCED_UPDATES] = { "fetchShowForcedUpdates", 1 }, |
| 114 | [ADVICE_GRAFT_FILE_DEPRECATED] = { "graftFileDeprecated", 1 }, |
| 115 | [ADVICE_IGNORED_HOOK] = { "ignoredHook", 1 }, |
| 116 | [ADVICE_IMPLICIT_IDENTITY] = { "implicitIdentity", 1 }, |
| 117 | [ADVICE_NESTED_TAG] = { "nestedTag", 1 }, |
| 118 | [ADVICE_OBJECT_NAME_WARNING] = { "objectNameWarning", 1 }, |
| 119 | [ADVICE_PUSH_ALREADY_EXISTS] = { "pushAlreadyExists", 1 }, |
| 120 | [ADVICE_PUSH_FETCH_FIRST] = { "pushFetchFirst", 1 }, |
| 121 | [ADVICE_PUSH_NEEDS_FORCE] = { "pushNeedsForce", 1 }, |
Srinidhi Kaushik | 3b990aa | 2020-10-03 17:40:45 +0530 | [diff] [blame] | 122 | [ADVICE_PUSH_REF_NEEDS_UPDATE] = { "pushRefNeedsUpdate", 1 }, |
Heba Waly | b3b18d1 | 2020-03-02 20:01:59 +0000 | [diff] [blame] | 123 | |
| 124 | /* make this an alias for backward compatibility */ |
| 125 | [ADVICE_PUSH_UPDATE_REJECTED_ALIAS] = { "pushNonFastForward", 1 }, |
| 126 | |
| 127 | [ADVICE_PUSH_NON_FF_CURRENT] = { "pushNonFFCurrent", 1 }, |
| 128 | [ADVICE_PUSH_NON_FF_MATCHING] = { "pushNonFFMatching", 1 }, |
| 129 | [ADVICE_PUSH_UNQUALIFIED_REF_NAME] = { "pushUnqualifiedRefName", 1 }, |
| 130 | [ADVICE_PUSH_UPDATE_REJECTED] = { "pushUpdateRejected", 1 }, |
| 131 | [ADVICE_RESET_QUIET_WARNING] = { "resetQuiet", 1 }, |
| 132 | [ADVICE_RESOLVE_CONFLICT] = { "resolveConflict", 1 }, |
| 133 | [ADVICE_RM_HINTS] = { "rmHints", 1 }, |
| 134 | [ADVICE_SEQUENCER_IN_USE] = { "sequencerInUse", 1 }, |
| 135 | [ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure", 1 }, |
| 136 | [ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning", 1 }, |
| 137 | [ADVICE_STATUS_HINTS] = { "statusHints", 1 }, |
| 138 | [ADVICE_STATUS_U_OPTION] = { "statusUoption", 1 }, |
| 139 | [ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE] = { "submoduleAlternateErrorStrategyDie", 1 }, |
Matheus Tavares | a20f704 | 2021-04-08 17:41:27 -0300 | [diff] [blame] | 140 | [ADVICE_UPDATE_SPARSE_PATH] = { "updateSparsePath", 1 }, |
Heba Waly | b3b18d1 | 2020-03-02 20:01:59 +0000 | [diff] [blame] | 141 | [ADVICE_WAITING_FOR_EDITOR] = { "waitingForEditor", 1 }, |
| 142 | }; |
| 143 | |
| 144 | static const char turn_off_instructions[] = |
| 145 | N_("\n" |
| 146 | "Disable this message with \"git config advice.%s false\""); |
| 147 | |
| 148 | static void vadvise(const char *advice, int display_instructions, |
| 149 | const char *key, va_list params) |
Ramkumar Ramachandra | 38ef61c | 2011-08-04 16:08:59 +0530 | [diff] [blame] | 150 | { |
Junio C Hamano | 23cb5bf | 2011-12-22 11:21:26 -0800 | [diff] [blame] | 151 | struct strbuf buf = STRBUF_INIT; |
Junio C Hamano | 23cb5bf | 2011-12-22 11:21:26 -0800 | [diff] [blame] | 152 | const char *cp, *np; |
Ramkumar Ramachandra | 38ef61c | 2011-08-04 16:08:59 +0530 | [diff] [blame] | 153 | |
Jeff King | 447b99c | 2012-07-23 14:48:57 -0400 | [diff] [blame] | 154 | strbuf_vaddf(&buf, advice, params); |
Junio C Hamano | 23cb5bf | 2011-12-22 11:21:26 -0800 | [diff] [blame] | 155 | |
Heba Waly | b3b18d1 | 2020-03-02 20:01:59 +0000 | [diff] [blame] | 156 | if (display_instructions) |
| 157 | strbuf_addf(&buf, turn_off_instructions, key); |
Junio C Hamano | 23cb5bf | 2011-12-22 11:21:26 -0800 | [diff] [blame] | 158 | |
| 159 | for (cp = buf.buf; *cp; cp = np) { |
| 160 | np = strchrnul(cp, '\n'); |
Ryan Dammrose | 960786e | 2018-04-21 12:10:00 +0200 | [diff] [blame] | 161 | fprintf(stderr, _("%shint: %.*s%s\n"), |
| 162 | advise_get_color(ADVICE_COLOR_HINT), |
| 163 | (int)(np - cp), cp, |
| 164 | advise_get_color(ADVICE_COLOR_RESET)); |
Junio C Hamano | 23cb5bf | 2011-12-22 11:21:26 -0800 | [diff] [blame] | 165 | if (*np) |
| 166 | np++; |
| 167 | } |
| 168 | strbuf_release(&buf); |
Ramkumar Ramachandra | 38ef61c | 2011-08-04 16:08:59 +0530 | [diff] [blame] | 169 | } |
| 170 | |
Heba Waly | 06ac2b3 | 2020-03-02 20:01:57 +0000 | [diff] [blame] | 171 | void advise(const char *advice, ...) |
| 172 | { |
| 173 | va_list params; |
| 174 | va_start(params, advice); |
Heba Waly | b3b18d1 | 2020-03-02 20:01:59 +0000 | [diff] [blame] | 175 | vadvise(advice, 0, "", params); |
| 176 | va_end(params); |
| 177 | } |
| 178 | |
| 179 | int advice_enabled(enum advice_type type) |
| 180 | { |
| 181 | switch(type) { |
| 182 | case ADVICE_PUSH_UPDATE_REJECTED: |
| 183 | return advice_setting[ADVICE_PUSH_UPDATE_REJECTED].enabled && |
| 184 | advice_setting[ADVICE_PUSH_UPDATE_REJECTED_ALIAS].enabled; |
| 185 | default: |
| 186 | return advice_setting[type].enabled; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | void advise_if_enabled(enum advice_type type, const char *advice, ...) |
| 191 | { |
| 192 | va_list params; |
| 193 | |
| 194 | if (!advice_enabled(type)) |
| 195 | return; |
| 196 | |
| 197 | va_start(params, advice); |
| 198 | vadvise(advice, 1, advice_setting[type].key, params); |
Heba Waly | 06ac2b3 | 2020-03-02 20:01:57 +0000 | [diff] [blame] | 199 | va_end(params); |
| 200 | } |
| 201 | |
Jeff King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 202 | int git_default_advice_config(const char *var, const char *value) |
| 203 | { |
Ryan Dammrose | 960786e | 2018-04-21 12:10:00 +0200 | [diff] [blame] | 204 | const char *k, *slot_name; |
Jeff King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 205 | int i; |
| 206 | |
Ryan Dammrose | 960786e | 2018-04-21 12:10:00 +0200 | [diff] [blame] | 207 | if (!strcmp(var, "color.advice")) { |
| 208 | advice_use_color = git_config_colorbool(var, value); |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | if (skip_prefix(var, "color.advice.", &slot_name)) { |
| 213 | int slot = parse_advise_color_slot(slot_name); |
| 214 | if (slot < 0) |
| 215 | return 0; |
| 216 | if (!value) |
| 217 | return config_error_nonbool(var); |
| 218 | return color_parse(value, advice_colors[slot]); |
| 219 | } |
| 220 | |
Jeff King | cf4fff5 | 2014-06-18 15:44:19 -0400 | [diff] [blame] | 221 | if (!skip_prefix(var, "advice.", &k)) |
| 222 | return 0; |
| 223 | |
Jeff King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 224 | for (i = 0; i < ARRAY_SIZE(advice_config); i++) { |
Nguyễn Thái Ngọc Duy | fb6fbff | 2018-05-26 15:55:26 +0200 | [diff] [blame] | 225 | if (strcasecmp(k, advice_config[i].name)) |
Jeff King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 226 | continue; |
| 227 | *advice_config[i].preference = git_config_bool(var, value); |
Heba Waly | b3b18d1 | 2020-03-02 20:01:59 +0000 | [diff] [blame] | 228 | break; |
| 229 | } |
| 230 | |
| 231 | for (i = 0; i < ARRAY_SIZE(advice_setting); i++) { |
| 232 | if (strcasecmp(k, advice_setting[i].key)) |
| 233 | continue; |
| 234 | advice_setting[i].enabled = git_config_bool(var, value); |
Jeff King | 7519443 | 2009-09-09 07:38:58 -0400 | [diff] [blame] | 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | return 0; |
| 239 | } |
Matthieu Moy | d38a30d | 2010-01-12 10:54:44 +0100 | [diff] [blame] | 240 | |
Nguyễn Thái Ngọc Duy | 3ac68a9 | 2018-05-26 15:55:24 +0200 | [diff] [blame] | 241 | void list_config_advices(struct string_list *list, const char *prefix) |
| 242 | { |
| 243 | int i; |
| 244 | |
Heba Waly | b3b18d1 | 2020-03-02 20:01:59 +0000 | [diff] [blame] | 245 | for (i = 0; i < ARRAY_SIZE(advice_setting); i++) |
| 246 | list_config_item(list, prefix, advice_setting[i].key); |
Nguyễn Thái Ngọc Duy | 3ac68a9 | 2018-05-26 15:55:24 +0200 | [diff] [blame] | 247 | } |
| 248 | |
Ramkumar Ramachandra | 38ef61c | 2011-08-04 16:08:59 +0530 | [diff] [blame] | 249 | int error_resolve_conflict(const char *me) |
Matthieu Moy | d38a30d | 2010-01-12 10:54:44 +0100 | [diff] [blame] | 250 | { |
Vasco Almeida | 8785c42 | 2016-06-17 20:20:52 +0000 | [diff] [blame] | 251 | if (!strcmp(me, "cherry-pick")) |
| 252 | error(_("Cherry-picking is not possible because you have unmerged files.")); |
| 253 | else if (!strcmp(me, "commit")) |
| 254 | error(_("Committing is not possible because you have unmerged files.")); |
| 255 | else if (!strcmp(me, "merge")) |
| 256 | error(_("Merging is not possible because you have unmerged files.")); |
| 257 | else if (!strcmp(me, "pull")) |
| 258 | error(_("Pulling is not possible because you have unmerged files.")); |
| 259 | else if (!strcmp(me, "revert")) |
| 260 | error(_("Reverting is not possible because you have unmerged files.")); |
| 261 | else |
| 262 | error(_("It is not possible to %s because you have unmerged files."), |
| 263 | me); |
| 264 | |
Junio C Hamano | 23cb5bf | 2011-12-22 11:21:26 -0800 | [diff] [blame] | 265 | if (advice_resolve_conflict) |
Matthieu Moy | d38a30d | 2010-01-12 10:54:44 +0100 | [diff] [blame] | 266 | /* |
| 267 | * Message used both when 'git commit' fails and when |
| 268 | * other commands doing a merge do. |
| 269 | */ |
Jeff King | c057b24 | 2014-06-03 03:17:17 -0400 | [diff] [blame] | 270 | 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] | 271 | "as appropriate to mark resolution and make a commit.")); |
Ramkumar Ramachandra | 38ef61c | 2011-08-04 16:08:59 +0530 | [diff] [blame] | 272 | return -1; |
| 273 | } |
| 274 | |
| 275 | void NORETURN die_resolve_conflict(const char *me) |
| 276 | { |
| 277 | error_resolve_conflict(me); |
Vasco Almeida | 8785c42 | 2016-06-17 20:20:52 +0000 | [diff] [blame] | 278 | die(_("Exiting because of an unresolved conflict.")); |
Matthieu Moy | d38a30d | 2010-01-12 10:54:44 +0100 | [diff] [blame] | 279 | } |
Nguyễn Thái Ngọc Duy | 2857093 | 2012-01-16 16:46:16 +0700 | [diff] [blame] | 280 | |
Paul Tan | 4a4cf9e | 2015-06-18 18:54:04 +0800 | [diff] [blame] | 281 | void NORETURN die_conclude_merge(void) |
| 282 | { |
| 283 | error(_("You have not concluded your merge (MERGE_HEAD exists).")); |
| 284 | if (advice_resolve_conflict) |
Alex Henrie | b744767 | 2015-10-01 22:25:33 -0600 | [diff] [blame] | 285 | advise(_("Please, commit your changes before merging.")); |
Paul Tan | 4a4cf9e | 2015-06-18 18:54:04 +0800 | [diff] [blame] | 286 | die(_("Exiting because of unfinished merge.")); |
| 287 | } |
| 288 | |
Matheus Tavares | a20f704 | 2021-04-08 17:41:27 -0300 | [diff] [blame] | 289 | void advise_on_updating_sparse_paths(struct string_list *pathspec_list) |
| 290 | { |
| 291 | struct string_list_item *item; |
| 292 | |
| 293 | if (!pathspec_list->nr) |
| 294 | return; |
| 295 | |
| 296 | fprintf(stderr, _("The following pathspecs didn't match any" |
| 297 | " eligible path, but they do match index\n" |
| 298 | "entries outside the current sparse checkout:\n")); |
| 299 | for_each_string_list_item(item, pathspec_list) |
| 300 | fprintf(stderr, "%s\n", item->string); |
| 301 | |
| 302 | advise_if_enabled(ADVICE_UPDATE_SPARSE_PATH, |
| 303 | _("Disable or modify the sparsity rules if you intend" |
| 304 | " to update such entries.")); |
| 305 | } |
| 306 | |
Nguyễn Thái Ngọc Duy | 2857093 | 2012-01-16 16:46:16 +0700 | [diff] [blame] | 307 | void detach_advice(const char *new_name) |
| 308 | { |
Vasco Almeida | e9f3cec | 2016-06-17 20:20:51 +0000 | [diff] [blame] | 309 | const char *fmt = |
Nguyễn Thái Ngọc Duy | 328c6cb | 2019-03-29 17:39:19 +0700 | [diff] [blame] | 310 | _("Note: switching to '%s'.\n" |
Nguyễn Thái Ngọc Duy | af9ded5 | 2019-03-29 17:38:58 +0700 | [diff] [blame] | 311 | "\n" |
Nguyễn Thái Ngọc Duy | 2857093 | 2012-01-16 16:46:16 +0700 | [diff] [blame] | 312 | "You are in 'detached HEAD' state. You can look around, make experimental\n" |
| 313 | "changes and commit them, and you can discard any commits you make in this\n" |
Nguyễn Thái Ngọc Duy | 328c6cb | 2019-03-29 17:39:19 +0700 | [diff] [blame] | 314 | "state without impacting any branches by switching back to a branch.\n" |
Nguyễn Thái Ngọc Duy | af9ded5 | 2019-03-29 17:38:58 +0700 | [diff] [blame] | 315 | "\n" |
Nguyễn Thái Ngọc Duy | 2857093 | 2012-01-16 16:46:16 +0700 | [diff] [blame] | 316 | "If you want to create a new branch to retain commits you create, you may\n" |
Nguyễn Thái Ngọc Duy | 328c6cb | 2019-03-29 17:39:19 +0700 | [diff] [blame] | 317 | "do so (now or later) by using -c with the switch command. Example:\n" |
Nguyễn Thái Ngọc Duy | af9ded5 | 2019-03-29 17:38:58 +0700 | [diff] [blame] | 318 | "\n" |
Nguyễn Thái Ngọc Duy | 328c6cb | 2019-03-29 17:39:19 +0700 | [diff] [blame] | 319 | " git switch -c <new-branch-name>\n" |
Nguyễn Thái Ngọc Duy | af9ded5 | 2019-03-29 17:38:58 +0700 | [diff] [blame] | 320 | "\n" |
Nguyễn Thái Ngọc Duy | 328c6cb | 2019-03-29 17:39:19 +0700 | [diff] [blame] | 321 | "Or undo this operation with:\n" |
Nguyễn Thái Ngọc Duy | af9ded5 | 2019-03-29 17:38:58 +0700 | [diff] [blame] | 322 | "\n" |
Nguyễn Thái Ngọc Duy | 328c6cb | 2019-03-29 17:39:19 +0700 | [diff] [blame] | 323 | " git switch -\n" |
Nguyễn Thái Ngọc Duy | af9ded5 | 2019-03-29 17:38:58 +0700 | [diff] [blame] | 324 | "\n" |
| 325 | "Turn off this advice by setting config variable advice.detachedHead to false\n\n"); |
Nguyễn Thái Ngọc Duy | 2857093 | 2012-01-16 16:46:16 +0700 | [diff] [blame] | 326 | |
| 327 | fprintf(stderr, fmt, new_name); |
| 328 | } |