git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/5] read-cache: update add_files_to_cache take param include_ignored_submodules

From
CGClaus Schneider(Eficode) via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 13, 2025, 18:10 UTC
Message-ID
<5796009122c6ab573a2961db598bbd33727a6ac0.1763057433.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1987.v2.git.1763057433.gitgitgadget@gmail.com>
From: "Claus Schneider(Eficode)" <claus.schneider@eficode.com>

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>
---
 builtin/add.c      |  4 +++-
 builtin/checkout.c |  2 +-
 builtin/commit.c   |  2 +-
 read-cache-ll.h    |  2 +-
 read-cache.c       | 51 ++++++++++++++++++++++++++++++++++++++++++++--
 5 files changed, 55 insertions(+), 6 deletions(-)
diff --git a/builtin/add.c b/builtin/add.c
index 0235854f80..6d11382f33 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -233,6 +233,7 @@ N_("The following paths are ignored by one of your .gitignore files:\n");
 static int verbose, show_only, ignored_too, refresh_only;
 static int ignore_add_errors, intent_to_add, ignore_missing;
 static int warn_on_embedded_repo = 1;
+static int include_ignored_submodules;
 
 #define ADDREMOVE_DEFAULT 1
 static int addremove = ADDREMOVE_DEFAULT;
@@ -271,6 +272,7 @@ static struct option builtin_add_options[] = {
 	OPT_BOOL( 0 , "ignore-errors", &ignore_add_errors, N_("just skip files which cannot be added because of errors")),
 	OPT_BOOL( 0 , "ignore-missing", &ignore_missing, N_("check if - even missing - files are ignored in dry run")),
 	OPT_BOOL(0, "sparse", &include_sparse, N_("allow updating entries outside of the sparse-checkout cone")),
+    OPT_BOOL(0, "include-ignored-submodules", &include_ignored_submodules, N_("add submodules even if they has configuration ignore=all")),
 	OPT_STRING(0, "chmod", &chmod_arg, "(+|-)x",
 		   N_("override the executable bit of the listed files")),
 	OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
@@ -582,7 +584,7 @@ int cmd_add(int argc,
 	else
 		exit_status |= add_files_to_cache(repo, prefix,
 						  &pathspec, ps_matched,
-						  include_sparse, flags);
+						  include_sparse, flags, include_ignored_submodules);
 
 	if (take_worktree_changes && !add_renormalize && !ignore_add_errors &&
 	    report_path_error(ps_matched, &pathspec))
diff --git a/builtin/checkout.c b/builtin/checkout.c
index f9453473fe..b2a404051d 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -899,7 +899,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
 			 */
 
 			add_files_to_cache(the_repository, NULL, NULL, NULL, 0,
-					   0);
+					   0, 0 );
 			init_ui_merge_options(&o, the_repository);
 			o.verbosity = 0;
 			work = write_in_core_index_as_tree(the_repository);
diff --git a/builtin/commit.c b/builtin/commit.c
index b5b9608813..5bf7ae5fc1 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -455,7 +455,7 @@ static const char *prepare_index(const char **argv, const char *prefix,
 		repo_hold_locked_index(the_repository, &index_lock,
 				       LOCK_DIE_ON_ERROR);
 		add_files_to_cache(the_repository, also ? prefix : NULL,
-				   &pathspec, ps_matched, 0, 0);
+				   &pathspec, ps_matched, 0, 0, 0 );
 		if (!all && report_path_error(ps_matched, &pathspec))
 			exit(128);
 
diff --git a/read-cache-ll.h b/read-cache-ll.h
index 71b49d9af4..2c8b4b21b1 100644
--- a/read-cache-ll.h
+++ b/read-cache-ll.h
@@ -481,7 +481,7 @@ int cmp_cache_name_compare(const void *a_, const void *b_);
 
 int add_files_to_cache(struct repository *repo, const char *prefix,
 		       const struct pathspec *pathspec, char *ps_matched,
-		       int include_sparse, int flags);
+		       int include_sparse, int flags, int ignored_too );
 
 void overlay_tree_on_index(struct index_state *istate,
 			   const char *tree_name, const char *prefix);
