2023-02-24 03:09:34 +03:00
|
|
|
#include "git-compat-util.h"
|
|
|
|
#include "advice.h"
|
2017-06-14 21:07:36 +03:00
|
|
|
#include "config.h"
|
2018-04-21 13:10:00 +03:00
|
|
|
#include "color.h"
|
2023-02-24 03:09:34 +03:00
|
|
|
#include "gettext.h"
|
2018-05-26 16:55:24 +03:00
|
|
|
#include "help.h"
|
2021-04-08 23:41:27 +03:00
|
|
|
#include "string-list.h"
|
2009-09-09 15:38:58 +04:00
|
|
|
|
2018-04-21 13:10:00 +03:00
|
|
|
static int advice_use_color = -1;
|
|
|
|
static char advice_colors[][COLOR_MAXLEN] = {
|
|
|
|
GIT_COLOR_RESET,
|
|
|
|
GIT_COLOR_YELLOW, /* HINT */
|
|
|
|
};
|
|
|
|
|
|
|
|
enum color_advice {
|
|
|
|
ADVICE_COLOR_RESET = 0,
|
|
|
|
ADVICE_COLOR_HINT = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int parse_advise_color_slot(const char *slot)
|
|
|
|
{
|
|
|
|
if (!strcasecmp(slot, "reset"))
|
|
|
|
return ADVICE_COLOR_RESET;
|
|
|
|
if (!strcasecmp(slot, "hint"))
|
|
|
|
return ADVICE_COLOR_HINT;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *advise_get_color(enum color_advice ix)
|
|
|
|
{
|
|
|
|
if (want_color_stderr(advice_use_color))
|
|
|
|
return advice_colors[ix];
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2024-01-15 17:28:28 +03:00
|
|
|
enum advice_level {
|
|
|
|
ADVICE_LEVEL_NONE = 0,
|
|
|
|
ADVICE_LEVEL_DISABLED,
|
|
|
|
ADVICE_LEVEL_ENABLED,
|
|
|
|
};
|
|
|
|
|
2020-03-02 23:01:59 +03:00
|
|
|
static struct {
|
|
|
|
const char *key;
|
2024-01-15 17:28:28 +03:00
|
|
|
enum advice_level level;
|
2020-03-02 23:01:59 +03:00
|
|
|
} advice_setting[] = {
|
2024-01-15 17:28:28 +03:00
|
|
|
[ADVICE_ADD_EMBEDDED_REPO] = { "addEmbeddedRepo" },
|
|
|
|
[ADVICE_ADD_EMPTY_PATHSPEC] = { "addEmptyPathspec" },
|
|
|
|
[ADVICE_ADD_IGNORED_FILE] = { "addIgnoredFile" },
|
|
|
|
[ADVICE_AMBIGUOUS_FETCH_REFSPEC] = { "ambiguousFetchRefspec" },
|
|
|
|
[ADVICE_AM_WORK_DIR] = { "amWorkDir" },
|
|
|
|
[ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] = { "checkoutAmbiguousRemoteBranchName" },
|
|
|
|
[ADVICE_COMMIT_BEFORE_MERGE] = { "commitBeforeMerge" },
|
|
|
|
[ADVICE_DETACHED_HEAD] = { "detachedHead" },
|
|
|
|
[ADVICE_DIVERGING] = { "diverging" },
|
|
|
|
[ADVICE_FETCH_SHOW_FORCED_UPDATES] = { "fetchShowForcedUpdates" },
|
|
|
|
[ADVICE_FORCE_DELETE_BRANCH] = { "forceDeleteBranch" },
|
|
|
|
[ADVICE_GRAFT_FILE_DEPRECATED] = { "graftFileDeprecated" },
|
|
|
|
[ADVICE_IGNORED_HOOK] = { "ignoredHook" },
|
|
|
|
[ADVICE_IMPLICIT_IDENTITY] = { "implicitIdentity" },
|
2024-03-17 00:16:29 +03:00
|
|
|
[ADVICE_MERGE_CONFLICT] = { "mergeConflict" },
|
2022-04-22 16:06:23 +03:00
|
|
|
[ADVICE_NAME_TOO_LONG] = { "nameTooLong" },
|
2024-01-15 17:28:28 +03:00
|
|
|
[ADVICE_NESTED_TAG] = { "nestedTag" },
|
|
|
|
[ADVICE_OBJECT_NAME_WARNING] = { "objectNameWarning" },
|
|
|
|
[ADVICE_PUSH_ALREADY_EXISTS] = { "pushAlreadyExists" },
|
|
|
|
[ADVICE_PUSH_FETCH_FIRST] = { "pushFetchFirst" },
|
|
|
|
[ADVICE_PUSH_NEEDS_FORCE] = { "pushNeedsForce" },
|
|
|
|
[ADVICE_PUSH_NON_FF_CURRENT] = { "pushNonFFCurrent" },
|
|
|
|
[ADVICE_PUSH_NON_FF_MATCHING] = { "pushNonFFMatching" },
|
|
|
|
[ADVICE_PUSH_REF_NEEDS_UPDATE] = { "pushRefNeedsUpdate" },
|
|
|
|
[ADVICE_PUSH_UNQUALIFIED_REF_NAME] = { "pushUnqualifiedRefName" },
|
|
|
|
[ADVICE_PUSH_UPDATE_REJECTED] = { "pushUpdateRejected" },
|
|
|
|
[ADVICE_PUSH_UPDATE_REJECTED_ALIAS] = { "pushNonFastForward" }, /* backwards compatibility */
|
2024-03-05 23:29:43 +03:00
|
|
|
[ADVICE_REF_SYNTAX] = { "refSyntax" },
|
2024-01-15 17:28:28 +03:00
|
|
|
[ADVICE_RESET_NO_REFRESH_WARNING] = { "resetNoRefresh" },
|
|
|
|
[ADVICE_RESOLVE_CONFLICT] = { "resolveConflict" },
|
|
|
|
[ADVICE_RM_HINTS] = { "rmHints" },
|
|
|
|
[ADVICE_SEQUENCER_IN_USE] = { "sequencerInUse" },
|
|
|
|
[ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure" },
|
|
|
|
[ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks" },
|
|
|
|
[ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning" },
|
|
|
|
[ADVICE_STATUS_HINTS] = { "statusHints" },
|
|
|
|
[ADVICE_STATUS_U_OPTION] = { "statusUoption" },
|
|
|
|
[ADVICE_SUBMODULES_NOT_UPDATED] = { "submodulesNotUpdated" },
|
|
|
|
[ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE] = { "submoduleAlternateErrorStrategyDie" },
|
2024-02-26 16:27:28 +03:00
|
|
|
[ADVICE_SUBMODULE_MERGE_CONFLICT] = { "submoduleMergeConflict" },
|
2024-01-15 17:28:28 +03:00
|
|
|
[ADVICE_SUGGEST_DETACHING_HEAD] = { "suggestDetachingHead" },
|
|
|
|
[ADVICE_UPDATE_SPARSE_PATH] = { "updateSparsePath" },
|
fsmonitor: reintroduce core.useBuiltinFSMonitor
Reintroduce the 'core.useBuiltinFSMonitor' config setting (originally added
in 0a756b2a25 (fsmonitor: config settings are repository-specific,
2021-03-05)) after its removal from the upstream version of FSMonitor.
Upstream, the 'core.useBuiltinFSMonitor' setting was rendered obsolete by
"overloading" the 'core.fsmonitor' setting to take a boolean value. However,
several applications (e.g., 'scalar') utilize the original config setting,
so it should be preserved for a deprecation period before complete removal:
* if 'core.fsmonitor' is a boolean, the user is correctly using the new
config syntax; do not use 'core.useBuiltinFSMonitor'.
* if 'core.fsmonitor' is unspecified, use 'core.useBuiltinFSMonitor'.
* if 'core.fsmonitor' is a path, override and use the builtin FSMonitor if
'core.useBuiltinFSMonitor' is 'true'; otherwise, use the FSMonitor hook
indicated by the path.
Additionally, for this deprecation period, advise users to switch to using
'core.fsmonitor' to specify their use of the builtin FSMonitor.
Signed-off-by: Victoria Dye <vdye@github.com>
2022-04-05 01:38:58 +03:00
|
|
|
[ADVICE_USE_CORE_FSMONITOR_CONFIG] = { "useCoreFSMonitorConfig" },
|
2024-01-15 17:28:28 +03:00
|
|
|
[ADVICE_WAITING_FOR_EDITOR] = { "waitingForEditor" },
|
|
|
|
[ADVICE_WORKTREE_ADD_ORPHAN] = { "worktreeAddOrphan" },
|
2020-03-02 23:01:59 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char turn_off_instructions[] =
|
|
|
|
N_("\n"
|
|
|
|
"Disable this message with \"git config advice.%s false\"");
|
|
|
|
|
|
|
|
static void vadvise(const char *advice, int display_instructions,
|
|
|
|
const char *key, va_list params)
|
2011-08-04 14:38:59 +04:00
|
|
|
{
|
i18n of multi-line advice messages
Advice messages are by definition meant for human end-users, and prime
candidates for i18n/l10n. They tend to also be more verbose to be helpful,
and need to be longer than just one line.
Although we do not have parameterized multi-line advice messages yet, once
we do, we cannot emit such a message like this:
advise(_("Please rename %s to something else"), gostak);
advise(_("so that we can avoid distimming %s unnecessarily."), doshes);
because some translations may need to have the replacement of 'gostak' on
the second line (or 'doshes' on the first line). Some languages may even
need to use three lines in order to fit the same message within a
reasonable width.
Instead, it has to be a single advise() construct, like this:
advise(_("Please rename %s to something else\n"
"so that we can avoid distimming %s unnecessarily."),
gostak, doshes);
Update the advise() function and its existing callers to
- take a format string that can be multi-line and translatable as a
whole;
- use the string and the parameters to form a localized message; and
- show each line in the result with the localization of the "hint: ".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-12-22 23:21:26 +04:00
|
|
|
struct strbuf buf = STRBUF_INIT;
|
|
|
|
const char *cp, *np;
|
2011-08-04 14:38:59 +04:00
|
|
|
|
2012-07-23 22:48:57 +04:00
|
|
|
strbuf_vaddf(&buf, advice, params);
|
i18n of multi-line advice messages
Advice messages are by definition meant for human end-users, and prime
candidates for i18n/l10n. They tend to also be more verbose to be helpful,
and need to be longer than just one line.
Although we do not have parameterized multi-line advice messages yet, once
we do, we cannot emit such a message like this:
advise(_("Please rename %s to something else"), gostak);
advise(_("so that we can avoid distimming %s unnecessarily."), doshes);
because some translations may need to have the replacement of 'gostak' on
the second line (or 'doshes' on the first line). Some languages may even
need to use three lines in order to fit the same message within a
reasonable width.
Instead, it has to be a single advise() construct, like this:
advise(_("Please rename %s to something else\n"
"so that we can avoid distimming %s unnecessarily."),
gostak, doshes);
Update the advise() function and its existing callers to
- take a format string that can be multi-line and translatable as a
whole;
- use the string and the parameters to form a localized message; and
- show each line in the result with the localization of the "hint: ".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-12-22 23:21:26 +04:00
|
|
|
|
2020-03-02 23:01:59 +03:00
|
|
|
if (display_instructions)
|
|
|
|
strbuf_addf(&buf, turn_off_instructions, key);
|
i18n of multi-line advice messages
Advice messages are by definition meant for human end-users, and prime
candidates for i18n/l10n. They tend to also be more verbose to be helpful,
and need to be longer than just one line.
Although we do not have parameterized multi-line advice messages yet, once
we do, we cannot emit such a message like this:
advise(_("Please rename %s to something else"), gostak);
advise(_("so that we can avoid distimming %s unnecessarily."), doshes);
because some translations may need to have the replacement of 'gostak' on
the second line (or 'doshes' on the first line). Some languages may even
need to use three lines in order to fit the same message within a
reasonable width.
Instead, it has to be a single advise() construct, like this:
advise(_("Please rename %s to something else\n"
"so that we can avoid distimming %s unnecessarily."),
gostak, doshes);
Update the advise() function and its existing callers to
- take a format string that can be multi-line and translatable as a
whole;
- use the string and the parameters to form a localized message; and
- show each line in the result with the localization of the "hint: ".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-12-22 23:21:26 +04:00
|
|
|
|
|
|
|
for (cp = buf.buf; *cp; cp = np) {
|
|
|
|
np = strchrnul(cp, '\n');
|
2024-03-30 01:57:06 +03:00
|
|
|
fprintf(stderr, _("%shint:%s%.*s%s\n"),
|
2018-04-21 13:10:00 +03:00
|
|
|
advise_get_color(ADVICE_COLOR_HINT),
|
2024-03-30 01:57:06 +03:00
|
|
|
(np == cp) ? "" : " ",
|
2018-04-21 13:10:00 +03:00
|
|
|
(int)(np - cp), cp,
|
|
|
|
advise_get_color(ADVICE_COLOR_RESET));
|
i18n of multi-line advice messages
Advice messages are by definition meant for human end-users, and prime
candidates for i18n/l10n. They tend to also be more verbose to be helpful,
and need to be longer than just one line.
Although we do not have parameterized multi-line advice messages yet, once
we do, we cannot emit such a message like this:
advise(_("Please rename %s to something else"), gostak);
advise(_("so that we can avoid distimming %s unnecessarily."), doshes);
because some translations may need to have the replacement of 'gostak' on
the second line (or 'doshes' on the first line). Some languages may even
need to use three lines in order to fit the same message within a
reasonable width.
Instead, it has to be a single advise() construct, like this:
advise(_("Please rename %s to something else\n"
"so that we can avoid distimming %s unnecessarily."),
gostak, doshes);
Update the advise() function and its existing callers to
- take a format string that can be multi-line and translatable as a
whole;
- use the string and the parameters to form a localized message; and
- show each line in the result with the localization of the "hint: ".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-12-22 23:21:26 +04:00
|
|
|
if (*np)
|
|
|
|
np++;
|
|
|
|
}
|
|
|
|
strbuf_release(&buf);
|
2011-08-04 14:38:59 +04:00
|
|
|
}
|
|
|
|
|
2020-03-02 23:01:57 +03:00
|
|
|
void advise(const char *advice, ...)
|
|
|
|
{
|
|
|
|
va_list params;
|
|
|
|
va_start(params, advice);
|
2020-03-02 23:01:59 +03:00
|
|
|
vadvise(advice, 0, "", params);
|
|
|
|
va_end(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
int advice_enabled(enum advice_type type)
|
|
|
|
{
|
2024-01-15 17:28:28 +03:00
|
|
|
int enabled = advice_setting[type].level != ADVICE_LEVEL_DISABLED;
|
|
|
|
|
|
|
|
if (type == ADVICE_PUSH_UPDATE_REJECTED)
|
|
|
|
return enabled &&
|
|
|
|
advice_enabled(ADVICE_PUSH_UPDATE_REJECTED_ALIAS);
|
|
|
|
|
|
|
|
return enabled;
|
2020-03-02 23:01:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void advise_if_enabled(enum advice_type type, const char *advice, ...)
|
|
|
|
{
|
|
|
|
va_list params;
|
|
|
|
|
|
|
|
if (!advice_enabled(type))
|
|
|
|
return;
|
|
|
|
|
|
|
|
va_start(params, advice);
|
2024-01-15 17:28:28 +03:00
|
|
|
vadvise(advice, !advice_setting[type].level, advice_setting[type].key,
|
|
|
|
params);
|
2020-03-02 23:01:57 +03:00
|
|
|
va_end(params);
|
|
|
|
}
|
|
|
|
|
2009-09-09 15:38:58 +04:00
|
|
|
int git_default_advice_config(const char *var, const char *value)
|
|
|
|
{
|
2018-04-21 13:10:00 +03:00
|
|
|
const char *k, *slot_name;
|
2009-09-09 15:38:58 +04:00
|
|
|
int i;
|
|
|
|
|
2018-04-21 13:10:00 +03:00
|
|
|
if (!strcmp(var, "color.advice")) {
|
|
|
|
advice_use_color = git_config_colorbool(var, value);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skip_prefix(var, "color.advice.", &slot_name)) {
|
|
|
|
int slot = parse_advise_color_slot(slot_name);
|
|
|
|
if (slot < 0)
|
|
|
|
return 0;
|
|
|
|
if (!value)
|
|
|
|
return config_error_nonbool(var);
|
|
|
|
return color_parse(value, advice_colors[slot]);
|
|
|
|
}
|
|
|
|
|
refactor skip_prefix to return a boolean
The skip_prefix() function returns a pointer to the content
past the prefix, or NULL if the prefix was not found. While
this is nice and simple, in practice it makes it hard to use
for two reasons:
1. When you want to conditionally skip or keep the string
as-is, you have to introduce a temporary variable.
For example:
tmp = skip_prefix(buf, "foo");
if (tmp)
buf = tmp;
2. It is verbose to check the outcome in a conditional, as
you need extra parentheses to silence compiler
warnings. For example:
if ((cp = skip_prefix(buf, "foo"))
/* do something with cp */
Both of these make it harder to use for long if-chains, and
we tend to use starts_with() instead. However, the first line
of "do something" is often to then skip forward in buf past
the prefix, either using a magic constant or with an extra
strlen(3) (which is generally computed at compile time, but
means we are repeating ourselves).
This patch refactors skip_prefix() to return a simple boolean,
and to provide the pointer value as an out-parameter. If the
prefix is not found, the out-parameter is untouched. This
lets you write:
if (skip_prefix(arg, "foo ", &arg))
do_foo(arg);
else if (skip_prefix(arg, "bar ", &arg))
do_bar(arg);
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-06-18 23:44:19 +04:00
|
|
|
if (!skip_prefix(var, "advice.", &k))
|
|
|
|
return 0;
|
|
|
|
|
2020-03-02 23:01:59 +03:00
|
|
|
for (i = 0; i < ARRAY_SIZE(advice_setting); i++) {
|
|
|
|
if (strcasecmp(k, advice_setting[i].key))
|
|
|
|
continue;
|
2024-01-15 17:28:28 +03:00
|
|
|
advice_setting[i].level = git_config_bool(var, value)
|
|
|
|
? ADVICE_LEVEL_ENABLED
|
|
|
|
: ADVICE_LEVEL_DISABLED;
|
2009-09-09 15:38:58 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
Be more user-friendly when refusing to do something because of conflict.
Various commands refuse to run in the presence of conflicts (commit,
merge, pull, cherry-pick/revert). They all used to provide rough, and
inconsistant error messages.
A new variable advice.resolveconflict is introduced, and allows more
verbose messages, pointing the user to the appropriate solution.
For commit, the error message used to look like this:
$ git commit
foo.txt: needs merge
foo.txt: unmerged (c34a92682e0394bc0d6f4d4a67a8e2d32395c169)
foo.txt: unmerged (3afcd75de8de0bb5076942fcb17446be50451030)
foo.txt: unmerged (c9785d77b76dfe4fb038bf927ee518f6ae45ede4)
error: Error building trees
The "need merge" line is given by refresh_cache. We add the IN_PORCELAIN
option to make the output more consistant with the other porcelain
commands, and catch the error in return, to stop with a clean error
message. The next lines were displayed by a call to cache_tree_update(),
which is not reached anymore if we noticed the conflict.
The new output looks like:
U foo.txt
fatal: 'commit' is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>' as
appropriate to mark resolution and make a commit, or use 'git commit -a'.
Pull is slightly modified to abort immediately if $GIT_DIR/MERGE_HEAD
exists instead of waiting for merge to complain.
The behavior of merge and the test-case are slightly modified to reflect
the usual flow: start with conflicts, fix them, and afterwards get rid of
MERGE_HEAD, with different error messages at each stage.
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-12 12:54:44 +03:00
|
|
|
|
2018-05-26 16:55:24 +03:00
|
|
|
void list_config_advices(struct string_list *list, const char *prefix)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2020-03-02 23:01:59 +03:00
|
|
|
for (i = 0; i < ARRAY_SIZE(advice_setting); i++)
|
|
|
|
list_config_item(list, prefix, advice_setting[i].key);
|
2018-05-26 16:55:24 +03:00
|
|
|
}
|
|
|
|
|
2011-08-04 14:38:59 +04:00
|
|
|
int error_resolve_conflict(const char *me)
|
Be more user-friendly when refusing to do something because of conflict.
Various commands refuse to run in the presence of conflicts (commit,
merge, pull, cherry-pick/revert). They all used to provide rough, and
inconsistant error messages.
A new variable advice.resolveconflict is introduced, and allows more
verbose messages, pointing the user to the appropriate solution.
For commit, the error message used to look like this:
$ git commit
foo.txt: needs merge
foo.txt: unmerged (c34a92682e0394bc0d6f4d4a67a8e2d32395c169)
foo.txt: unmerged (3afcd75de8de0bb5076942fcb17446be50451030)
foo.txt: unmerged (c9785d77b76dfe4fb038bf927ee518f6ae45ede4)
error: Error building trees
The "need merge" line is given by refresh_cache. We add the IN_PORCELAIN
option to make the output more consistant with the other porcelain
commands, and catch the error in return, to stop with a clean error
message. The next lines were displayed by a call to cache_tree_update(),
which is not reached anymore if we noticed the conflict.
The new output looks like:
U foo.txt
fatal: 'commit' is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>' as
appropriate to mark resolution and make a commit, or use 'git commit -a'.
Pull is slightly modified to abort immediately if $GIT_DIR/MERGE_HEAD
exists instead of waiting for merge to complain.
The behavior of merge and the test-case are slightly modified to reflect
the usual flow: start with conflicts, fix them, and afterwards get rid of
MERGE_HEAD, with different error messages at each stage.
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-12 12:54:44 +03:00
|
|
|
{
|
2016-06-17 23:20:52 +03:00
|
|
|
if (!strcmp(me, "cherry-pick"))
|
|
|
|
error(_("Cherry-picking is not possible because you have unmerged files."));
|
|
|
|
else if (!strcmp(me, "commit"))
|
|
|
|
error(_("Committing is not possible because you have unmerged files."));
|
|
|
|
else if (!strcmp(me, "merge"))
|
|
|
|
error(_("Merging is not possible because you have unmerged files."));
|
|
|
|
else if (!strcmp(me, "pull"))
|
|
|
|
error(_("Pulling is not possible because you have unmerged files."));
|
|
|
|
else if (!strcmp(me, "revert"))
|
|
|
|
error(_("Reverting is not possible because you have unmerged files."));
|
2023-08-07 20:09:35 +03:00
|
|
|
else if (!strcmp(me, "rebase"))
|
|
|
|
error(_("Rebasing is not possible because you have unmerged files."));
|
2016-06-17 23:20:52 +03:00
|
|
|
else
|
2023-08-07 20:09:35 +03:00
|
|
|
BUG("Unhandled conflict reason '%s'", me);
|
2016-06-17 23:20:52 +03:00
|
|
|
|
2021-08-23 13:44:00 +03:00
|
|
|
if (advice_enabled(ADVICE_RESOLVE_CONFLICT))
|
Be more user-friendly when refusing to do something because of conflict.
Various commands refuse to run in the presence of conflicts (commit,
merge, pull, cherry-pick/revert). They all used to provide rough, and
inconsistant error messages.
A new variable advice.resolveconflict is introduced, and allows more
verbose messages, pointing the user to the appropriate solution.
For commit, the error message used to look like this:
$ git commit
foo.txt: needs merge
foo.txt: unmerged (c34a92682e0394bc0d6f4d4a67a8e2d32395c169)
foo.txt: unmerged (3afcd75de8de0bb5076942fcb17446be50451030)
foo.txt: unmerged (c9785d77b76dfe4fb038bf927ee518f6ae45ede4)
error: Error building trees
The "need merge" line is given by refresh_cache. We add the IN_PORCELAIN
option to make the output more consistant with the other porcelain
commands, and catch the error in return, to stop with a clean error
message. The next lines were displayed by a call to cache_tree_update(),
which is not reached anymore if we noticed the conflict.
The new output looks like:
U foo.txt
fatal: 'commit' is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>' as
appropriate to mark resolution and make a commit, or use 'git commit -a'.
Pull is slightly modified to abort immediately if $GIT_DIR/MERGE_HEAD
exists instead of waiting for merge to complain.
The behavior of merge and the test-case are slightly modified to reflect
the usual flow: start with conflicts, fix them, and afterwards get rid of
MERGE_HEAD, with different error messages at each stage.
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-12 12:54:44 +03:00
|
|
|
/*
|
|
|
|
* Message used both when 'git commit' fails and when
|
|
|
|
* other commands doing a merge do.
|
|
|
|
*/
|
2014-06-03 11:17:17 +04:00
|
|
|
advise(_("Fix them up in the work tree, and then use 'git add/rm <file>'\n"
|
merge, pull: stop advising 'commit -a' in case of conflict
'git commit -a' is rarely a good way to mark conflicts as resolved:
the user anyway has to go manually through the list of conflicts to
do the actual resolution, and it is usually better to use "git add"
on each files after doing the resolution.
On the other hand, using 'git commit -a' is potentially dangerous,
as it makes it very easy to mistakenly commit conflict markers
without noticing, and even worse, the user may have started a merge
while having local changes that do not overlap with it in the
working tree.
While we're there, synchronize the 'git pull' and 'git merge'
messages: the first was ending with '... and make a commit.', but
not the latter.
Eventually, git should detect that conflicts have been resolved in
the working tree and tailor these messages further. Not only "use
git commit -a" could be resurected, but "Fix them up in the work
tree" should be dropped when it happens.
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-08-28 13:46:58 +04:00
|
|
|
"as appropriate to mark resolution and make a commit."));
|
2011-08-04 14:38:59 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NORETURN die_resolve_conflict(const char *me)
|
|
|
|
{
|
|
|
|
error_resolve_conflict(me);
|
2016-06-17 23:20:52 +03:00
|
|
|
die(_("Exiting because of an unresolved conflict."));
|
Be more user-friendly when refusing to do something because of conflict.
Various commands refuse to run in the presence of conflicts (commit,
merge, pull, cherry-pick/revert). They all used to provide rough, and
inconsistant error messages.
A new variable advice.resolveconflict is introduced, and allows more
verbose messages, pointing the user to the appropriate solution.
For commit, the error message used to look like this:
$ git commit
foo.txt: needs merge
foo.txt: unmerged (c34a92682e0394bc0d6f4d4a67a8e2d32395c169)
foo.txt: unmerged (3afcd75de8de0bb5076942fcb17446be50451030)
foo.txt: unmerged (c9785d77b76dfe4fb038bf927ee518f6ae45ede4)
error: Error building trees
The "need merge" line is given by refresh_cache. We add the IN_PORCELAIN
option to make the output more consistant with the other porcelain
commands, and catch the error in return, to stop with a clean error
message. The next lines were displayed by a call to cache_tree_update(),
which is not reached anymore if we noticed the conflict.
The new output looks like:
U foo.txt
fatal: 'commit' is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>' as
appropriate to mark resolution and make a commit, or use 'git commit -a'.
Pull is slightly modified to abort immediately if $GIT_DIR/MERGE_HEAD
exists instead of waiting for merge to complain.
The behavior of merge and the test-case are slightly modified to reflect
the usual flow: start with conflicts, fix them, and afterwards get rid of
MERGE_HEAD, with different error messages at each stage.
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-01-12 12:54:44 +03:00
|
|
|
}
|
2012-01-16 13:46:16 +04:00
|
|
|
|
2015-06-18 13:54:04 +03:00
|
|
|
void NORETURN die_conclude_merge(void)
|
|
|
|
{
|
|
|
|
error(_("You have not concluded your merge (MERGE_HEAD exists)."));
|
2021-08-23 13:44:00 +03:00
|
|
|
if (advice_enabled(ADVICE_RESOLVE_CONFLICT))
|
2015-10-02 07:25:33 +03:00
|
|
|
advise(_("Please, commit your changes before merging."));
|
2015-06-18 13:54:04 +03:00
|
|
|
die(_("Exiting because of unfinished merge."));
|
|
|
|
}
|
|
|
|
|
2021-07-21 04:42:19 +03:00
|
|
|
void NORETURN die_ff_impossible(void)
|
|
|
|
{
|
2023-03-08 05:48:33 +03:00
|
|
|
advise_if_enabled(ADVICE_DIVERGING,
|
|
|
|
_("Diverging branches can't be fast-forwarded, you need to either:\n"
|
|
|
|
"\n"
|
|
|
|
"\tgit merge --no-ff\n"
|
|
|
|
"\n"
|
|
|
|
"or:\n"
|
|
|
|
"\n"
|
|
|
|
"\tgit rebase\n"));
|
2021-07-21 04:42:19 +03:00
|
|
|
die(_("Not possible to fast-forward, aborting."));
|
|
|
|
}
|
|
|
|
|
2021-04-08 23:41:27 +03:00
|
|
|
void advise_on_updating_sparse_paths(struct string_list *pathspec_list)
|
|
|
|
{
|
|
|
|
struct string_list_item *item;
|
|
|
|
|
|
|
|
if (!pathspec_list->nr)
|
|
|
|
return;
|
|
|
|
|
2021-09-24 18:39:14 +03:00
|
|
|
fprintf(stderr, _("The following paths and/or pathspecs matched paths that exist\n"
|
|
|
|
"outside of your sparse-checkout definition, so will not be\n"
|
|
|
|
"updated in the index:\n"));
|
2021-04-08 23:41:27 +03:00
|
|
|
for_each_string_list_item(item, pathspec_list)
|
|
|
|
fprintf(stderr, "%s\n", item->string);
|
|
|
|
|
|
|
|
advise_if_enabled(ADVICE_UPDATE_SPARSE_PATH,
|
2021-09-24 18:39:14 +03:00
|
|
|
_("If you intend to update such entries, try one of the following:\n"
|
|
|
|
"* Use the --sparse option.\n"
|
|
|
|
"* Disable or modify the sparsity rules."));
|
2021-04-08 23:41:27 +03:00
|
|
|
}
|
|
|
|
|
2012-01-16 13:46:16 +04:00
|
|
|
void detach_advice(const char *new_name)
|
|
|
|
{
|
2016-06-17 23:20:51 +03:00
|
|
|
const char *fmt =
|
2019-03-29 13:39:19 +03:00
|
|
|
_("Note: switching to '%s'.\n"
|
2019-03-29 13:38:58 +03:00
|
|
|
"\n"
|
2012-01-16 13:46:16 +04:00
|
|
|
"You are in 'detached HEAD' state. You can look around, make experimental\n"
|
|
|
|
"changes and commit them, and you can discard any commits you make in this\n"
|
2019-03-29 13:39:19 +03:00
|
|
|
"state without impacting any branches by switching back to a branch.\n"
|
2019-03-29 13:38:58 +03:00
|
|
|
"\n"
|
2012-01-16 13:46:16 +04:00
|
|
|
"If you want to create a new branch to retain commits you create, you may\n"
|
2019-03-29 13:39:19 +03:00
|
|
|
"do so (now or later) by using -c with the switch command. Example:\n"
|
2019-03-29 13:38:58 +03:00
|
|
|
"\n"
|
2019-03-29 13:39:19 +03:00
|
|
|
" git switch -c <new-branch-name>\n"
|
2019-03-29 13:38:58 +03:00
|
|
|
"\n"
|
2019-03-29 13:39:19 +03:00
|
|
|
"Or undo this operation with:\n"
|
2019-03-29 13:38:58 +03:00
|
|
|
"\n"
|
2019-03-29 13:39:19 +03:00
|
|
|
" git switch -\n"
|
2019-03-29 13:38:58 +03:00
|
|
|
"\n"
|
|
|
|
"Turn off this advice by setting config variable advice.detachedHead to false\n\n");
|
2012-01-16 13:46:16 +04:00
|
|
|
|
|
|
|
fprintf(stderr, fmt, new_name);
|
|
|
|
}
|
2022-08-09 15:09:09 +03:00
|
|
|
|
|
|
|
void advise_on_moving_dirty_path(struct string_list *pathspec_list)
|
|
|
|
{
|
|
|
|
struct string_list_item *item;
|
|
|
|
|
|
|
|
if (!pathspec_list->nr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fprintf(stderr, _("The following paths have been moved outside the\n"
|
|
|
|
"sparse-checkout definition but are not sparse due to local\n"
|
|
|
|
"modifications.\n"));
|
|
|
|
for_each_string_list_item(item, pathspec_list)
|
|
|
|
fprintf(stderr, "%s\n", item->string);
|
|
|
|
|
|
|
|
advise_if_enabled(ADVICE_UPDATE_SPARSE_PATH,
|
|
|
|
_("To correct the sparsity of these paths, do the following:\n"
|
|
|
|
"* Use \"git add --sparse <paths>\" to update the index\n"
|
|
|
|
"* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
|
|
|
|
}
|