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

Re: Request feature: –no-submodule

From
Taylor Blau <me@ttaylorr.com>
Date
Jun 2, 2021, 20:31 UTC
Message-ID
<YLfqiLbpPXWXHlBi@nand.local>
In-Reply-To
<c5709df6-c357-56b4-f0e0-673bc8b4e668@gmail.com>
On Wed, Jun 02, 2021 at 01:31:11PM +0300, Ilias Apostolou wrote:
Show 6 quoted lines
> Hello Git community.
>
> As you already know, git ls-files command lists all of the tracked files,
> but submodule names are included.
>
> My team would like a –no-submodule switch to exclude those.

In all honesty, though this seems like a niche request for ls-files to fulfill, ls-files already has quite the collection of options, so I wouldn't be sad to see it learn how to do this, too.

The change boils down to having builtin/ls-files.c:show_ce() avoid printing out submoudles in when '--exclude-submoudles' is given). Something like this:

--- >8 ---
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index 45cc3b23dd..09d76fd068 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -35,6 +35,7 @@ static int show_fsmonitor_bit;
 static int line_terminator = '\n';
 static int debug_mode;
 static int show_eol;
+static int exclude_submodules;
 static int recurse_submodules;
 static int skipping_duplicates;

@@ -230,6 +231,9 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,
 	if (max_prefix_len > strlen(fullname))
 		die("git ls-files: internal error - cache entry not superset of prefix");

+	if (exclude_submodules && S_ISGITLINK(ce->ce_mode))
+		return;
+
 	if (recurse_submodules && S_ISGITLINK(ce->ce_mode) &&
 	    is_submodule_active(repo, ce->name)) {
 		show_submodule(repo, dir, ce->name);
@@ -662,6 +666,8 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
 		OPT_SET_INT_F(0, "full-name", &prefix_len,
 			      N_("make the output relative to the project top directory"),
 			      0, PARSE_OPT_NONEG),
+		OPT_BOOL(0, "exclude-submodules", &exclude_submodules,
+			N_("avoid showing submodules altogether")),
 		OPT_BOOL(0, "recurse-submodules", &recurse_submodules,
 			N_("recurse through submodules")),
 		OPT_BOOL(0, "error-unmatch", &error_unmatch,

--- 8< ---

I'll leave it at that to decide if others think this is a good idea or
not.

Thanks,
Taylor
Previous: Ilias ApostolouNext: Junio C Hamano
Message 2 of 12 in “Request feature: –no-submodule”
  1. Ilias ApostolouJun 2, 2021
  2. Taylor BlauJun 2, 2021
  3. Junio C HamanoJun 3, 2021
  4. Taylor BlauJun 3, 2021
  5. Ilias ApostolouJun 3, 2021
  6. Junio C HamanoJun 3, 2021
  7. Junio C HamanoJun 3, 2021
  8. Jeff KingJun 3, 2021
  9. Junio C HamanoJun 3, 2021
  10. Jeff KingJun 4, 2021
  11. Junio C HamanoJun 4, 2021
  12. Ilias ApostolouJun 5, 2021

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.