2009-09-09 15:38:58 +04:00
|
|
|
#include "cache.h"
|
2017-06-14 21:07:36 +03:00
|
|
|
#include "config.h"
|
2018-04-21 13:10:00 +03:00
|
|
|
#include "color.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 "";
|
|
|
|
}
|
|
|
|
|
2020-03-02 23:01:59 +03:00
|
|
|
static struct {
|
|
|
|
const char *key;
|
|
|
|
int enabled;
|
|
|
|
} advice_setting[] = {
|
|
|
|
[ADVICE_ADD_EMBEDDED_REPO] = { "addEmbeddedRepo", 1 },
|
2021-08-23 13:43:59 +03:00
|
|
|
[ADVICE_ADD_EMPTY_PATHSPEC] = { "addEmptyPathspec", 1 },
|
|
|
|
[ADVICE_ADD_IGNORED_FILE] = { "addIgnoredFile", 1 },
|
2020-03-02 23:01:59 +03:00
|
|
|
[ADVICE_AM_WORK_DIR] = { "amWorkDir", 1 },
|
2022-04-01 09:05:13 +03:00
|
|
|
[ADVICE_AMBIGUOUS_FETCH_REFSPEC] = { "ambiguousFetchRefspec", 1 },
|
2020-03-02 23:01:59 +03:00
|
|
|
[ADVICE_CHECKOUT_AMBIGUOUS_REMOTE_BRANCH_NAME] = { "checkoutAmbiguousRemoteBranchName", 1 },
|
|
|
|
[ADVICE_COMMIT_BEFORE_MERGE] = { "commitBeforeMerge", 1 },
|
|
|
|
[ADVICE_DETACHED_HEAD] = { "detachedHead", 1 },
|
2022-02-26 09:12:13 +03:00
|
|
|
[ADVICE_SUGGEST_DETACHING_HEAD] = { "suggestDetachingHead", 1 },
|
2020-03-02 23:01:59 +03:00
|
|
|
[ADVICE_FETCH_SHOW_FORCED_UPDATES] = { "fetchShowForcedUpdates", 1 },
|
|
|
|
[ADVICE_GRAFT_FILE_DEPRECATED] = { "graftFileDeprecated", 1 },
|
|
|
|
[ADVICE_IGNORED_HOOK] = { "ignoredHook", 1 },
|
|
|
|
[ADVICE_IMPLICIT_IDENTITY] = { "implicitIdentity", 1 },
|
|
|
|
[ADVICE_NESTED_TAG] = { "nestedTag", 1 },
|
|
|
|
[ADVICE_OBJECT_NAME_WARNING] = { "objectNameWarning", 1 },
|
|
|
|
[ADVICE_PUSH_ALREADY_EXISTS] = { "pushAlreadyExists", 1 },
|
|
|
|
[ADVICE_PUSH_FETCH_FIRST] = { "pushFetchFirst", 1 },
|
|
|
|
[ADVICE_PUSH_NEEDS_FORCE] = { "pushNeedsForce", 1 },
|
2020-10-03 15:10:45 +03:00
|
|
|
[ADVICE_PUSH_REF_NEEDS_UPDATE] = { "pushRefNeedsUpdate", 1 },
|
2020-03-02 23:01:59 +03:00
|
|
|
|
|
|
|
/* make this an alias for backward compatibility */
|
|
|
|
[ADVICE_PUSH_UPDATE_REJECTED_ALIAS] = { "pushNonFastForward", 1 },
|
|
|
|
|
|
|
|
[ADVICE_PUSH_NON_FF_CURRENT] = { "pushNonFFCurrent", 1 },
|
|
|
|
[ADVICE_PUSH_NON_FF_MATCHING] = { "pushNonFFMatching", 1 },
|
|
|
|
[ADVICE_PUSH_UNQUALIFIED_REF_NAME] = { "pushUnqualifiedRefName", 1 },
|
|
|
|
[ADVICE_PUSH_UPDATE_REJECTED] = { "pushUpdateRejected", 1 },
|
2022-03-15 04:49:40 +03:00
|
|
|
[ADVICE_RESET_NO_REFRESH_WARNING] = { "resetNoRefresh", 1 },
|
2020-03-02 23:01:59 +03:00
|
|
|
[ADVICE_RESOLVE_CONFLICT] = { "resolveConflict", 1 },
|
|
|
|
[ADVICE_RM_HINTS] = { "rmHints", 1 },
|
|
|
|
[ADVICE_SEQUENCER_IN_USE] = { "sequencerInUse", 1 },
|
|
|
|
[ADVICE_SET_UPSTREAM_FAILURE] = { "setUpstreamFailure", 1 },
|
2021-08-31 00:46:02 +03:00
|
|
|
[ADVICE_SKIPPED_CHERRY_PICKS] = { "skippedCherryPicks", 1 },
|
2020-03-02 23:01:59 +03:00
|
|
|
[ADVICE_STATUS_AHEAD_BEHIND_WARNING] = { "statusAheadBehindWarning", 1 },
|
|
|
|
[ADVICE_STATUS_HINTS] = { "statusHints", 1 },
|
|
|
|
[ADVICE_STATUS_U_OPTION] = { "statusUoption", 1 },
|
|
|
|
[ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE] = { "submoduleAlternateErrorStrategyDie", 1 },
|
branch: add --recurse-submodules option for branch creation
To improve the submodules UX, we would like to teach Git to handle
branches in submodules. Start this process by teaching "git branch" the
--recurse-submodules option so that "git branch --recurse-submodules
topic" will create the `topic` branch in the superproject and its
submodules.
Although this commit does not introduce breaking changes, it does not
work well with existing --recurse-submodules commands because "git
branch --recurse-submodules" writes to the submodule ref store, but most
commands only consider the superproject gitlink and ignore the submodule
ref store. For example, "git checkout --recurse-submodules" will check
out the commits in the superproject gitlinks (and put the submodules in
detached HEAD) instead of checking out the submodule branches.
Because of this, this commit introduces a new configuration value,
`submodule.propagateBranches`. The plan is for Git commands to
prioritize submodule ref store information over superproject gitlinks if
this value is true. Because "git branch --recurse-submodules" writes to
submodule ref stores, for the sake of clarity, it will not function
unless this configuration value is set.
This commit also includes changes that support working with submodules
from a superproject commit because "branch --recurse-submodules" (and
future commands) need to read .gitmodules and gitlinks from the
superproject commit, but submodules are typically read from the
filesystem's .gitmodules and the index's gitlinks. These changes are:
* add a submodules_of_tree() helper that gives the relevant
information of an in-tree submodule (e.g. path and oid) and
initializes the repository
* add is_tree_submodule_active() by adding a treeish_name parameter to
is_submodule_active()
* add the "submoduleNotUpdated" advice to advise users to update the
submodules in their trees
Incidentally, fix an incorrect usage string that combined the 'list'
usage of git branch (-l) with the 'create' usage; this string has been
incorrect since its inception, a8dfd5eac4 (Make builtin-branch.c use
parse_options., 2007-10-07).
Helped-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Glen Choo <chooglen@google.com>
Reviewed-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-01-29 03:04:45 +03:00
|
|
|
[ADVICE_SUBMODULES_NOT_UPDATED] = { "submodulesNotUpdated", 1 },
|
2021-04-08 23:41:27 +03:00
|
|
|
[ADVICE_UPDATE_SPARSE_PATH] = { "updateSparsePath", 1 },
|
2020-03-02 23:01:59 +03:00
|
|
|
[ADVICE_WAITING_FOR_EDITOR] = { "waitingForEditor", 1 },
|
|
|
|
};
|
|
|
|
|
|
|
|
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');
|
2018-04-21 13:10:00 +03:00
|
|
|
fprintf(stderr, _("%shint: %.*s%s\n"),
|
|
|
|
advise_get_color(ADVICE_COLOR_HINT),
|
|
|
|
(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)
|
|
|
|
{
|
|
|
|
switch(type) {
|
|
|
|
case ADVICE_PUSH_UPDATE_REJECTED:
|
|
|
|
return advice_setting[ADVICE_PUSH_UPDATE_REJECTED].enabled &&
|
|
|
|
advice_setting[ADVICE_PUSH_UPDATE_REJECTED_ALIAS].enabled;
|
|
|
|
default:
|
|
|
|
return advice_setting[type].enabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void advise_if_enabled(enum advice_type type, const char *advice, ...)
|
|
|
|
{
|
|
|
|
va_list params;
|
|
|
|
|
|
|
|
if (!advice_enabled(type))
|
|
|
|
return;
|
|
|
|
|
|
|
|
va_start(params, advice);
|
|
|
|
vadvise(advice, 1, 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;
|
|
|
|
advice_setting[i].enabled = git_config_bool(var, value);
|
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."));
|
|
|
|
else
|
|
|
|
error(_("It is not possible to %s because you have unmerged files."),
|
|
|
|
me);
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|