2023-02-24 00:09:34 +00:00
|
|
|
#include "git-compat-util.h"
|
|
|
|
#include "advice.h"
|
2017-06-14 18:07:36 +00:00
|
|
|
#include "config.h"
|
2018-04-21 10:10:00 +00:00
|
|
|
#include "color.h"
|
2024-05-03 07:17:06 +00:00
|
|
|
#include "environment.h"
|
2023-02-24 00:09:34 +00:00
|
|
|
#include "gettext.h"
|
2018-05-26 13:55:24 +00:00
|
|
|
#include "help.h"
|
2021-04-08 20:41:27 +00:00
|
|
|
#include "string-list.h"
|
2009-09-09 11:38:58 +00:00
|
|
|
|
2018-04-21 10:10:00 +00: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 14:28:28 +00:00
|
|
|
enum advice_level {
|
|
|
|
ADVICE_LEVEL_NONE = 0,
|
|
|
|
ADVICE_LEVEL_DISABLED,
|
|
|
|
ADVICE_LEVEL_ENABLED,
|
|
|
|
};
|
|
|
|
|
2020-03-02 20:01:59 +00:00
|
|
|
static struct {
|
|
|
|
const char *key;
|
2024-01-15 14:28:28 +00:00
|
|
|
enum advice_level level;
|
2020-03-02 20:01:59 +00:00
|
|
|
} advice_setting[] = {
|
2024-01-15 14:28:28 +00: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-16 21:16:29 +00:00
|
|
|
[ADVICE_MERGE_CONFLICT] = { "mergeConflict" },
|
2024-01-15 14:28:28 +00: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-05-30 13:43:50 +00:00
|
|
|
[ADVICE_REBASE_TODO_ERROR] = { "rebaseTodoError" },
|
2024-03-05 20:29:43 +00:00
|
|
|
[ADVICE_REF_SYNTAX] = { "refSyntax" },
|
2024-01-15 14:28:28 +00: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: warn when sparse index expands
Typically, forcing a sparse index to expand to a full index means that
Git could not determine the status of a file outside of the
sparse-checkout and needed to expand sparse trees into the full list of
sparse blobs. This operation can be very slow when the sparse-checkout
is much smaller than the full tree at HEAD.
When users are in this state, there is usually a modified or untracked
file outside of the sparse-checkout mentioned by the output of 'git
status'. There are a number of reasons why this is insufficient:
1. Users may not have a full understanding of which files are inside or
outside of their sparse-checkout. This is more common in monorepos
that manage the sparse-checkout using custom tools that map build
dependencies into sparse-checkout definitions.
2. In some cases, an empty directory could exist outside the
sparse-checkout and these empty directories are not reported by 'git
status' and friends.
3. If the user has '.gitignore' or 'exclude' files, then 'git status'
will squelch the warnings and not demonstrate any problems.
In order to help users who are in this state, add a new advice message
to indicate that a sparse index is expanded to a full index. This
message should be written at most once per process, so add a static
global 'give_advice_on_expansion' to sparse-index.c. Further, there is a
case in 'git sparse-checkout set' that uses the sparse index as an
in-memory data structure (even when writing a full index) so we need to
disable the message in that kind of case.
The t1092-sparse-checkout-compatibility.sh test script compares the
behavior of several Git commands across full and sparse repositories,
including sparse repositories with and without a sparse index. We need
to disable the advice in the sparse-index repo to avoid differences in
stderr. By leaving the advice on in the sparse-checkout repo (without
the sparse index), we can test the behavior of disabling the advice in
convert_to_sparse(). (Indeed, these tests are how that necessity was
discovered.) Add a test that reenables the advice and demonstrates that
the message is output.
The advice message is defined outside of expand_index() to avoid super-
wide lines. It is also defined as a macro to avoid compile issues with
-Werror=format-security.
Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-07-08 14:13:58 +00:00
|
|
|
[ADVICE_SPARSE_INDEX_EXPANDED] = { "sparseIndexExpanded" },
|
2024-01-15 14:28:28 +00:00
|
|
|
[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 13:27:28 +00:00
|
|
|
[ADVICE_SUBMODULE_MERGE_CONFLICT] = { "submoduleMergeConflict" },
|
2024-01-15 14:28:28 +00:00
|
|
|
[ADVICE_SUGGEST_DETACHING_HEAD] = { "suggestDetachingHead" },
|
|
|
|
[ADVICE_UPDATE_SPARSE_PATH] = { "updateSparsePath" },
|
|
|
|
[ADVICE_WAITING_FOR_EDITOR] = { "waitingForEditor" },
|
|
|
|
[ADVICE_WORKTREE_ADD_ORPHAN] = { "worktreeAddOrphan" },
|
2020-03-02 20:01:59 +00: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 10:38:59 +00: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 19:21:26 +00:00
|
|
|
struct strbuf buf = STRBUF_INIT;
|
|
|
|
const char *cp, *np;
|
2011-08-04 10:38:59 +00:00
|
|
|
|
2012-07-23 18:48:57 +00: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 19:21:26 +00:00
|
|
|
|
2020-03-02 20:01:59 +00: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 19:21:26 +00:00
|
|
|
|
|
|
|
for (cp = buf.buf; *cp; cp = np) {
|
|
|
|
np = strchrnul(cp, '\n');
|
2024-03-29 22:57:06 +00:00
|
|
|
fprintf(stderr, _("%shint:%s%.*s%s\n"),
|
2018-04-21 10:10:00 +00:00
|
|
|
advise_get_color(ADVICE_COLOR_HINT),
|
2024-03-29 22:57:06 +00:00
|
|
|
(np == cp) ? "" : " ",
|
2018-04-21 10:10:00 +00: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 19:21:26 +00:00
|
|
|
if (*np)
|
|
|
|
np++;
|
|
|
|
}
|
|
|
|
strbuf_release(&buf);
|
2011-08-04 10:38:59 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 20:01:57 +00:00
|
|
|
void advise(const char *advice, ...)
|
|
|
|
{
|
|
|
|
va_list params;
|
|
|
|
va_start(params, advice);
|
2020-03-02 20:01:59 +00:00
|
|
|
vadvise(advice, 0, "", params);
|
|
|
|
va_end(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
int advice_enabled(enum advice_type type)
|
|
|
|
{
|
2024-01-15 14:28:28 +00:00
|
|
|
int enabled = advice_setting[type].level != ADVICE_LEVEL_DISABLED;
|
2024-05-03 07:17:06 +00:00
|
|
|
static int globally_enabled = -1;
|
|
|
|
|
|
|
|
if (globally_enabled < 0)
|
|
|
|
globally_enabled = git_env_bool(GIT_ADVICE_ENVIRONMENT, 1);
|
|
|
|
if (!globally_enabled)
|
|
|
|
return 0;
|
2024-01-15 14:28:28 +00:00
|
|
|
|
|
|
|
if (type == ADVICE_PUSH_UPDATE_REJECTED)
|
|
|
|
return enabled &&
|
|
|
|
advice_enabled(ADVICE_PUSH_UPDATE_REJECTED_ALIAS);
|
|
|
|
|
|
|
|
return enabled;
|
2020-03-02 20:01:59 +00: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 14:28:28 +00:00
|
|
|
vadvise(advice, !advice_setting[type].level, advice_setting[type].key,
|
|
|
|
params);
|
2020-03-02 20:01:57 +00:00
|
|
|
va_end(params);
|
|
|
|
}
|
|
|
|
|
2009-09-09 11:38:58 +00:00
|
|
|
int git_default_advice_config(const char *var, const char *value)
|
|
|
|
{
|
2018-04-21 10:10:00 +00:00
|
|
|
const char *k, *slot_name;
|
2009-09-09 11:38:58 +00:00
|
|
|
int i;
|
|
|
|
|
2018-04-21 10:10:00 +00: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 19:44:19 +00:00
|
|
|
if (!skip_prefix(var, "advice.", &k))
|
|
|
|
return 0;
|
|
|
|
|
2020-03-02 20:01:59 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(advice_setting); i++) {
|
|
|
|
if (strcasecmp(k, advice_setting[i].key))
|
|
|
|
continue;
|
2024-01-15 14:28:28 +00:00
|
|
|
advice_setting[i].level = git_config_bool(var, value)
|
|
|
|
? ADVICE_LEVEL_ENABLED
|
|
|
|
: ADVICE_LEVEL_DISABLED;
|
2009-09-09 11:38:58 +00: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 09:54:44 +00:00
|
|
|
|
2018-05-26 13:55:24 +00:00
|
|
|
void list_config_advices(struct string_list *list, const char *prefix)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2020-03-02 20:01:59 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(advice_setting); i++)
|
|
|
|
list_config_item(list, prefix, advice_setting[i].key);
|
2018-05-26 13:55:24 +00:00
|
|
|
}
|
|
|
|
|
2011-08-04 10:38:59 +00: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 09:54:44 +00:00
|
|
|
{
|
2016-06-17 20:20:52 +00: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 17:09:35 +00:00
|
|
|
else if (!strcmp(me, "rebase"))
|
|
|
|
error(_("Rebasing is not possible because you have unmerged files."));
|
2016-06-17 20:20:52 +00:00
|
|
|
else
|
2023-08-07 17:09:35 +00:00
|
|
|
BUG("Unhandled conflict reason '%s'", me);
|
2016-06-17 20:20:52 +00:00
|
|
|
|
2021-08-23 10:44:00 +00: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 09:54:44 +00:00
|
|
|
/*
|
|
|
|
* Message used both when 'git commit' fails and when
|
|
|
|
* other commands doing a merge do.
|
|
|
|
*/
|
2014-06-03 07:17:17 +00: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 09:46:58 +00:00
|
|
|
"as appropriate to mark resolution and make a commit."));
|
2011-08-04 10:38:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NORETURN die_resolve_conflict(const char *me)
|
|
|
|
{
|
|
|
|
error_resolve_conflict(me);
|
2016-06-17 20:20:52 +00: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 09:54:44 +00:00
|
|
|
}
|
2012-01-16 09:46:16 +00:00
|
|
|
|
2015-06-18 10:54:04 +00:00
|
|
|
void NORETURN die_conclude_merge(void)
|
|
|
|
{
|
|
|
|
error(_("You have not concluded your merge (MERGE_HEAD exists)."));
|
2021-08-23 10:44:00 +00:00
|
|
|
if (advice_enabled(ADVICE_RESOLVE_CONFLICT))
|
2015-10-02 04:25:33 +00:00
|
|
|
advise(_("Please, commit your changes before merging."));
|
2015-06-18 10:54:04 +00:00
|
|
|
die(_("Exiting because of unfinished merge."));
|
|
|
|
}
|
|
|
|
|
2021-07-21 01:42:19 +00:00
|
|
|
void NORETURN die_ff_impossible(void)
|
|
|
|
{
|
2023-03-08 02:48:33 +00: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 01:42:19 +00:00
|
|
|
die(_("Not possible to fast-forward, aborting."));
|
|
|
|
}
|
|
|
|
|
2021-04-08 20:41:27 +00: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 15:39:14 +00: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 20:41:27 +00: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 15:39:14 +00: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 20:41:27 +00:00
|
|
|
}
|
|
|
|
|
2012-01-16 09:46:16 +00:00
|
|
|
void detach_advice(const char *new_name)
|
|
|
|
{
|
2016-06-17 20:20:51 +00:00
|
|
|
const char *fmt =
|
2019-03-29 10:39:19 +00:00
|
|
|
_("Note: switching to '%s'.\n"
|
2019-03-29 10:38:58 +00:00
|
|
|
"\n"
|
2012-01-16 09:46:16 +00: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 10:39:19 +00:00
|
|
|
"state without impacting any branches by switching back to a branch.\n"
|
2019-03-29 10:38:58 +00:00
|
|
|
"\n"
|
2012-01-16 09:46:16 +00:00
|
|
|
"If you want to create a new branch to retain commits you create, you may\n"
|
2019-03-29 10:39:19 +00:00
|
|
|
"do so (now or later) by using -c with the switch command. Example:\n"
|
2019-03-29 10:38:58 +00:00
|
|
|
"\n"
|
2019-03-29 10:39:19 +00:00
|
|
|
" git switch -c <new-branch-name>\n"
|
2019-03-29 10:38:58 +00:00
|
|
|
"\n"
|
2019-03-29 10:39:19 +00:00
|
|
|
"Or undo this operation with:\n"
|
2019-03-29 10:38:58 +00:00
|
|
|
"\n"
|
2019-03-29 10:39:19 +00:00
|
|
|
" git switch -\n"
|
2019-03-29 10:38:58 +00:00
|
|
|
"\n"
|
|
|
|
"Turn off this advice by setting config variable advice.detachedHead to false\n\n");
|
2012-01-16 09:46:16 +00:00
|
|
|
|
|
|
|
fprintf(stderr, fmt, new_name);
|
|
|
|
}
|
2022-08-09 12:09:09 +00: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"));
|
|
|
|
}
|