With Git 2.44 (Q1 2024), "git add"(man) and git stash(man) learned to support the ":(attr:...)" magic pathspec.
That means your scenario (submodules without a repo name) is supported:
git add . ':(exclude,attr:submodule)'
See commit 1164c72 (03 Nov 2023) by Joanna Wang (joannajw).
(Merged by Junio C Hamano -- gitster -- in commit d8b0ec4, 09 Dec 2023)
attr: enable attr pathspec magic for git-add and git-stash
Signed-off-by: Joanna Wang
Allow users to limit or exclude files based on file attributes during git-add(man) and git-stash.
For example, the chromium project would like to use
$ git add . ':(exclude,attr:submodule)'
as submodules are managed by an external tool, forbidding end users to record changes with git add.
Allowing "git add" to often records changes that users do not want in their commits.
This commit does not change any attr magic implementation.
It is only adding attr as an allowed pathspec in git-add and git-stash, which was previously blocked by GUARD_PATHSPEC and a pathspec mask in parse_pathspec()).
However, we fix a bug in prefix_magic() where attr values were unintentionally removed.
This was triggerable when parse_pathspec() is called with PATHSPEC_PREFIX_ORIGIN as a flag, which was the case for git-stash (Bug originally filed here)
Furthermore, while other commands hit this code path it did not result in unexpected behavior because this bug only impacts the pathspec->items->original field which is NOT used to filter paths.
However, git-stash(man) does use pathspec->items->original when building args used to call other git commands.
(See add_pathspecs() usage and implementation in stash.c)
It is possible that when the attr pathspec feature was first added in b0db704 ("pathspec: allow querying for attributes", 2017-03-13, Git v2.13.0-rc0 -- merge listed in batch #5), "PATHSPEC_ATTR" was just unintentionally left out of a few GUARD_PATHSPEC() invocations.
Later, to get a more user-friendly error message when attr was used with git-add, PATHSPEC_ATTR was added as a mask to git-add's invocation of parse_pathspec() 84d938b ("add: do not accept pathspec magic 'attr'", 2018-09-18, Git v2.20.0-rc0 -- merge listed in batch #2).
However, this user-friendly error message was never added for git-stash.