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