diff --git a/read-cache.c b/read-cache.c
index 06ad74db22..32f32bdb4c 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -3880,9 +3880,12 @@ void overlay_tree_on_index(struct index_state *istate,
 
 struct update_callback_data {
 	struct index_state *index;
+	struct repository *repo;
+	struct pathspec *pathspec;
 	int include_sparse;
 	int flags;
 	int add_errors;
+	int include_ignored_submodules;
 };
 
 static int fix_unmerged_status(struct diff_filepair *p,
@@ -3924,7 +3927,48 @@ static void update_callback(struct diff_queue_struct *q,
 		default:
 			die(_("unexpected diff status %c"), p->status);
 		case DIFF_STATUS_MODIFIED:
-		case DIFF_STATUS_TYPE_CHANGED:
+		case DIFF_STATUS_TYPE_CHANGED: {
+			struct stat st;
+			if (!lstat(path, &st) && S_ISDIR(st.st_mode)) { // only consider submodule if it is a directory
+				const struct submodule *sub = submodule_from_path(data->repo, null_oid(the_hash_algo), path);
+				if (sub && sub->name && sub->ignore && !strcmp(sub->ignore, "all")) {
+					int pathspec_matches = 0;
+					char *norm_pathspec = NULL;
+					int ps_i;
+					trace_printf("ignore=all %s\n", path);
+					trace_printf("pathspec %s\n",
+							(data->pathspec && data->pathspec->nr) ? "has pathspec" : "no pathspec");
+					/* Safely scan all pathspec items (q->nr may exceed pathspec->nr). */
+					if (data->pathspec) {
+						for (ps_i = 0; ps_i < data->pathspec->nr; ps_i++) {
+							const char *m = data->pathspec->items[ps_i].match;
+							if (!m)
+								continue;
+							norm_pathspec = xstrdup(m);
+							strip_dir_trailing_slashes(norm_pathspec);
+							if (!strcmp(path, norm_pathspec)) {
+								pathspec_matches = 1;
+								FREE_AND_NULL(norm_pathspec);
+								break;
+							}
+							FREE_AND_NULL(norm_pathspec);
+						}
+					}
+					if (pathspec_matches) {
+						if (data->include_ignored_submodules && data->include_ignored_submodules > 0) {
+							trace_printf("Add ignored=all submodule due to --include_ignored_submodules: %s\n", path);
+						} else {
+							printf(_("Skipping submodule due to ignore=all: %s"), path);
+							printf(_("Use --include_ignored_submodules, if you really want to add them.") );
+							continue;
+						}
+					} else {
+						/* No explicit pathspec match -> skip silently (or with trace). */
+						trace_printf("pathspec does not match %s\n", path);
+						continue;
+					}
+				}
+			}
 			if (add_file_to_index(data->index, path, data->flags)) {
 				if (!(data->flags & ADD_CACHE_IGNORE_ERRORS))
 					die(_("updating files failed"));
@@ -3945,7 +3989,7 @@ static void update_callback(struct diff_queue_struct *q,
 
 int add_files_to_cache(struct repository *repo, const char *prefix,
 		       const struct pathspec *pathspec, char *ps_matched,
-		       int include_sparse, int flags)
+		       int include_sparse, int flags, int include_ignored_submodules )
 {
 	struct update_callback_data data;
 	struct rev_info rev;
@@ -3954,6 +3998,9 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
 	data.index = repo->index;
 	data.include_sparse = include_sparse;
 	data.flags = flags;
+	data.repo = repo;
+	data.include_ignored_submodules = include_ignored_submodules;
+	data.pathspec = (struct pathspec *)pathspec;
 
 	repo_init_revisions(repo, &rev, prefix);
 	setup_revisions(0, NULL, &rev, NULL);
-- 
gitgitgadget
Previous: Claus Schneider via GitGitGadgetNext: Junio C Hamano
Message 9 of 43 in “git-add : Respect submodule ignore=all and only add changes with --force”
  1. 0/5 git-add : Respect submodule ignore=all and only add changes with --forceClaus Schneider via GitGitGadget, Oct 18, 2025
  2. 1/5 read-cache: update add_files_to_cache to take param ignored_too(--force)Claus Schneider(Eficode) via GitGitGadget, Oct 18, 2025
  3. 2/5 read-cache: let read-cache respect submodule ignore=all and --forceClaus Schneider(Eficode) via GitGitGadget, Oct 18, 2025
  4. 3/5 tests: add new t2206-add-submodule-ignored.sh to test ignore=all scenarioClaus Schneider(Eficode) via GitGitGadget, Oct 18, 2025
  5. 4/5 tests: fix existing tests when add an ignore=all submoduleClaus Schneider(Eficode) via GitGitGadget, Oct 18, 2025
  6. 5/5 Documentation: update add --force and submodule ignore=all configClaus Schneider(Eficode) via GitGitGadget, Oct 18, 2025
  7. Phillip WoodOct 19, 2025
  8. 0/5 git-add : Respect submodule ignore=all and only add changes with --forceClaus Schneider via GitGitGadget, Nov 13, 2025
  9. 1/5 read-cache: update add_files_to_cache take param include_ignored_submodulesClaus Schneider(Eficode) via GitGitGadget, Nov 13, 2025
  10. Junio C HamanoNov 13, 2025
  11. 2/5 read-cache: add/read-cache respect submodule ignore=allClaus Schneider(Eficode) via GitGitGadget, Nov 13, 2025
  12. 3/5 tests: add new t2206-add-submodule-ignored.sh to test ignore=all scenarioClaus Schneider(Eficode) via GitGitGadget, Nov 13, 2025
  13. 4/5 tests: fix existing tests when add an ignore=all submoduleClaus Schneider(Eficode) via GitGitGadget, Nov 13, 2025
  14. 5/5 Documentation: add --include_ignored_submodules + ignore=all configClaus Schneider(Eficode) via GitGitGadget, Nov 13, 2025
  15. Junio C HamanoNov 13, 2025
  16. Claus SchneiderNov 14, 2025
  17. Claus SchneiderFeb 5, 2026
  18. Junio C HamanoFeb 5, 2026
  19. 0/5 git-add: Skip submodules with ignore=all unless --force and explicit path usedClaus Schneider via GitGitGadget, Jan 14, 2026
  20. 1/5 read-cache: update add_files_to_cache take param ignored_tooClaus Schneider(Eficode) via GitGitGadget, Jan 14, 2026
  21. 2/5 read-cache: submodule add need --force given ignore=all configurationClaus Schneider(Eficode) via GitGitGadget, Jan 14, 2026
  22. Kristoffer HaugsbakkJan 15, 2026
  23. Claus SchneiderJan 16, 2026
  24. 3/5 tests: t2206-add-submodule-ignored: ignore=all and add --force testsClaus Schneider(Eficode) via GitGitGadget, Jan 14, 2026
  25. 4/5 tests: fix existing tests when add an ignore=all submoduleClaus Schneider(Eficode) via GitGitGadget, Jan 14, 2026
  26. 5/5 Documentation: update add --force option + ignore=all configClaus Schneider(Eficode) via GitGitGadget, Jan 14, 2026
  27. Ben KnobleJan 14, 2026
  28. Claus SchneiderJan 16, 2026
  29. 0/5 git-add: Skip submodules with ignore=all unless --force and explicit path usedClaus Schneider via GitGitGadget, Feb 6, 2026
  30. 1/5 read-cache: update add_files_to_cache take param ignored_tooClaus Schneider(Eficode) via GitGitGadget, Feb 6, 2026
  31. Junio C HamanoFeb 9, 2026
  32. Junio C HamanoFeb 9, 2026
  33. 2/5 read-cache: submodule add need --force given ignore=all configurationClaus Schneider(Eficode) via GitGitGadget, Feb 6, 2026
  34. 3/5 tests: t2206-add-submodule-ignored: ignore=all and add --force testsClaus Schneider(Eficode) via GitGitGadget, Feb 6, 2026
  35. 4/5 tests: fix existing tests when add an ignore=all submoduleClaus Schneider(Eficode) via GitGitGadget, Feb 6, 2026
  36. 5/5 Documentation: update add --force option + ignore=all configClaus Schneider(Eficode) via GitGitGadget, Feb 6, 2026
  37. Kristoffer HaugsbakkMar 4, 2026
  38. Claus SchneiderMar 10, 2026
  39. Claus SchneiderMar 10, 2026
  40. Junio C HamanoFeb 20, 2026
  41. Claus SchneiderOct 20, 2025
  42. Phillip WoodOct 24, 2025
  43. Claus SchneiderNov 13, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.