Skip to content

Commit fa7cf4e

Browse files
committed
read-cache: let read-cache respect submodule ignore=all and bypass with --force
The submomodule path reference update is skipped if: - the ignore=all configuration is set on the submodule unless: - the --force option is also given and the submodule path is explicit given. A message is printed (like ignored files) guilding the user to use the --force flag if the user has explicitely want to update the submodule reference. Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
1 parent ddddd25 commit fa7cf4e

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

read-cache.c

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
#include "csum-file.h"
4949
#include "promisor-remote.h"
5050
#include "hook.h"
51+
#include "submodule.h"
52+
#include "submodule-config.h"
5153

5254
/* Mask for the name length in ce_flags in the on-disk index */
5355

@@ -3927,13 +3929,54 @@ static void update_callback(struct diff_queue_struct *q,
39273929
default:
39283930
die(_("unexpected diff status %c"), p->status);
39293931
case DIFF_STATUS_MODIFIED:
3930-
case DIFF_STATUS_TYPE_CHANGED:
3932+
case DIFF_STATUS_TYPE_CHANGED: {
3933+
const struct submodule *sub = submodule_from_path(data->repo, null_oid(the_hash_algo), path);
3934+
if (sub && sub->name && sub->ignore && !strcmp(sub->ignore, "all")) {
3935+
int pathspec_matches = 0;
3936+
char *norm_pathspec = NULL;
3937+
int ps_i;
3938+
trace_printf("ignore=all %s\n", path);
3939+
trace_printf("pathspec %s\n",
3940+
(data->pathspec && data->pathspec->nr) ? "has pathspec" : "no pathspec");
3941+
/* Safely scan all pathspec items (q->nr may exceed pathspec->nr). */
3942+
if (data->pathspec) {
3943+
for (ps_i = 0; ps_i < data->pathspec->nr; ps_i++) {
3944+
const char *m = data->pathspec->items[ps_i].match;
3945+
if (!m)
3946+
continue;
3947+
norm_pathspec = xstrdup(m);
3948+
strip_dir_trailing_slashes(norm_pathspec);
3949+
if (!strcmp(path, norm_pathspec)) {
3950+
pathspec_matches = 1;
3951+
free(norm_pathspec);
3952+
norm_pathspec = NULL;
3953+
break;
3954+
}
3955+
free(norm_pathspec);
3956+
norm_pathspec = NULL;
3957+
}
3958+
}
3959+
if (pathspec_matches) {
3960+
if (data->ignored_too && data->ignored_too > 0) {
3961+
trace_printf("Forcing add of submodule ignored=all due to --force: %s\n", path);
3962+
} else {
3963+
printf(_("Skipping submodule due to ignore=all: %s"), path);
3964+
printf(_("Use -f if you really want to add them.") );
3965+
continue;
3966+
}
3967+
} else {
3968+
/* No explicit pathspec match -> skip silently (or with trace). */
3969+
trace_printf("pathspec does not match %s\n", path);
3970+
continue;
3971+
}
3972+
}
39313973
if (add_file_to_index(data->index, path, data->flags)) {
39323974
if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
39333975
die(_("updating files failed"));
39343976
data->add_errors++;
39353977
}
39363978
break;
3979+
}
39373980
case DIFF_STATUS_DELETED:
39383981
if (data->flags & ADD_CACHE_IGNORE_REMOVAL)
39393982
break;

0 commit comments

Comments
 (0)