Skip to content

Commit 5796009

Browse files
committed
read-cache: update add_files_to_cache take param include_ignored_submodules
The include_ignored_submodules parameter is added to the function add_files_to_cache for usage of explicit updating the index for the updated submodule using the explicit patchspec to the submodule. Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
1 parent 81f86aa commit 5796009

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed

builtin/add.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ N_("The following paths are ignored by one of your .gitignore files:\n");
233233
static int verbose, show_only, ignored_too, refresh_only;
234234
static int ignore_add_errors, intent_to_add, ignore_missing;
235235
static int warn_on_embedded_repo = 1;
236+
static int include_ignored_submodules;
236237

237238
#define ADDREMOVE_DEFAULT 1
238239
static int addremove = ADDREMOVE_DEFAULT;
@@ -271,6 +272,7 @@ static struct option builtin_add_options[] = {
271272
OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
272273
OPT_BOOL( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")),
273274
OPT_BOOL(0, "sparse", &include_sparse, N_("allow updating entries outside of the sparse-checkout cone")),
275+
OPT_BOOL(0, "include-ignored-submodules", &include_ignored_submodules, N_("add submodules even if they has configuration ignore=all")),
274276
OPT_STRING(0, "chmod", &chmod_arg, "(+|-)x",
275277
N_("override the executable bit of the listed files")),
276278
OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
@@ -582,7 +584,7 @@ int cmd_add(int argc,
582584
else
583585
exit_status |= add_files_to_cache(repo, prefix,
584586
&pathspec, ps_matched,
585-
include_sparse, flags);
587+
include_sparse, flags, include_ignored_submodules);
586588

587589
if (take_worktree_changes && !add_renormalize && !ignore_add_errors &&
588590
report_path_error(ps_matched, &pathspec))

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
899899
*/
900900

901901
add_files_to_cache(the_repository, NULL, NULL, NULL, 0,
902-
0);
902+
0, 0 );
903903
init_ui_merge_options(&o, the_repository);
904904
o.verbosity = 0;
905905
work = write_in_core_index_as_tree(the_repository);

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
455455
repo_hold_locked_index(the_repository, &index_lock,
456456
LOCK_DIE_ON_ERROR);
457457
add_files_to_cache(the_repository, also ? prefix : NULL,
458-
&pathspec, ps_matched, 0, 0);
458+
&pathspec, ps_matched, 0, 0, 0 );
459459
if (!all && report_path_error(ps_matched, &pathspec))
460460
exit(128);
461461

read-cache-ll.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ int cmp_cache_name_compare(const void *a_, const void *b_);
481481

482482
int add_files_to_cache(struct repository *repo, const char *prefix,
483483
const struct pathspec *pathspec, char *ps_matched,
484-
int include_sparse, int flags);
484+
int include_sparse, int flags, int ignored_too );
485485

486486
void overlay_tree_on_index(struct index_state *istate,
487487
const char *tree_name, const char *prefix);

read-cache.c

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3880,9 +3880,12 @@ void overlay_tree_on_index(struct index_state *istate,
38803880

38813881
struct update_callback_data {
38823882
struct index_state *index;
3883+
struct repository *repo;
3884+
struct pathspec *pathspec;
38833885
int include_sparse;
38843886
int flags;
38853887
int add_errors;
3888+
int include_ignored_submodules;
38863889
};
38873890

38883891
static int fix_unmerged_status(struct diff_filepair *p,
@@ -3924,7 +3927,48 @@ static void update_callback(struct diff_queue_struct *q,
39243927
default:
39253928
die(_("unexpected diff status %c"), p->status);
39263929
case DIFF_STATUS_MODIFIED:
3927-
case DIFF_STATUS_TYPE_CHANGED:
3930+
case DIFF_STATUS_TYPE_CHANGED: {
3931+
struct stat st;
3932+
if (!lstat(path, &st) && S_ISDIR(st.st_mode)) { // only consider submodule if it is a directory
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_AND_NULL(norm_pathspec);
3952+
break;
3953+
}
3954+
FREE_AND_NULL(norm_pathspec);
3955+
}
3956+
}
3957+
if (pathspec_matches) {
3958+
if (data->include_ignored_submodules && data->include_ignored_submodules > 0) {
3959+
trace_printf("Add ignored=all submodule due to --include_ignored_submodules: %s\n", path);
3960+
} else {
3961+
printf(_("Skipping submodule due to ignore=all: %s"), path);
3962+
printf(_("Use --include_ignored_submodules, if you really want to add them.") );
3963+
continue;
3964+
}
3965+
} else {
3966+
/* No explicit pathspec match -> skip silently (or with trace). */
3967+
trace_printf("pathspec does not match %s\n", path);
3968+
continue;
3969+
}
3970+
}
3971+
}
39283972
if (add_file_to_index(data->index, path, data->flags)) {
39293973
if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
39303974
die(_("updating files failed"));
@@ -3945,7 +3989,7 @@ static void update_callback(struct diff_queue_struct *q,
39453989

39463990
int add_files_to_cache(struct repository *repo, const char *prefix,
39473991
const struct pathspec *pathspec, char *ps_matched,
3948-
int include_sparse, int flags)
3992+
int include_sparse, int flags, int include_ignored_submodules )
39493993
{
39503994
struct update_callback_data data;
39513995
struct rev_info rev;
@@ -3954,6 +3998,9 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
39543998
data.index = repo->index;
39553999
data.include_sparse = include_sparse;
39564000
data.flags = flags;
4001+
data.repo = repo;
4002+
data.include_ignored_submodules = include_ignored_submodules;
4003+
data.pathspec = (struct pathspec *)pathspec;
39574004

39584005
repo_init_revisions(repo, &rev, prefix);
39594006
setup_revisions(0, NULL, &rev, NULL);

0 commit comments

Comments
 (0)