From: "Philippe Blain via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Brandon Williams <bmwill@google.com>,
Philippe Blain <levraiphilippeblain@gmail.com>,
Philippe Blain <levraiphilippeblain@gmail.com>
Subject: [PATCH] ls-files: respect 'submodule.recurse' config
Date: Thu, 10 Sep 2020 03:07:39 +0000 [thread overview]
Message-ID: <pull.732.git.1599707259907.gitgitgadget@gmail.com> (raw)
From: Philippe Blain <levraiphilippeblain@gmail.com>
`git ls-files` learned to recurse into submodules when given
'--recurse-submodules' back in e77aa336f1 (ls-files: optionally recurse
into submodules, 2016-10-07) but it does not respect the
'submodule.recurse' config option which was later introduced in
046b48239e (Introduce 'submodule.recurse' option for worktree
manipulators, 2017-05-31).
Add a 'git_ls_files_config' function to read this configuration
variable, and adjust the documentation and tests accordingly.
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
---
ls-files: respect 'submodule.recurse' config
This follows the approach of 121e43fa53 (pull: honor submodule.recurse
config option, 2017-09-06)
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-732%2Fphil-blain%2Fls-files-submodule.recurse-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-732/phil-blain/ls-files-submodule.recurse-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/732
Documentation/config/submodule.txt | 4 +--
builtin/ls-files.c | 16 ++++++++++-
t/t3007-ls-files-recurse-submodules.sh | 37 ++++++++++++++++++++++++++
3 files changed, 54 insertions(+), 3 deletions(-)
diff --git a/Documentation/config/submodule.txt b/Documentation/config/submodule.txt
index d7a63c8c12..9ba3adbf48 100644
--- a/Documentation/config/submodule.txt
+++ b/Documentation/config/submodule.txt
@@ -60,8 +60,8 @@ submodule.active::
submodule.recurse::
Specifies if commands recurse into submodules by default. This
applies to all commands that have a `--recurse-submodules` option
- (`checkout`, `fetch`, `grep`, `pull`, `push`, `read-tree`, `reset`,
- `restore` and `switch`) except `clone` and `ls-files`.
+ (`checkout`, `fetch`, `grep`, `ls-files`, `pull`, `push`, `read-tree`,
+ `reset`, `restore` and `switch`) except `clone` .
Defaults to false.
When set to true, it can be deactivated via the
`--no-recurse-submodules` option. Note that some Git commands
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index c8eae899b8..43c7c9bd62 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -512,6 +512,20 @@ static int option_parse_exclude_standard(const struct option *opt,
return 0;
}
+/**
+ * Read config variables.
+ */
+static int git_ls_files_config(const char *var, const char *value, void *cb)
+{
+ if (!strcmp(var, "submodule.recurse")) {
+ recurse_submodules = git_config_bool(var, value) ?
+ RECURSE_SUBMODULES_ON : RECURSE_SUBMODULES_OFF;
+ return 0;
+ }
+
+ return git_default_config(var, value, cb);
+}
+
int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
{
int require_work_tree = 0, show_tag = 0, i;
@@ -588,7 +602,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
prefix = cmd_prefix;
if (prefix)
prefix_len = strlen(prefix);
- git_config(git_default_config, NULL);
+ git_config(git_ls_files_config, NULL);
if (repo_read_index(the_repository) < 0)
die("index file corrupt");
diff --git a/t/t3007-ls-files-recurse-submodules.sh b/t/t3007-ls-files-recurse-submodules.sh
index 4a08000713..30c2c1e0bd 100755
--- a/t/t3007-ls-files-recurse-submodules.sh
+++ b/t/t3007-ls-files-recurse-submodules.sh
@@ -34,6 +34,43 @@ test_expect_success 'ls-files correctly outputs files in submodule' '
test_cmp expect actual
'
+test_expect_success 'ls-files respects submodule.recurse' '
+ cat >expect <<-\EOF &&
+ .gitmodules
+ a
+ b/b
+ submodule/c
+ EOF
+
+ git -c submodule.recurse ls-files >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '--[no-]recurse-submodule and submodule.recurse' '
+ cat >expect-recurse <<-\EOF &&
+ .gitmodules
+ a
+ b/b
+ submodule/c
+ EOF
+
+ cat >expect-no-recurse <<-\EOF &&
+ .gitmodules
+ a
+ b/b
+ submodule
+ EOF
+
+ git -c submodule.recurse ls-files --no-recurse-submodules >actual &&
+ test_cmp expect-no-recurse actual &&
+ git -c submodule.recurse=false ls-files --recurse-submodules >actual &&
+ test_cmp expect-recurse actual &&
+ git -c submodule.recurse=false ls-files --no-recurse-submodules >actual &&
+ test_cmp expect-no-recurse actual &&
+ git -c submodule.recurse ls-files --recurse-submodules >actual &&
+ test_cmp expect-recurse actual
+'
+
test_expect_success 'ls-files correctly outputs files in submodule with -z' '
lf_to_nul >expect <<-\EOF &&
.gitmodules
base-commit: e19713638985533ce461db072b49112da5bd2042
--
gitgitgadget
next reply other threads:[~2020-09-10 3:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-10 3:07 Philippe Blain via GitGitGadget [this message]
2020-09-10 4:25 ` [PATCH] ls-files: respect 'submodule.recurse' config Junio C Hamano
2020-09-10 4:50 ` Junio C Hamano
2020-09-11 13:11 ` Philippe Blain
2020-09-11 14:30 ` Philippe Blain
2020-09-11 13:05 ` Philippe Blain
2020-09-11 19:19 ` Junio C Hamano
2020-09-13 10:47 ` Đoàn Trần Công Danh
2020-09-13 10:51 ` Đoàn Trần Công Danh
2020-09-11 13:48 ` Philippe Blain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.732.git.1599707259907.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=bmwill@google.com \
--cc=git@vger.kernel.org \
--cc=levraiphilippeblain@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).