Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

github/git Checkout Returns 'error: invalid path' on Windows

When I attempt to checkout a repository from github I get the error:

error: invalid path 'configs/perl-modules/DIST.64/perl-HTML-Tree-1:5.03-1.el6.noarch.rpm' 

I suspect the issue is that the path contains a : which is illegal on Windows.

After researching the error, I've found 2 possible answers:
1) Change the path on the repository file. Unfortunately, this is is a team resource and can not be fixed in the foreseeable future.
2) Use sparse-checkout. I've tried this with no effect as evidenced in the following:

$ git clone -n [email protected]:XXXXXX/deploy.git
Cloning into 'deploy'...
remote: Enumerating objects: 57, done.
remote: Counting objects: 100% (57/57), done.
remote: Compressing objects: 100% (49/49), done.
remote: Total 86457 (delta 10), reused 22 (delta 8), pack-reused 86400
Receiving objects: 100% (86457/86457), 1.50 GiB | 4.73 MiB/s, done.
Resolving deltas: 100% (59779/59779), done.
$ cd deploy/
$ git config core.sparsecheckout true
$ echo www >> .git/info/sparse-checkout
$ git checkout centos6
error: invalid path 'configs/perl-modules/DIST.64/perl-HTML-Tree-1:5.03-1.el6.noarch.rpm'
error: invalid path 'configs/perlbrew/perls/perl-5.24.1/man/man3/App::Cpan.3'
.
. (repeat for many files)
.

This was done with Git for Windows "git version 2.28.0.windows.1". I have also tried both types of line endings and using various version of .git/info/sparse-checkout such as:

/* !/configs/perl-modules !/configs/perlbrew/perls/perl-5.24.1/man/man3 

Checkout works fine on Linux, MacOS and WSL, only problem is that my IDEs don't work there. Why isn't sparse-checkout working on Windows. Is there any other possibilities?

like image 915
wdtj Avatar asked Sep 03 '20 16:09

wdtj


People also ask

How do I fix a git error not a repository?

To do so, you need to navigate to the correct folder and then run the command git init , which will create a new empty Git repository or reinitialize an existing one.

Can we checkout specific folder in git?

To checkout everything from your HEAD (not index) to a specific out directory: git --work-tree=/path/to/outputdir checkout HEAD -- . Save this answer.


2 Answers

After I opened an issue on the git-for-windows bug tracker (https://github.com/git-for-windows/git/issues/2803), I found that my issue had already been filed as https://github.com/git-for-windows/git/issues/2777. That issue suggested that I need to set another git flag:

git config core.protectNTFS false 

This (#2777) indeed contains a bypass for the my problem. I hope the git or git-for-windows (who were very responsive) come up with a better warning message, or even a true fix like a filepath mapping scheme.

Note that this is only an issue when using sparse-checkout with windows.

like image 178
wdtj Avatar answered Sep 17 '22 16:09

wdtj


I have experienced a similar problem, trying to checkout a repository from GitHub that contained files with a ":" in the name, on a Windows. (example file name that caused the problem: "test-img.jpg:Zone.Identifier"). The repo downloaded, but the files were not showing up in the folder.

I found that running git config core.protectNTFS false solved my issue, but only if I took some steps before and after running it. The entire process went like so:

  1. Clone the Git repository locally;
  2. 'cd' into the local Git repository folder that has just been cloned;
  3. Run git reset
  4. Run git config core.protectNTFS false
  5. Run git checkout (just git checkout, no * at the end of command).

After that, I could see the files. Granted, some extra things downloaded from Git that are usually omitted, but it wasn't a big deal in my case.

like image 37
sn0wmaid3n Avatar answered Sep 17 '22 16:09

sn0wmaid3n