Skip to content
  • Joanna Wang's avatar
    attr: enable attr pathspec magic for git-add and git-stash · 1164c723
    Joanna Wang authored and Junio C Hamano's avatar Junio C Hamano committed
    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 b0db7046 (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() 84d938b7 (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: default avatarJoanna Wang <jojwang@google.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    1164c723