-
Notifications
You must be signed in to change notification settings - Fork 157
git-add : Respect submodule ignore=all and only add changes with --force <path> #1987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Welcome to GitGitGadgetHi @bicschneider, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests. Please make sure that either:
You can CC potential reviewers by adding a footer to the PR description with the following syntax: NOTE: DO NOT copy/paste your CC list from a previous GGG PR's description, Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:
It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code. Contributing the patchesBefore you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form Both the person who commented An alternative is the channel Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment If you want to see what email(s) would be sent for a After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions (while the comments and suggestions will be mirrored into the PR by GitGitGadget, you will still want to reply via mail). If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox from the Git mailing list archive (click the curl -g --user "<EMailAddress>:<Password>" \
--url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txtTo iterate on your change, i.e. send a revised patch or patch series, you will first want to (force-)push to the same branch. You probably also want to modify your Pull Request description (or title). It is a good idea to summarize the revision by adding something like this to the cover letter (read: by editing the first comment on the PR, i.e. the PR description): To send a new iteration, just add another PR comment with the contents: Need help?New contributors who want advice are encouraged to join git-mentoring@googlegroups.com, where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join. You may also be able to find help in real time in the developer IRC channel, |
|
There are issues in commit a3105e7: |
|
There are issues in commit b2d5354: |
|
There are issues in commit 8348a4a: |
|
There are issues in commit 6657438: |
|
There are issues in commit c2d703e: |
|
There are issues in commit a56d8b8: |
|
There are issues in commit 79598c6: |
|
There are issues in commit 1b8d93b: |
|
There are issues in commit e45daed: |
|
/allow |
|
User bicschneider is now allowed to use GitGitGadget. WARNING: bicschneider has no public email address set on GitHub; GitGitGadget needs an email address to Cc: you on your contribution, so that you receive any feedback on the Git mailing list. Go to https://github.com/settings/profile to make your preferred email public to let GitGitGadget know which email address to use. |
|
@bicschneider the Git project is very particular about the form of the commit messages it accepts, and it is outright hostile towards contributors who send patches that introduce white-space problems even if those are fixed by later patches in the same patch series (they demand that the fixes are squashed into the appropriate patches, which I recommend you do before Further, they are adamant about the Finally, you can increase the chances for a pleasant review on the Git mailing list dramatically by imitating the rather verbose style of Git's own commit messages. There is some really useful guidance here, in particular the part where it recommends to ensure that the following are covered by the commit message:
|
e45daed to
d94d2d5
Compare
|
There are issues in commit fa7cf4e: |
|
There are issues in commit 78c6a1a: |
|
There are issues in commit d94d2d5: |
ee01742 to
cd3e2a3
Compare
|
@bicschneider you needn't worry about the |
80907de to
416695f
Compare
|
/allow |
|
User bicschneider already allowed to use GitGitGadget. |
|
/preview |
|
Preview email sent as pull.1987.git.1760817159.gitgitgadget@gmail.com |
|
/submit |
|
Submitted as pull.1987.git.1760818039.gitgitgadget@gmail.com To fetch this version into To fetch this version to local tag |
416695f to
3167309
Compare
|
On the Git mailing list, Phillip Wood wrote (reply to this): Hi Claus
[I've adjusted the CC list slightly]
On 18/10/2025 21:07, Claus Schneider via GitGitGadget wrote:
> The feature of configuring a submodule to "ignore=all" is nicely respected
> in commands "status" and "diff". However the "add" command does not respect
> the configuration the same way.
I was curious why, when "git add" uses the same machinery as "git diff" to figure out which paths need updating, it behaves differently. It turns out that add_files_to_cache() contains
rev.diffopt.flags.override_submodule_config = 1;
which makes "git add" ignore "submodule.<name>.ignore". Tracing the history of this line, it originates from 5556808690e (add, reset: ensure submodules can be added or reset, 2017-07-25) which made a deliberate choice for both "git add" and "git reset" not to behave like "git diff". If we're going to change the behavior then it would be helpful to explain how this patch series ameliorates the concerns that lead to that commit and why it is sensible to change the behavior of "git add" but not "git reset". It also suggests that a much simpler way of implementing the change would be to delete that line.
I'm not convinced that the approach of using "--force" is a good idea as it conflates ignoring changes to tracked paths (which is what submodule.<name>.ignore" does) with ignoring untracked paths (which is what ".gitignore" does). If we're happy to break existing uses that rely on the current behavior then having a new option to override submodule.<name>.ignore strikes me as a better way forward. I don't have much experience of using submodules so I can't comment on whether changing the behavior is a good idea or not.
Thanks
Phillip
The behavior is problematic for the logic
> between status/diff and add. Secondly it makes it problematic to track
> branches in the submodule configuration as developers unintentionally keeps
> add submodule updates and get conflicts for no intentional reason. Both adds
> unnecessary friction to the usage of submodules.
> > The patches implement the same logical behavior for ignore=all submodules as
> regular ignored files. The status now does not show any diff - nor will the
> add command update the reference submodule reference. If you add the
> submodule path which is ignore=all then you are presented with a message
> that you need to use the --force option. The branch=, ignore=all (and
> update=none) now works great with update --remote, but developers does not
> have to consider changes in the updates of the submodule sha1. The
> implementation removes a friction of working with submodules and can be used
> like the repo tool with branches configured. The submodule status report
> could be used for build/release documentation for reproduction of a setup.
> > A few tests used the adding of submodules without --force, hence they have
> been updated to use the --force option.
> > Claus Schneider(Eficode) (5):
> read-cache: update add_files_to_cache to take param
> ignored_too(--force)
> read-cache: let read-cache respect submodule ignore=all and --force
> tests: add new t2206-add-submodule-ignored.sh to test ignore=all
> scenario
> tests: fix existing tests when add an ignore=all submodule
> Documentation: update add --force and submodule ignore=all config
> > Documentation/git-add.adoc | 4 +-
> Documentation/gitmodules.adoc | 5 +-
> builtin/add.c | 2 +-
> builtin/checkout.c | 2 +-
> builtin/commit.c | 2 +-
> read-cache-ll.h | 2 +-
> read-cache.c | 54 ++++++++++++-
> t/lib-submodule-update.sh | 6 +-
> t/meson.build | 1 +
> t/t2206-add-submodule-ignored.sh | 134 +++++++++++++++++++++++++++++++
> t/t7508-status.sh | 2 +-
> 11 files changed, 202 insertions(+), 12 deletions(-)
> create mode 100755 t/t2206-add-submodule-ignored.sh
> > > base-commit: c44beea485f0f2feaf460e2ac87fdd5608d63cf0
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1987%2FPraqma%2Frespect-submodule-ignore-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1987/Praqma/respect-submodule-ignore-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/1987 |
|
User |
|
On the Git mailing list, Claus Schneider wrote (reply to this): Hi again ..
I have read the documentation for submodule and reset. See from a
non-git-developer it is actually pretty hard to understand what
happens with regards to the "reset" command.
The only hint I can find which does not mean a lot to an ordinary user:
- "Defines under what circumstances "git status" and the diff family
show a submodule as modified".
- GPT-5 does not say anything regarding "reset", if asked a few levels
of "/explains" regarding "diff family". I find the documentation
inconclusive as an end-user.
- Looking at the "reset" --help it does only talk about
--[no-]recurse-submodules but not really what the ignore=all
- I can find the override_submodule_config=1 in reset, commit, status,
add-interactive, read-cache.
.. so I am a bit confused.
From an end-user perspective I would expect this of "all":
- (pre-action): "status" and "diff-of-workspace/staging". It should
respect ignore=all unless overridden or explicit specified
- (action): "add" : It should respect ignore=all unless overridden or
explicit specified(--force)
- (action): "reset", "restore" ..<etc>: It should respect ignore=all
unless overridden or explicit specified and leave it to submodules
--init / --remote
- (action): "clean": It could be argued of the -x option should also
act on submodules - but fair to leave it to submodules --init /
--remote
- (post-action) "diff-of-history", "log" (aka <ref1> <ref2> ) : It
should always tell what happened in history (git-graph) despite what
the current .gitmodules states regards to ignore=all
It could be a new option value should be added like "always" or
"logical" respectively the above and then leave the "all" to the
current behavior.
Best regards
Claus
On Sun, Oct 19, 2025 at 11:55 PM Claus Schneider
<claus.schneider@eficode.com> wrote:
>
> Hi Philip ..
>
> Thank you for your feedback and for investigating this. I was not aware of the setting that causes `add` and `reset` to override submodule configuration, and I will need to look into `reset` further.
>
> I understand the problematic aspect of not being able to add an update of a submodule reference, which likely led to the overwrite setting. From a Git developer's perspective, always adding it might have seemed like the simplest approach.
>
> However, from an end-user perspective, it's not logical for `status` to show nothing while `add` has an effect. A more intuitive workflow would align with how ignored files are handled even though it is already tracked.
>
> My patch implements what I believe should have been in the first place. My implementation still needs the `overwrite=1` set in order to get the diff files list so I can 'operate' on it and make the `--force` logic like the ignore files.
>
> Best regards
> Claus
>
> On Sun, Oct 19, 2025, 17:34 Phillip Wood <phillip.wood123@gmail.com> wrote:
>>
>> Hi Claus
>>
>> [I've adjusted the CC list slightly]
>>
>> On 18/10/2025 21:07, Claus Schneider via GitGitGadget wrote:
>> > The feature of configuring a submodule to "ignore=all" is nicely respected
>> > in commands "status" and "diff". However the "add" command does not respect
>> > the configuration the same way.
>>
>> I was curious why, when "git add" uses the same machinery as "git diff"
>> to figure out which paths need updating, it behaves differently. It
>> turns out that add_files_to_cache() contains
>>
>> rev.diffopt.flags.override_submodule_config = 1;
>>
>> which makes "git add" ignore "submodule.<name>.ignore". Tracing the
>> history of this line, it originates from 5556808690e (add, reset: ensure
>> submodules can be added or reset, 2017-07-25) which made a deliberate
>> choice for both "git add" and "git reset" not to behave like "git diff".
>> If we're going to change the behavior then it would be helpful to
>> explain how this patch series ameliorates the concerns that lead to that
>> commit and why it is sensible to change the behavior of "git add" but
>> not "git reset". It also suggests that a much simpler way of
>> implementing the change would be to delete that line.
>>
>> I'm not convinced that the approach of using "--force" is a good idea as
>> it conflates ignoring changes to tracked paths (which is what
>> submodule.<name>.ignore" does) with ignoring untracked paths (which is
>> what ".gitignore" does). If we're happy to break existing uses that rely
>> on the current behavior then having a new option to override
>> submodule.<name>.ignore strikes me as a better way forward. I don't have
>> much experience of using submodules so I can't comment on whether
>> changing the behavior is a good idea or not.
>>
>> Thanks
>>
>> Phillip
>>
>>
>> The behavior is problematic for the logic
>> > between status/diff and add. Secondly it makes it problematic to track
>> > branches in the submodule configuration as developers unintentionally keeps
>> > add submodule updates and get conflicts for no intentional reason. Both adds
>> > unnecessary friction to the usage of submodules.
>> >
>> > The patches implement the same logical behavior for ignore=all submodules as
>> > regular ignored files. The status now does not show any diff - nor will the
>> > add command update the reference submodule reference. If you add the
>> > submodule path which is ignore=all then you are presented with a message
>> > that you need to use the --force option. The branch=, ignore=all (and
>> > update=none) now works great with update --remote, but developers does not
>> > have to consider changes in the updates of the submodule sha1. The
>> > implementation removes a friction of working with submodules and can be used
>> > like the repo tool with branches configured. The submodule status report
>> > could be used for build/release documentation for reproduction of a setup.
>> >
>> > A few tests used the adding of submodules without --force, hence they have
>> > been updated to use the --force option.
>> >
>> > Claus Schneider(Eficode) (5):
>> > read-cache: update add_files_to_cache to take param
>> > ignored_too(--force)
>> > read-cache: let read-cache respect submodule ignore=all and --force
>> > tests: add new t2206-add-submodule-ignored.sh to test ignore=all
>> > scenario
>> > tests: fix existing tests when add an ignore=all submodule
>> > Documentation: update add --force and submodule ignore=all config
>> >
>> > Documentation/git-add.adoc | 4 +-
>> > Documentation/gitmodules.adoc | 5 +-
>> > builtin/add.c | 2 +-
>> > builtin/checkout.c | 2 +-
>> > builtin/commit.c | 2 +-
>> > read-cache-ll.h | 2 +-
>> > read-cache.c | 54 ++++++++++++-
>> > t/lib-submodule-update.sh | 6 +-
>> > t/meson.build | 1 +
>> > t/t2206-add-submodule-ignored.sh | 134 +++++++++++++++++++++++++++++++
>> > t/t7508-status.sh | 2 +-
>> > 11 files changed, 202 insertions(+), 12 deletions(-)
>> > create mode 100755 t/t2206-add-submodule-ignored.sh
>> >
>> >
>> > base-commit: c44beea485f0f2feaf460e2ac87fdd5608d63cf0
>> > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1987%2FPraqma%2Frespect-submodule-ignore-v1
>> > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1987/Praqma/respect-submodule-ignore-v1
>> > Pull-Request: https://github.com/gitgitgadget/git/pull/1987
>> |
|
User |
|
On the Git mailing list, Phillip Wood wrote (reply to this): Hi Claus
On 19/10/2025 22:39, Claus Schneider wrote:
> On Sun, Oct 19, 2025, 17:34 Phillip Wood <phillip.wood123@gmail.com > <mailto:phillip.wood123@gmail.com>> wrote:
> >> I was curious why, when "git add" uses the same machinery as "git diff"
>> to figure out which paths need updating, it behaves differently. It
>> turns out that add_files_to_cache() contains
>> >> rev.diffopt.flags.override_submodule_config = 1;
>> >> which makes "git add" ignore "submodule.<name>.ignore". Tracing the
>> history of this line, it originates from 5556808690e (add, reset: ensure
>> submodules can be added or reset, 2017-07-25) which made a deliberate
>> choice for both "git add" and "git reset" not to behave like "git diff".
> Thank you for your feedback and for investigating this. I was not aware > of the setting that causes `add` and `reset` to override submodule > configuration, and I will need to look into `reset` further.
You should mention the commit that added the current behavior and the
reason it was added in the commit message where you change the behavior.
> I understand the problematic aspect of not being able to add an update > of a submodule reference, which likely led to the overwrite setting. > From a Git developer's perspective, always adding it might have seemed > like the simplest approach.
> > However, from an end-user perspective, it's not logical for `status` to > show nothing while `add` has an effect. I'm quite sympathetic to this view, I think you should explain this in the
commit message where you change the behavior and see what others think.
> A more intuitive workflow would > align with how ignored files are handled even though it is already tracked.
As I said before do not think conflating ignoring changes to tracked files
with ignoring files is a good idea. The two are fundamentally different
because ignored files are not tracked. I would suggest adding a new option
such as "--include-ignored-submodules" instead of piggybacking on "--force".
Using a different option also means that user's will not accidentally stage
ignored files when they're trying to stage a submodule whose changes are
normally ignored.
> My patch implements what I believe should have been in the first place. > My implementation still needs the `overwrite=1` set in order to get the > diff files list so I can 'operate' on it and make the `--force` logic > like the ignore files.
Oh, you're right, if we want to print a warning we will need to keep
overriding the submodule config.
Hopefully someone with more experience of submodules will be able to review
the code soon.
Thanks
Phillip |
…lint-9.34.0 build(deps-dev): bump eslint from 9.33.0 to 9.34.0
…odules 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>
Submodules configured with ignore=all are now skipped during add operations unless overridden by --include-ignored-submodules and the submodule path is explicitly specified. A message is printed (like ignored files) guiding the user to use the --include-ignored-submodules flag if the user has explicitely want to update the submodule reference. The reason for the change is support submodule branch tracking or similar and git status state nothing and git add should not add either. The workflow is more logic and similar to regular ignored files even the submodule is already tracked. The change opens up a lot of possibilities for submodules to be used more freely and simular to the repo tool. A submodule can be added for many more reason and loosely coupled dependencies to the super repo which often gives the friction of handle the explicit commits and updates without the need for tracking the submodule sha1 by sha1. Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
…ario The tests verify that the submodule behavior is intact and updating the config with ignore=all also behaves as intended with configuration in .gitmodules and configuration given on the command line. The usage of --include_ignored_submodules is showcased and tested in the test suite. The test file is added to meson.build for execution. Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
There are tests that rely on "git add <submodule>" to add updates in the parent repository. A new option --include-ignored-submodules is introduced as it is now needed with this enhancement. Updated tests: - t1013-read-tree-submodule.sh ( fixed in: t/lib-submodule-update.sh ) - t2013-checkout-submodule.sh ( fixed in: t/lib-submodule-update.sh ) - t7406-submodule-update.sh - t7508-status.sh Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
3167309 to
867ad4d
Compare
- git-add.adoc: Add new documentation for --include_ignored_submodules option to supress ignore=all and new submodule functionality of not adding a ignore=all submodule by default. - gitmodules.adoc and config/submodule.adoc: The submodule config ignore=all now need --include_ignored_submodules in order to update the index. Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
867ad4d to
ee84190
Compare
|
I have added more reasoning and change the option name as suggest to --include-ignored-submodules. |
|
On the Git mailing list, Claus Schneider wrote (reply to this): Thanks for the feedback and suggestions.
I have now implemented the --include-ignored-submodules option instead
of --force.
I have also extended the commit messages with more reasoning.
? Is it best to have a single commit with everything or a set of
commit for each part of the solution
? How do I update the patches with the modifications accordingly (
from GitGadget PR with a new /submit ) ?
Thanks in advance
Claus Schneider
On Fri, Oct 24, 2025 at 3:55 PM Phillip Wood <phillip.wood123@gmail.com> wrote:
>
> Hi Claus
>
> On 19/10/2025 22:39, Claus Schneider wrote:
> > On Sun, Oct 19, 2025, 17:34 Phillip Wood <phillip.wood123@gmail.com
> > <mailto:phillip.wood123@gmail.com>> wrote:
> >
> >> I was curious why, when "git add" uses the same machinery as "git diff"
> >> to figure out which paths need updating, it behaves differently. It
> >> turns out that add_files_to_cache() contains
> >>
> >> rev.diffopt.flags.override_submodule_config = 1;
> >>
> >> which makes "git add" ignore "submodule.<name>.ignore". Tracing the
> >> history of this line, it originates from 5556808690e (add, reset: ensure
> >> submodules can be added or reset, 2017-07-25) which made a deliberate
> >> choice for both "git add" and "git reset" not to behave like "git diff".
>
> > Thank you for your feedback and for investigating this. I was not aware > of the setting that causes `add` and `reset` to override submodule
> > configuration, and I will need to look into `reset` further.
>
> You should mention the commit that added the current behavior and the
> reason it was added in the commit message where you change the behavior.
>
> > I understand the problematic aspect of not being able to add an update
> > of a submodule reference, which likely led to the overwrite setting.
> > From a Git developer's perspective, always adding it might have seemed
> > like the simplest approach.
> >
> > However, from an end-user perspective, it's not logical for `status` to
> > show nothing while `add` has an effect.
>
> I'm quite sympathetic to this view, I think you should explain this in the
> commit message where you change the behavior and see what others think.
>
> > A more intuitive workflow would
> > align with how ignored files are handled even though it is already tracked.
>
> As I said before do not think conflating ignoring changes to tracked files
> with ignoring files is a good idea. The two are fundamentally different
> because ignored files are not tracked. I would suggest adding a new option
> such as "--include-ignored-submodules" instead of piggybacking on "--force".
> Using a different option also means that user's will not accidentally stage
> ignored files when they're trying to stage a submodule whose changes are
> normally ignored.
>
> > My patch implements what I believe should have been in the first place.
> > My implementation still needs the `overwrite=1` set in order to get the
> > diff files list so I can 'operate' on it and make the `--force` logic
> > like the ignore files.
>
> Oh, you're right, if we want to print a warning we will need to keep
> overriding the submodule config.
>
> Hopefully someone with more experience of submodules will be able to review
> the code soon.
>
> Thanks
>
> Phillip |
|
/submit |
|
Submitted as pull.1987.v2.git.1763057433.gitgitgadget@gmail.com To fetch this version into To fetch this version to local tag |
|
On the Git mailing list, Junio C Hamano wrote (reply to this): "Claus Schneider via GitGitGadget" <gitgitgadget@gmail.com> writes:
> The feature of configuring a submodule to "ignore=all" is nicely respected
> in commands "status" and "diff".
"nicely respected" is not very informative for those who do not know
what the setting does. Saying something like
"git status" and "git diff" will not report modified submodules
with submodule.<name>.ignore set to "all".
would not waste significantly more bytes than what you wrote, and is
more helpful.
> However the "add" command does not respect
> the configuration the same way.
Again, "does not respect" and then what? Running "git add" on a
submodule with submodule.<name>.ignore set to "all" does what?
Complains that it has changes but because .ignore is set it won't
add? Adds it silently? Something else?
> The behavior is problematic for the logic
> between status/diff and add.
After this sentence, "because ..." is missing. Please help readers
understand the issue you perceive as problematic more easily.
I am guessing that you are assuming that an "add", after "diff" or
"status" said there is no change, is expected to be a no-op, but I
cannot be sure if that is what you are referring to here with the
reason left unsaid like the above.
> Secondly it makes it problematic to track
> branches in the submodule configuration as developers unintentionally keeps
> add submodule updates and get conflicts for no intentional reason. Both adds
> unnecessary friction to the usage of submodules.
>
> The patches implement the same logical behavior for ignore=all submodules as
> regular ignored files. The status now does not show any diff - nor will the
> add command update the reference submodule reference. If you add the
> submodule path which is ignore=all then you are presented with a message
> that you need to use the --force option.
I vaguely recall that an earlier discussion between you and Phillip
were concluding against "--force"? I personally feel it is in line
with "git add foo.o" (when '*.o' is in .gitignore) gets rejected and
"git add -f foo.o" is a way to override it, but in the list of
patches below, I see --include-ignored-submodules (no, our command
line option names do not use underscore for inter-word-gaps), so I
suspect the description in the cover letter around here is stale?
> The branch=, ignore=all (and
> update=none) now works great with update --remote,
Again, "great" is not very informative, and as bad as "nicely
respected". Avoid using these adjectives loaded with unnecessary
value judgements, and instead trust your readers. They are
intelligent to judge if the updated behaviour is great or not for
themselves. Try to use the same bytes on helping readers understand
what actually happens.
> but developers does not
"do not".
> have to consider changes in the updates of the submodule sha1. The
> implementation removes a friction of working with submodules and can be used
> like the repo tool with branches configured. The submodule status report
> could be used for build/release documentation for reproduction of a setup.
>
> A few tests used the adding of submodules without --force, hence they have
> been updated to use the --force option.
>
> Claus Schneider(Eficode) (5):
> read-cache: update add_files_to_cache take param
> include_ignored_submodules
> read-cache: add/read-cache respect submodule ignore=all
> tests: add new t2206-add-submodule-ignored.sh to test ignore=all
> scenario
> tests: fix existing tests when add an ignore=all submodule
> Documentation: add --include_ignored_submodules + ignore=all config
>
> .devcontainer/Dockerfile | 70 +++++++++++++++
> .devcontainer/Dockerfile.standalone | 76 ++++++++++++++++
> .devcontainer/devcontainer.json | 25 ++++++
> Documentation/config/submodule.adoc | 13 +--
> Documentation/git-add.adoc | 5 ++
> Documentation/gitmodules.adoc | 5 +-
> builtin/add.c | 4 +-
> builtin/checkout.c | 2 +-
> builtin/commit.c | 2 +-
> read-cache-ll.h | 2 +-
> read-cache.c | 54 ++++++++++-
> t/lib-submodule-update.sh | 6 +-
> t/meson.build | 1 +
> t/t2206-add-submodule-ignored.sh | 134 ++++++++++++++++++++++++++++
> t/t7508-status.sh | 2 +-
> 15 files changed, 384 insertions(+), 17 deletions(-)
> create mode 100644 .devcontainer/Dockerfile
> create mode 100644 .devcontainer/Dockerfile.standalone
> create mode 100644 .devcontainer/devcontainer.json
> create mode 100755 t/t2206-add-submodule-ignored.sh
>
>
> base-commit: 81f86aacc4eb74cdb9c2c8082d36d2070c666045
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1987%2FPraqma%2Frespect-submodule-ignore-v2
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1987/Praqma/respect-submodule-ignore-v2
> Pull-Request: https://github.com/gitgitgadget/git/pull/1987
>
> Range-diff vs v1:
>
> 1: d98cca698d ! 1: 5796009122 read-cache: update add_files_to_cache to take param ignored_too(--force)
> @@ Metadata
> Author: Claus Schneider(Eficode) <claus.schneider@eficode.com>
>
> ## Commit message ##
> - read-cache: update add_files_to_cache to take param ignored_too(--force)
> + read-cache: update add_files_to_cache take param include_ignored_submodules
>
> - The ignored_too 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.
> + 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 ##
> +@@ builtin/add.c: 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;
> +@@ builtin/add.c: 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,
> @@ builtin/add.c: int cmd_add(int argc,
> else
> exit_status |= add_files_to_cache(repo, prefix,
> &pathspec, ps_matched,
> - include_sparse, flags);
> -+ include_sparse, flags, ignored_too);
> ++ include_sparse, flags, include_ignored_submodules);
>
> if (take_worktree_changes && !add_renormalize && !ignore_add_errors &&
> report_path_error(ps_matched, &pathspec))
> @@ read-cache.c: void overlay_tree_on_index(struct index_state *istate,
> int include_sparse;
> int flags;
> int add_errors;
> -+ int ignored_too;
> ++ int include_ignored_submodules;
> };
>
> static int fix_unmerged_status(struct diff_filepair *p,
> @@ read-cache.c: 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"));
> +@@ read-cache.c: 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 ignored_too )
> ++ int include_sparse, int flags, int include_ignored_submodules )
> {
> struct update_callback_data data;
> struct rev_info rev;
> @@ read-cache.c: int add_files_to_cache(struct repository *repo, const char *prefix
> data.include_sparse = include_sparse;
> data.flags = flags;
> + data.repo = repo;
> -+ data.ignored_too = ignored_too;
> ++ data.include_ignored_submodules = include_ignored_submodules;
> + data.pathspec = (struct pathspec *)pathspec;
>
> repo_init_revisions(repo, &rev, prefix);
> 2: d1b02617e6 ! 2: 9ec79b9a11 read-cache: let read-cache respect submodule ignore=all and --force
> @@ Metadata
> Author: Claus Schneider(Eficode) <claus.schneider@eficode.com>
>
> ## Commit message ##
> - read-cache: let read-cache respect submodule ignore=all and --force
> + read-cache: add/read-cache respect submodule ignore=all
>
> - Given the submdule configuration is ignore=all then only update the
> - submdule if the --force option is given and the submodule is explicit
> - given in the pathspec.
> + Submodules configured with ignore=all are now skipped during add operations
> + unless overridden by --include-ignored-submodules and the submodule path is
> + explicitly specified.
>
> A message is printed (like ignored files) guiding the user to use the
> - --force flag if the user has explicitely want to update the submodule
> - reference.
> + --include-ignored-submodules flag if the user has explicitely want to update
> + the submodule reference.
>
> The reason for the change is support submodule branch tracking or
> similar and git status state nothing and git add should not add either.
> @@ Commit message
> the submodule is already tracked.
>
> The change opens up a lot of possibilities for submodules to be used
> - more freely and a like the repo tool. A submodule can be added for many
> + more freely and simular to the repo tool. A submodule can be added for many
> more reason and loosely coupled dependencies to the super repo which often
> gives the friction of handle the explicit commits and updates without
> the need for tracking the submodule sha1 by sha1.
> @@ read-cache.c
> /* Mask for the name length in ce_flags in the on-disk index */
>
> @@ read-cache.c: 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->ignored_too && data->ignored_too > 0) {
> -+ trace_printf("Forcing add of submodule ignored=all due to --force: %s\n", path);
> -+ } else {
> -+ printf(_("Skipping submodule due to ignore=all: %s"), path);
> -+ printf(_("Use -f 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"));
> + }
> + 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);
> ++ trace_printf("Add 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.") );
> +@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
> + }
> + } else {
> + /* No explicit pathspec match -> skip silently (or with trace). */
> +- trace_printf("pathspec does not match %s\n", path);
> ++ trace_printf("Pathspec to submodule does not match explicitly: %s\n", path);
> + continue;
> + }
> + }
> +@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
> data->add_errors++;
> }
> break;
> 3: 8f3d5f7ec1 ! 3: 399a153b95 tests: add new t2206-add-submodule-ignored.sh to test ignore=all scenario
> @@ Commit message
> config with ignore=all also behaves as intended with configuration in
> .gitmodules and configuration given on the command line.
>
> - Testfile is added to meson.build for execution.
> + The usage of --include_ignored_submodules is showcased and tested in the
> + test suite.
> +
> + The test file is added to meson.build for execution.
>
> Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
>
> @@ t/t2206-add-submodule-ignored.sh (new)
> +# This test covers the behavior of "git add", "git status" and "git log" when
> +# dealing with submodules that have the ignore=all setting in
> +# .gitmodules. It ensures that changes in such submodules are
> -+# ignored by default, but can be staged with "git add --force".
> ++# ignored by default, but can be staged with "git add --include-ignored-submodules".
> +
> +# shellcheck disable=SC1091
> +. ./test-lib.sh
> @@ t/t2206-add-submodule-ignored.sh (new)
> +'
> +
> +#6
> -+# check that 'git add --force .' does not stage the change in the submodule
> ++# check that 'git add --include-ignored-submodules .' does not stage the change in the submodule
> +# and that 'git status' does not show it as modified
> -+test_expect_success 'main: check --force add . and status' '
> ++test_expect_success 'main: check --include-ignored-submodules add . and status' '
> + cd "${base_path}" &&
> + cd main &&
> -+ GIT_TRACE=1 git add --force . &&
> ++ GIT_TRACE=1 git add --include-ignored-submodules . &&
> + ! git status --porcelain | grep "^M sub$" &&
> + echo
> +'
> @@ t/t2206-add-submodule-ignored.sh (new)
> +'
> +
> +#8
> -+# check that 'git add --force sub' does stage the change in the submodule
> -+# check that 'git add --force ./sub/' does stage the change in the submodule
> ++# check that 'git add --include-ignored-submodules sub' does stage the change in the submodule
> ++# check that 'git add --include-ignored-submodules ./sub/' does stage the change in the submodule
> +# and that 'git status --porcelain' does show it as modified
> +# commit it..
> +# check that 'git log --ignore-submodules=none' shows the submodule change
> @@ t/t2206-add-submodule-ignored.sh (new)
> +test_expect_success 'main: check force add sub and ./sub/ and status' '
> + cd "${base_path}" &&
> + cd main &&
> -+ echo "Adding with --force should work: git add --force sub" &&
> -+ GIT_TRACE=1 git add --force sub &&
> ++ echo "Adding with --include-ignored-submodules should work: git add --include-ignored-submodules sub" &&
> ++ GIT_TRACE=1 git add --include-ignored-submodules sub &&
> + git status --porcelain | grep "^M sub$" &&
> + git restore --staged sub &&
> + ! git status --porcelain | grep "^M sub$" &&
> -+ echo "Adding with --force should work: git add --force ./sub/" &&
> -+ GIT_TRACE=1 git add --force ./sub/ &&
> ++ echo "Adding with --include-ignored-submodules should work: git add --include-ignored-submodules ./sub/" &&
> ++ GIT_TRACE=1 git add --include-ignored-submodules ./sub/ &&
> + git status --porcelain | grep "^M sub$" &&
> + git commit -m "update submodule pointer" &&
> + ! git status --porcelain | grep "^ M sub$" &&
> 4: 58563a7b90 ! 4: 93c95954f1 tests: fix existing tests when add an ignore=all submodule
> @@ Metadata
> ## Commit message ##
> tests: fix existing tests when add an ignore=all submodule
>
> - There are tests that rely on "git add <submodule>" also adds it. A --force
> - is needed with this enhancement hence they are added accordingly in these
> - tests.
> + There are tests that rely on "git add <submodule>" to add updates in the
> + parent repository. A new option --include-ignored-submodules is introduced
> + as it is now needed with this enhancement.
>
> Updated tests:
> - t1013-read-tree-submodule.sh ( fixed in: t/lib-submodule-update.sh )
> + - t2013-checkout-submodule.sh ( fixed in: t/lib-submodule-update.sh )
> - t7406-submodule-update.sh
> - t7508-status.sh
>
> @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
> git push origin modifications
> ) &&
> - git add sub1 &&
> -+ git add --force sub1 &&
> ++ git add --include-ignored-submodules sub1 &&
> git commit -m "Modify sub1" &&
>
> git checkout -b add_nested_sub modify_sub1 &&
> @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
> git -C sub1 submodule add --branch no_submodule ../submodule_update_sub2 sub2 &&
> git -C sub1 commit -a -m "add a nested submodule" &&
> - git add sub1 &&
> -+ git add --force sub1 &&
> ++ git add --include-ignored-submodules sub1 &&
> git commit -a -m "update submodule, that updates a nested submodule" &&
> git checkout -b modify_sub1_recursively &&
> git -C sub1 checkout -b modify_sub1_recursively &&
> @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
> git -C sub1 add sub2 &&
> git -C sub1 commit -m "update nested sub" &&
> - git add sub1 &&
> -+ git add --force sub1 &&
> ++ git add --include-ignored-submodules sub1 &&
> git commit -m "update sub1, that updates nested sub" &&
> git -C sub1 push origin modify_sub1_recursively &&
> git -C sub1/sub2 push origin modify_sub1_recursively &&
> @@ t/t7508-status.sh: test_expect_success 'git commit will commit a staged but igno
> test_expect_success 'git commit --dry-run will show a staged but ignored submodule' '
> git reset HEAD^ &&
> - git add sm &&
> -+ git add --force sm &&
> ++ git add --include-ignored-submodules sm &&
> cat >expect << EOF &&
> On branch main
> Your branch and '\''upstream'\'' have diverged,
> 5: 416695f439 < -: ---------- Documentation: update add --force and submodule ignore=all config
> -: ---------- > 5: ee84190cd8 Documentation: add --include_ignored_submodules + ignore=all config |
| static const char ignore_error[] = | ||
| N_("The following paths are ignored by one of your .gitignore files:\n"); | ||
|
|
||
| static int verbose, show_only, ignored_too, refresh_only; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the Git mailing list, Junio C Hamano wrote (reply to this):
"Claus Schneider(Eficode) via GitGitGadget" <gitgitgadget@gmail.com>
writes:
> 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>
> ---
I still do not know enough if the overall idea of this topic is a
good idea, but let me regiew the code change at the mechanical level
(i.e., what needs fixing if these changes are good things to have).
> 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")),
Wrong indentation. Also, perhaps wrap this new line that is overly
long (*WITHOUT* rewrapping existing overly long lines)?
> add_files_to_cache(the_repository, NULL, NULL, NULL, 0,
> - 0);
> + 0, 0 );
Our coding style does not allow an extra space after "(" or before ")".
> 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 );
I am not sure if adding an extra parameter randomly like this is a
good idea. Existing include_sparse is already a single bit that is
stuffed in an int, so it might make sense to change it into a set of
bits (i.e., "unsigned int") in one preliminary patch, and then your
change can borrow another bit in the same flag word.
See the attached patch (not even compile tested, though) for an
illustration of what such a "preliminary clean-up" step to get rid
of the extra include_sparse parameter may look like.
> +++ 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
/* Our single liner comment should look like this, not with double-slashes */
The fact that this block has to be so deeply indented strongly
indicates that it should probably become a separate helper function.
I'll stop here for now.
builtin/add.c | 8 ++++----
builtin/checkout.c | 3 +--
builtin/commit.c | 2 +-
read-cache-ll.h | 6 +++++-
read-cache.c | 8 +++-----
5 files changed, 14 insertions(+), 13 deletions(-)
diff --git c/builtin/add.c w/builtin/add.c
index 32709794b3..49d0199c0b 100644
--- c/builtin/add.c
+++ w/builtin/add.c
@@ -384,7 +384,7 @@ int cmd_add(int argc,
int exit_status = 0;
struct pathspec pathspec;
struct dir_struct dir = DIR_INIT;
- int flags;
+ unsigned flags;
int add_new_files;
int require_pathspec;
char *seen = NULL;
@@ -485,7 +485,8 @@ int cmd_add(int argc,
(intent_to_add ? ADD_CACHE_INTENT : 0) |
(ignore_add_errors ? ADD_CACHE_IGNORE_ERRORS : 0) |
(!(addremove || take_worktree_changes)
- ? ADD_CACHE_IGNORE_REMOVAL : 0));
+ ? ADD_CACHE_IGNORE_REMOVAL : 0) |
+ (include_sparse ? ADD_CACHE_INCLUDE_SPARSE : 0));
if (repo_read_index_preload(repo, &pathspec, 0) < 0)
die(_("index file corrupt"));
@@ -583,8 +584,7 @@ int cmd_add(int argc,
exit_status |= renormalize_tracked_files(repo, &pathspec, flags);
else
exit_status |= add_files_to_cache(repo, prefix,
- &pathspec, ps_matched,
- include_sparse, flags);
+ &pathspec, ps_matched, flags);
if (take_worktree_changes && !add_renormalize && !ignore_add_errors &&
report_path_error(ps_matched, &pathspec))
diff --git c/builtin/checkout.c w/builtin/checkout.c
index f9453473fe..766a8e3b66 100644
--- c/builtin/checkout.c
+++ w/builtin/checkout.c
@@ -898,8 +898,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
* entries in the index.
*/
- add_files_to_cache(the_repository, NULL, NULL, NULL, 0,
- 0);
+ add_files_to_cache(the_repository, NULL, NULL, NULL, 0);
init_ui_merge_options(&o, the_repository);
o.verbosity = 0;
work = write_in_core_index_as_tree(the_repository);
diff --git c/builtin/commit.c w/builtin/commit.c
index 0243f17d53..6e42534977 100644
--- c/builtin/commit.c
+++ w/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);
if (!all && report_path_error(ps_matched, &pathspec))
exit(128);
diff --git c/read-cache-ll.h w/read-cache-ll.h
index 71b49d9af4..c9311f845b 100644
--- c/read-cache-ll.h
+++ w/read-cache-ll.h
@@ -390,11 +390,15 @@ int remove_index_entry_at(struct index_state *, int pos);
void remove_marked_cache_entries(struct index_state *istate, int invalidate);
int remove_file_from_index(struct index_state *, const char *path);
+
+/* add_files_to_cache() flags */
#define ADD_CACHE_VERBOSE 1
#define ADD_CACHE_PRETEND 2
#define ADD_CACHE_IGNORE_ERRORS 4
#define ADD_CACHE_IGNORE_REMOVAL 8
#define ADD_CACHE_INTENT 16
+#define ADD_CACHE_INCLUDE_SPARSE 32
+
/*
* These two are used to add the contents of the file at path
* to the index, marking the working tree up-to-date by storing
@@ -481,7 +485,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);
+ unsigned flags);
void overlay_tree_on_index(struct index_state *istate,
const char *tree_name, const char *prefix);
diff --git c/read-cache.c w/read-cache.c
index 032480d0c7..f32b642446 100644
--- c/read-cache.c
+++ w/read-cache.c
@@ -3881,8 +3881,7 @@ void overlay_tree_on_index(struct index_state *istate,
struct update_callback_data {
struct index_state *index;
- int include_sparse;
- int flags;
+ unsigned flags;
int add_errors;
};
@@ -3917,7 +3916,7 @@ static void update_callback(struct diff_queue_struct *q,
struct diff_filepair *p = q->queue[i];
const char *path = p->one->path;
- if (!data->include_sparse &&
+ if (!(data->flags & ADD_CACHE_INCLUDE_SPARSE) &&
!path_in_sparse_checkout(path, data->index))
continue;
@@ -3946,7 +3945,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)
+ unsigned flags)
{
struct odb_transaction *transaction;
struct update_callback_data data;
@@ -3954,7 +3953,6 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
memset(&data, 0, sizeof(data));
data.index = repo->index;
- data.include_sparse = include_sparse;
data.flags = flags;
repo_init_revisions(repo, &rev, prefix);|
On the Git mailing list, Claus Schneider wrote (reply to this): Thanks Junio - well received and noted. I have updated the PR
description accordingly, but I have not changed the "--force" in the
description even though I have implemented
''--include-ignored-submodules' as Philip had the input not to use
"--force". He suggested using a new option. Philips comment:
> I'm not convinced that the approach of using "--force" is a good idea as
> it conflates ignoring changes to tracked paths (which is what
> submodule.<name>.ignore" does) with ignoring untracked paths (which is
> what ".gitignore" does). If we're happy to break existing uses that rely
> on the current behavior then having a new option to override
> submodule.<name>.ignore strikes me as a better way forward. I don't have
> much experience of using submodules so I can't comment on whether
> changing the behavior is a good idea or not.
I think it will be more simple to use the '--force' option though and
keep the amount of options lower and less to remember. Given your
comments about more usages of bytes for option also becomes obsolete
if we stick to "--force". I am happy to do so.
I am investigating your other comments on the patches in the meantime.
On Thu, Nov 13, 2025 at 8:58 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> "Claus Schneider via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > The feature of configuring a submodule to "ignore=all" is nicely respected
> > in commands "status" and "diff".
>
> "nicely respected" is not very informative for those who do not know
> what the setting does. Saying something like
>
> "git status" and "git diff" will not report modified submodules
> with submodule.<name>.ignore set to "all".
>
> would not waste significantly more bytes than what you wrote, and is
> more helpful.
>
> > However the "add" command does not respect
> > the configuration the same way.
>
> Again, "does not respect" and then what? Running "git add" on a
> submodule with submodule.<name>.ignore set to "all" does what?
> Complains that it has changes but because .ignore is set it won't
> add? Adds it silently? Something else?
>
> > The behavior is problematic for the logic
> > between status/diff and add.
>
> After this sentence, "because ..." is missing. Please help readers
> understand the issue you perceive as problematic more easily.
>
> I am guessing that you are assuming that an "add", after "diff" or
> "status" said there is no change, is expected to be a no-op, but I
> cannot be sure if that is what you are referring to here with the
> reason left unsaid like the above.
>
> > Secondly it makes it problematic to track
> > branches in the submodule configuration as developers unintentionally keeps
> > add submodule updates and get conflicts for no intentional reason. Both adds
> > unnecessary friction to the usage of submodules.
> >
> > The patches implement the same logical behavior for ignore=all submodules as
> > regular ignored files. The status now does not show any diff - nor will the
> > add command update the reference submodule reference. If you add the
> > submodule path which is ignore=all then you are presented with a message
> > that you need to use the --force option.
>
> I vaguely recall that an earlier discussion between you and Phillip
> were concluding against "--force"? I personally feel it is in line
> with "git add foo.o" (when '*.o' is in .gitignore) gets rejected and
> "git add -f foo.o" is a way to override it, but in the list of
> patches below, I see --include-ignored-submodules (no, our command
> line option names do not use underscore for inter-word-gaps), so I
> suspect the description in the cover letter around here is stale?
>
>
> > The branch=, ignore=all (and
> > update=none) now works great with update --remote,
>
> Again, "great" is not very informative, and as bad as "nicely
> respected". Avoid using these adjectives loaded with unnecessary
> value judgements, and instead trust your readers. They are
> intelligent to judge if the updated behaviour is great or not for
> themselves. Try to use the same bytes on helping readers understand
> what actually happens.
>
> > but developers does not
>
> "do not".
>
> > have to consider changes in the updates of the submodule sha1. The
> > implementation removes a friction of working with submodules and can be used
> > like the repo tool with branches configured. The submodule status report
> > could be used for build/release documentation for reproduction of a setup.
> >
> > A few tests used the adding of submodules without --force, hence they have
> > been updated to use the --force option.
> >
> > Claus Schneider(Eficode) (5):
> > read-cache: update add_files_to_cache take param
> > include_ignored_submodules
> > read-cache: add/read-cache respect submodule ignore=all
> > tests: add new t2206-add-submodule-ignored.sh to test ignore=all
> > scenario
> > tests: fix existing tests when add an ignore=all submodule
> > Documentation: add --include_ignored_submodules + ignore=all config
> >
> > .devcontainer/Dockerfile | 70 +++++++++++++++
> > .devcontainer/Dockerfile.standalone | 76 ++++++++++++++++
> > .devcontainer/devcontainer.json | 25 ++++++
> > Documentation/config/submodule.adoc | 13 +--
> > Documentation/git-add.adoc | 5 ++
> > Documentation/gitmodules.adoc | 5 +-
> > builtin/add.c | 4 +-
> > builtin/checkout.c | 2 +-
> > builtin/commit.c | 2 +-
> > read-cache-ll.h | 2 +-
> > read-cache.c | 54 ++++++++++-
> > t/lib-submodule-update.sh | 6 +-
> > t/meson.build | 1 +
> > t/t2206-add-submodule-ignored.sh | 134 ++++++++++++++++++++++++++++
> > t/t7508-status.sh | 2 +-
> > 15 files changed, 384 insertions(+), 17 deletions(-)
> > create mode 100644 .devcontainer/Dockerfile
> > create mode 100644 .devcontainer/Dockerfile.standalone
> > create mode 100644 .devcontainer/devcontainer.json
> > create mode 100755 t/t2206-add-submodule-ignored.sh
> >
> >
> > base-commit: 81f86aacc4eb74cdb9c2c8082d36d2070c666045
> > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1987%2FPraqma%2Frespect-submodule-ignore-v2
> > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1987/Praqma/respect-submodule-ignore-v2
> > Pull-Request: https://github.com/gitgitgadget/git/pull/1987
> >
> > Range-diff vs v1:
> >
> > 1: d98cca698d ! 1: 5796009122 read-cache: update add_files_to_cache to take param ignored_too(--force)
> > @@ Metadata
> > Author: Claus Schneider(Eficode) <claus.schneider@eficode.com>
> >
> > ## Commit message ##
> > - read-cache: update add_files_to_cache to take param ignored_too(--force)
> > + read-cache: update add_files_to_cache take param include_ignored_submodules
> >
> > - The ignored_too 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.
> > + 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 ##
> > +@@ builtin/add.c: 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;
> > +@@ builtin/add.c: 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,
> > @@ builtin/add.c: int cmd_add(int argc,
> > else
> > exit_status |= add_files_to_cache(repo, prefix,
> > &pathspec, ps_matched,
> > - include_sparse, flags);
> > -+ include_sparse, flags, ignored_too);
> > ++ include_sparse, flags, include_ignored_submodules);
> >
> > if (take_worktree_changes && !add_renormalize && !ignore_add_errors &&
> > report_path_error(ps_matched, &pathspec))
> > @@ read-cache.c: void overlay_tree_on_index(struct index_state *istate,
> > int include_sparse;
> > int flags;
> > int add_errors;
> > -+ int ignored_too;
> > ++ int include_ignored_submodules;
> > };
> >
> > static int fix_unmerged_status(struct diff_filepair *p,
> > @@ read-cache.c: 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"));
> > +@@ read-cache.c: 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 ignored_too )
> > ++ int include_sparse, int flags, int include_ignored_submodules )
> > {
> > struct update_callback_data data;
> > struct rev_info rev;
> > @@ read-cache.c: int add_files_to_cache(struct repository *repo, const char *prefix
> > data.include_sparse = include_sparse;
> > data.flags = flags;
> > + data.repo = repo;
> > -+ data.ignored_too = ignored_too;
> > ++ data.include_ignored_submodules = include_ignored_submodules;
> > + data.pathspec = (struct pathspec *)pathspec;
> >
> > repo_init_revisions(repo, &rev, prefix);
> > 2: d1b02617e6 ! 2: 9ec79b9a11 read-cache: let read-cache respect submodule ignore=all and --force
> > @@ Metadata
> > Author: Claus Schneider(Eficode) <claus.schneider@eficode.com>
> >
> > ## Commit message ##
> > - read-cache: let read-cache respect submodule ignore=all and --force
> > + read-cache: add/read-cache respect submodule ignore=all
> >
> > - Given the submdule configuration is ignore=all then only update the
> > - submdule if the --force option is given and the submodule is explicit
> > - given in the pathspec.
> > + Submodules configured with ignore=all are now skipped during add operations
> > + unless overridden by --include-ignored-submodules and the submodule path is
> > + explicitly specified.
> >
> > A message is printed (like ignored files) guiding the user to use the
> > - --force flag if the user has explicitely want to update the submodule
> > - reference.
> > + --include-ignored-submodules flag if the user has explicitely want to update
> > + the submodule reference.
> >
> > The reason for the change is support submodule branch tracking or
> > similar and git status state nothing and git add should not add either.
> > @@ Commit message
> > the submodule is already tracked.
> >
> > The change opens up a lot of possibilities for submodules to be used
> > - more freely and a like the repo tool. A submodule can be added for many
> > + more freely and simular to the repo tool. A submodule can be added for many
> > more reason and loosely coupled dependencies to the super repo which often
> > gives the friction of handle the explicit commits and updates without
> > the need for tracking the submodule sha1 by sha1.
> > @@ read-cache.c
> > /* Mask for the name length in ce_flags in the on-disk index */
> >
> > @@ read-cache.c: 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->ignored_too && data->ignored_too > 0) {
> > -+ trace_printf("Forcing add of submodule ignored=all due to --force: %s\n", path);
> > -+ } else {
> > -+ printf(_("Skipping submodule due to ignore=all: %s"), path);
> > -+ printf(_("Use -f 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"));
> > + }
> > + 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);
> > ++ trace_printf("Add 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.") );
> > +@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
> > + }
> > + } else {
> > + /* No explicit pathspec match -> skip silently (or with trace). */
> > +- trace_printf("pathspec does not match %s\n", path);
> > ++ trace_printf("Pathspec to submodule does not match explicitly: %s\n", path);
> > + continue;
> > + }
> > + }
> > +@@ read-cache.c: static void update_callback(struct diff_queue_struct *q,
> > data->add_errors++;
> > }
> > break;
> > 3: 8f3d5f7ec1 ! 3: 399a153b95 tests: add new t2206-add-submodule-ignored.sh to test ignore=all scenario
> > @@ Commit message
> > config with ignore=all also behaves as intended with configuration in
> > .gitmodules and configuration given on the command line.
> >
> > - Testfile is added to meson.build for execution.
> > + The usage of --include_ignored_submodules is showcased and tested in the
> > + test suite.
> > +
> > + The test file is added to meson.build for execution.
> >
> > Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
> >
> > @@ t/t2206-add-submodule-ignored.sh (new)
> > +# This test covers the behavior of "git add", "git status" and "git log" when
> > +# dealing with submodules that have the ignore=all setting in
> > +# .gitmodules. It ensures that changes in such submodules are
> > -+# ignored by default, but can be staged with "git add --force".
> > ++# ignored by default, but can be staged with "git add --include-ignored-submodules".
> > +
> > +# shellcheck disable=SC1091
> > +. ./test-lib.sh
> > @@ t/t2206-add-submodule-ignored.sh (new)
> > +'
> > +
> > +#6
> > -+# check that 'git add --force .' does not stage the change in the submodule
> > ++# check that 'git add --include-ignored-submodules .' does not stage the change in the submodule
> > +# and that 'git status' does not show it as modified
> > -+test_expect_success 'main: check --force add . and status' '
> > ++test_expect_success 'main: check --include-ignored-submodules add . and status' '
> > + cd "${base_path}" &&
> > + cd main &&
> > -+ GIT_TRACE=1 git add --force . &&
> > ++ GIT_TRACE=1 git add --include-ignored-submodules . &&
> > + ! git status --porcelain | grep "^M sub$" &&
> > + echo
> > +'
> > @@ t/t2206-add-submodule-ignored.sh (new)
> > +'
> > +
> > +#8
> > -+# check that 'git add --force sub' does stage the change in the submodule
> > -+# check that 'git add --force ./sub/' does stage the change in the submodule
> > ++# check that 'git add --include-ignored-submodules sub' does stage the change in the submodule
> > ++# check that 'git add --include-ignored-submodules ./sub/' does stage the change in the submodule
> > +# and that 'git status --porcelain' does show it as modified
> > +# commit it..
> > +# check that 'git log --ignore-submodules=none' shows the submodule change
> > @@ t/t2206-add-submodule-ignored.sh (new)
> > +test_expect_success 'main: check force add sub and ./sub/ and status' '
> > + cd "${base_path}" &&
> > + cd main &&
> > -+ echo "Adding with --force should work: git add --force sub" &&
> > -+ GIT_TRACE=1 git add --force sub &&
> > ++ echo "Adding with --include-ignored-submodules should work: git add --include-ignored-submodules sub" &&
> > ++ GIT_TRACE=1 git add --include-ignored-submodules sub &&
> > + git status --porcelain | grep "^M sub$" &&
> > + git restore --staged sub &&
> > + ! git status --porcelain | grep "^M sub$" &&
> > -+ echo "Adding with --force should work: git add --force ./sub/" &&
> > -+ GIT_TRACE=1 git add --force ./sub/ &&
> > ++ echo "Adding with --include-ignored-submodules should work: git add --include-ignored-submodules ./sub/" &&
> > ++ GIT_TRACE=1 git add --include-ignored-submodules ./sub/ &&
> > + git status --porcelain | grep "^M sub$" &&
> > + git commit -m "update submodule pointer" &&
> > + ! git status --porcelain | grep "^ M sub$" &&
> > 4: 58563a7b90 ! 4: 93c95954f1 tests: fix existing tests when add an ignore=all submodule
> > @@ Metadata
> > ## Commit message ##
> > tests: fix existing tests when add an ignore=all submodule
> >
> > - There are tests that rely on "git add <submodule>" also adds it. A --force
> > - is needed with this enhancement hence they are added accordingly in these
> > - tests.
> > + There are tests that rely on "git add <submodule>" to add updates in the
> > + parent repository. A new option --include-ignored-submodules is introduced
> > + as it is now needed with this enhancement.
> >
> > Updated tests:
> > - t1013-read-tree-submodule.sh ( fixed in: t/lib-submodule-update.sh )
> > + - t2013-checkout-submodule.sh ( fixed in: t/lib-submodule-update.sh )
> > - t7406-submodule-update.sh
> > - t7508-status.sh
> >
> > @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
> > git push origin modifications
> > ) &&
> > - git add sub1 &&
> > -+ git add --force sub1 &&
> > ++ git add --include-ignored-submodules sub1 &&
> > git commit -m "Modify sub1" &&
> >
> > git checkout -b add_nested_sub modify_sub1 &&
> > @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
> > git -C sub1 submodule add --branch no_submodule ../submodule_update_sub2 sub2 &&
> > git -C sub1 commit -a -m "add a nested submodule" &&
> > - git add sub1 &&
> > -+ git add --force sub1 &&
> > ++ git add --include-ignored-submodules sub1 &&
> > git commit -a -m "update submodule, that updates a nested submodule" &&
> > git checkout -b modify_sub1_recursively &&
> > git -C sub1 checkout -b modify_sub1_recursively &&
> > @@ t/lib-submodule-update.sh: create_lib_submodule_repo () {
> > git -C sub1 add sub2 &&
> > git -C sub1 commit -m "update nested sub" &&
> > - git add sub1 &&
> > -+ git add --force sub1 &&
> > ++ git add --include-ignored-submodules sub1 &&
> > git commit -m "update sub1, that updates nested sub" &&
> > git -C sub1 push origin modify_sub1_recursively &&
> > git -C sub1/sub2 push origin modify_sub1_recursively &&
> > @@ t/t7508-status.sh: test_expect_success 'git commit will commit a staged but igno
> > test_expect_success 'git commit --dry-run will show a staged but ignored submodule' '
> > git reset HEAD^ &&
> > - git add sm &&
> > -+ git add --force sm &&
> > ++ git add --include-ignored-submodules sm &&
> > cat >expect << EOF &&
> > On branch main
> > Your branch and '\''upstream'\'' have diverged,
> > 5: 416695f439 < -: ---------- Documentation: update add --force and submodule ignore=all config
> > -: ---------- > 5: ee84190cd8 Documentation: add --include_ignored_submodules + ignore=all config |
The feature of configuring a submodule to "ignore=all" is nicely respected in commands "status" and "diff". However the "add" command does not respect the configuration the same way. The behavior is problematic for the logic between status/diff and add. Secondly it makes it problematic to track branches in the submodule configuration as developers unintentionally keeps add submodule updates and get conflicts for no intentional reason. Both adds unnecessary friction to the usage of submodules.
The patches implement the same logical behavior for ignore=all submodules as regular ignored files. The status now does not show any diff - nor will the add command update the reference submodule reference. If you add the submodule path which is ignore=all then you are presented with a message that you need to use the --force option. The branch=, ignore=all (and update=none) now works great with update --remote, but developers does not have to consider changes in the updates of the submodule sha1. The implementation removes a friction of working with submodules and can be used like the repo tool with branches configured. The submodule status report could be used for build/release documentation for reproduction of a setup.
A few tests used the adding of submodules without --force, hence they have been updated to use the --force option.
CC: Ævar Arnfjörð Bjarmason avarab@gmail.com
CC: Junio C Hamano gitster@pobox.com
CC: Brandon Williams bmwill@google.com
cc: Phillip Wood phillip.wood123@gmail.com
cc: Claus Schneider claus.schneider@eficode.com