Bilbo Baggins
Bilbo Baggins

Reputation: 1199

Git is unable to access jarfile on Windows. No backslash characters are showing up in file path

I'm trying to integrate a checkstyle.xml file into a pre-compile git hook.

I successfully ran the command

git config --add checkstyle.xml C:\Users\<user>\Documents\<App-Name>\CheckStyle\checkstyle.xml 

However, now when I try to commit I get the following error:

Error: Unable to access jarfile C:Users<user>Documents<AppName>...

Notice that the backslashes don't exist. I looked at the git config file and each backslash has another backslash in front of it as an escape character.

Does git not recognize any backslashes? I tried adding the file with forward slashes instead of back and I get that the jarfile is corrupt. Any help would be appreciated.

edit: Paul Hicks' solution of changing

git config --add C:\mydir\checkstyle.xml

to

git config --add C:\\mydir\\checkstyle.xml

worked.

Upvotes: 0

Views: 1496

Answers (1)

Paul Hicks
Paul Hicks

Reputation: 14009

git understands both slashes and backslashes. To add backslashes, you must escape them. So either of these commands will work.

git config --add checkstyle.jar C:/yourdir/checkstyle.jar
git config --add checkstyle.jar C:\\yourdir\\checkstyle.jar

You can check your configuration by viewing the file .git/config, you should see something like this:

[checkstyle]
        jar = C:/yourdir/checkstyle.jar

Upvotes: 2

Related Questions