Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid pathspec magic

Tags:

git

When I try to partially stage a file in git, I get the following error message.

git add -p mass_scan.py

fatal: Invalid pathspec magic 'prefix:8' in ':(prefix:8)mass_scan.py'
No changes.

What does it mean? How can I partially stage a file?

I use git version

git version 2.6.2.450.g259b5e6

installed directly from source (without package manager). I can still partially add files with tig.

like image 670
pfnuesel Avatar asked Jan 08 '16 20:01

pfnuesel


2 Answers

I reinstalled git and the error went away. I don't know what the original problem was, but it works now.

like image 102
pfnuesel Avatar answered Sep 29 '22 19:09

pfnuesel


There is another case where the Invalid pathspec magic can appear: when the file has multiple attributes declared in a .gitattributes.
That is, until Git 2.13 (Q2 2017) which fixes that bug.

See commit c5af19f, commit b0db704 (13 Mar 2017) by Brandon Williams (mbrandonw).
(Merged by Junio C Hamano -- gitster -- in commit f6c64c6, 17 Mar 2017)

pathspec: allow escaped query values

In our own .gitattributes file we have attributes such as:

*.[ch] whitespace=indent,trail,space

When querying for attributes we want to be able to ask for the exact value, i.e.

git ls-files :(attr:whitespace=indent,trail,space)

should work, but the commas are used in the attr magic to introduce the next attr, such that this query currently fails with:

fatal: Invalid pathspec magic 'trail' in ':(attr:whitespace=indent,trail,space)'

This change allows escaping characters by a backslash, such that the query

git ls-files :(attr:whitespace=indent\,trail\,space)

will match all path that have the value "indent,trail,space" for the whitespace attribute.


Note: with Git 2.20 (Q4 2018), "git add ':(attr:foo)'" is not supported and is supposed to be rejected while the command line arguments are parsed, but was not rejected.
It is now

See commit 84d938b (18 Sep 2018) by Nguyễn Thái Ngọc Duy (pclouds).
(Merged by Junio C Hamano -- gitster -- in commit faadedb, 24 Sep 2018)

add: do not accept pathspec magic 'attr'

Commit b0db704 (pathspec: allow querying for attributes - 2017-03-13, Git v2.13.0-rc0) adds new pathspec magic 'attr' but only with match_pathspec().
"git add" has some pathspec related code that still does not know about 'attr' and will bail out:

$ git add ':(attr:foo)'
fatal: BUG:dir.c:1584: unsupported magic 40

A better solution would be making this code support 'attr'. But I don't know how much work is needed (I'm not familiar with this new magic). For now, let's simply reject this magic with a friendlier message:

$ git add ':(attr:foo)'
fatal: :(attr:foo): pathspec magic not supported by this command: 'attr'

Update t6135 so that the expected error message is from the "graceful" rejection codepath, not "oops, we were supposed to reject the request to trigger this magic" codepath.


And since Git 2.21 (Q1 2019), that "pathspec magic" is no longer reserved to git ls-files, but applies to git log and git grep too!
The traversal over tree objects has learned to honor ":(attr:label)" pathspec match, which has been implemented only for enumerating paths on the filesystem.

See commit 5a0b97b, commit 22af33b, commit 93e2379, commit 67022e0, commit e092073 (18 Nov 2018) by Nguyễn Thái Ngọc Duy (pclouds).
(Merged by Junio C Hamano -- gitster -- in commit d6f05a4, 14 Jan 2019)

tree-walk: support :(attr) matching

This lets us use :(attr) with "git grep <tree-ish>" or "git log".

:(attr) requires another round of checking before we can declare that a path is matched. This is done after path matching since we have lots of optimization to take a shortcut when things don't match.

Note that if :(attr) is present, we can't return all_entries_interesting / all_entries_not_interesting anymore because we can't be certain about that.
Not until match_pathspec_attrs() can tell us "yes: all these paths satisfy :(attr)".

Second note. Even though we walk a specific tree, we use attributes from worktree (or falling back to the index), not from .gitattributes files on that tree.
This by itself is not necessarily wrong, but the user just have to be aware of this.

like image 35
VonC Avatar answered Sep 29 '22 19:09

VonC