summaryrefslogtreecommitdiff
path: root/advice.c
diff options
context:
space:
mode:
authorMatheus Tavares <matheus.bernardino@usp.br>2021-04-08 20:41:27 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-04-08 21:18:03 (GMT)
commita20f70478ffcc66d30936920ebcc35ebfc12a7c7 (patch)
tree1e5865434bde7d8f5a94bb6f93ba304df307bd4c /advice.c
parentb243012cb39e2151ffae96bded2387751d876d12 (diff)
downloadgit-a20f70478ffcc66d30936920ebcc35ebfc12a7c7.zip
git-a20f70478ffcc66d30936920ebcc35ebfc12a7c7.tar.gz
git-a20f70478ffcc66d30936920ebcc35ebfc12a7c7.tar.bz2
add: warn when asked to update SKIP_WORKTREE entries
`git add` already refrains from updating SKIP_WORKTREE entries, but it silently exits with zero code when it is asked to do so. Instead, let's warn the user and display a hint on how to update these entries. Note that we only warn the user whey they give a pathspec item that matches no eligible path for updating, but it does match one or more SKIP_WORKTREE entries. A warning was chosen over erroring out right away to reproduce the same behavior `add` already exhibits with ignored files. This also allow users to continue their workflow without having to invoke `add` again with only the eligible paths (as those will have already been added). Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'advice.c')
-rw-r--r--advice.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/advice.c b/advice.c
index 1647423..0b9c89c 100644
--- a/advice.c
+++ b/advice.c
@@ -2,6 +2,7 @@
#include "config.h"
#include "color.h"
#include "help.h"
+#include "string-list.h"
int advice_fetch_show_forced_updates = 1;
int advice_push_update_rejected = 1;
@@ -136,6 +137,7 @@ static struct {
[ADVICE_STATUS_HINTS] = { "statusHints", 1 },
[ADVICE_STATUS_U_OPTION] = { "statusUoption", 1 },
[ADVICE_SUBMODULE_ALTERNATE_ERROR_STRATEGY_DIE] = { "submoduleAlternateErrorStrategyDie", 1 },
+ [ADVICE_UPDATE_SPARSE_PATH] = { "updateSparsePath", 1 },
[ADVICE_WAITING_FOR_EDITOR] = { "waitingForEditor", 1 },
};
@@ -284,6 +286,24 @@ void NORETURN die_conclude_merge(void)
die(_("Exiting because of unfinished merge."));
}
+void advise_on_updating_sparse_paths(struct string_list *pathspec_list)
+{
+ struct string_list_item *item;
+
+ if (!pathspec_list->nr)
+ return;
+
+ fprintf(stderr, _("The following pathspecs didn't match any"
+ " eligible path, but they do match index\n"
+ "entries outside the current sparse checkout:\n"));
+ for_each_string_list_item(item, pathspec_list)
+ fprintf(stderr, "%s\n", item->string);
+
+ advise_if_enabled(ADVICE_UPDATE_SPARSE_PATH,
+ _("Disable or modify the sparsity rules if you intend"
+ " to update such entries."));
+}
+
void detach_advice(const char *new_name)
{
const char *fmt =