1
0
mirror of https://github.com/git/git.git synced 2024-09-29 00:23:44 +02:00
git/builtin
Joanna Wang 1164c7232e attr: enable attr pathspec magic for git-add and git-stash
Allow users to limit or exclude files based on file attributes
during git-add 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 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 b0db704652 (pathspec: allow querying for attributes, 2017-03-13),
"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() 84d938b732 (add: do not accept
pathspec magic 'attr', 2018-09-18).  However, this user-friendly
error message was never added for git-stash.

[Reference]
 * https://lore.kernel.org/git/CAMmZTi-0QKtj7Q=sbC5qhipGsQxJFOY-Qkk1jfkRYwfF5FcUVg@mail.gmail.com/)

Signed-off-by: Joanna Wang <jojwang@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-11-04 17:00:27 +09:00
..
add.c attr: enable attr pathspec magic for git-add and git-stash 2023-11-04 17:00:27 +09:00
am.c Merge branch 'ob/am-msgfix' 2023-09-29 09:04:16 -07:00
annotate.c
apply.c
archive.c
bisect.c doc/git-bisect: clarify git bisect run syntax 2023-10-23 13:04:47 -07:00
blame.c
branch.c builtin/branch.c: adjust error messages to coding guidelines 2023-10-23 12:22:57 -07:00
bugreport.c
bundle.c
cat-file.c doc/cat-file: make synopsis and description less confusing 2023-10-09 12:46:33 -07:00
check-attr.c
check-ignore.c
check-mailmap.c
check-ref-format.c
checkout--worker.c
checkout-index.c
checkout.c Merge branch 'jc/unresolve-removal' 2023-10-02 11:20:00 -07:00
clean.c
clone.c
column.c
commit-graph.c Merge branch 'jk/commit-graph-leak-fixes' 2023-10-13 14:18:28 -07:00
commit-tree.c
commit.c Merge branch 'jc/commit-new-underscore-index-fix' 2023-10-30 07:09:58 +09:00
config.c
count-objects.c
credential-cache--daemon.c
credential-cache.c
credential-store.c
credential.c
describe.c
diagnose.c
diff-files.c
diff-index.c
diff-tree.c
diff.c diff --stat: set the width defaults in a helper function 2023-09-29 15:46:06 -07:00
difftool.c
fast-export.c
fast-import.c Merge branch 'ew/hash-with-openssl-evp' 2023-09-13 10:07:57 -07:00
fetch-pack.c
fetch.c
fmt-merge-msg.c
for-each-ref.c
for-each-repo.c
fsck.c
fsmonitor--daemon.c run-command: mark unused parameters in start_bg_wait callbacks 2023-09-18 15:56:15 -07:00
gc.c Merge branch 'tb/repack-max-cruft-size' 2023-10-18 13:25:41 -07:00
get-tar-commit-id.c
grep.c Merge branch 'rs/grep-no-no-or' 2023-09-18 13:53:13 -07:00
hash-object.c
help.c
hook.c
index-pack.c Merge branch 'ew/hash-with-openssl-evp' 2023-09-13 10:07:57 -07:00
init-db.c
interpret-trailers.c Merge branch 'la/trailer-test-and-doc-updates' 2023-10-13 14:18:27 -07:00
log.c diff --stat: set the width defaults in a helper function 2023-09-29 15:46:06 -07:00
ls-files.c
ls-remote.c
ls-tree.c
mailinfo.c
mailsplit.c
merge-base.c
merge-file.c
merge-index.c
merge-ours.c
merge-recursive.c
merge-tree.c merge: introduce {copy|clear}_merge_options() 2023-10-11 13:37:47 -07:00
merge.c Merge branch 'jk/commit-graph-leak-fixes' 2023-10-13 14:18:28 -07:00
mktag.c
mktree.c
multi-pack-index.c
mv.c
name-rev.c
notes.c
pack-objects.c pack-objects: allow --filter without --stdout 2023-10-02 14:54:29 -07:00
pack-redundant.c
pack-refs.c
patch-id.c
prune-packed.c
prune.c
pull.c
push.c
range-diff.c
read-tree.c
rebase.c rebase: move parse_opt_keep_empty() down 2023-10-20 14:47:44 -07:00
receive-pack.c
reflog.c
remote-ext.c
remote-fd.c
remote.c
repack.c Merge branch 'tb/repack-max-cruft-size' 2023-10-18 13:25:41 -07:00
replace.c
rerere.c
reset.c
rev-list.c
rev-parse.c
revert.c
rm.c
send-pack.c
shortlog.c
show-branch.c
show-index.c
show-ref.c
sparse-checkout.c
stash.c Merge branch 'jc/fail-stash-to-store-non-stash' 2023-10-23 13:56:37 -07:00
stripspace.c
submodule--helper.c submodule--helper: return error from set-url when modifying failed 2023-10-03 15:30:43 -07:00
symbolic-ref.c
tag.c
unpack-file.c
unpack-objects.c Merge branch 'ew/hash-with-openssl-evp' 2023-09-13 10:07:57 -07:00
update-index.c Merge branch 'jc/unresolve-removal' 2023-10-02 11:20:00 -07:00
update-ref.c
update-server-info.c
upload-archive.c
upload-pack.c
var.c Merge branch 'bc/more-git-var' 2023-09-13 10:07:57 -07:00
verify-commit.c
verify-pack.c
verify-tag.c
worktree.c
write-tree.c