git and absolute Windows-style paths

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

git and absolute Windows-style paths

silverwind
Hey,

I noticed that Cygwin's git does not seem to correctly process
Windows-style paths in at least v2.7.4 and v2.8.1. It may have worked
before, but I'm not totally certain.

Interestingly, a command like "git add" still sets an 0 exit code
despite the apparent failure. Could it be that some effort to correct
the path is attempted, but it failed?

$ mkdir /cygdrive/c/test
$ cd /cygdrive/c/test
$ git init
$ touch file
$ git add C:\\test\\file         <-- this fails despite exit code 0
$ git status                     <-- shows no changes
$ git add /cygdrive/c/test/file  <-- this works
$ git status                     <-- correctly shows "new file"

Regards
Roman

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: git and absolute Windows-style paths

marco atzeri-4
On 19/04/2016 22:34, silverwind wrote:
> Hey,
>
> I noticed that Cygwin's git does not seem to correctly process
> Windows-style paths in at least v2.7.4 and v2.8.1. It may have worked
> before, but I'm not totally certain.

don't assume cygwin programs are able to process windows path.
Most don't. Use Posix paths



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: git and absolute Windows-style paths

Ken Brown-6
On 4/19/2016 5:31 PM, Marco Atzeri wrote:
> On 19/04/2016 22:34, silverwind wrote:
>> Hey,
>>
>> I noticed that Cygwin's git does not seem to correctly process
>> Windows-style paths in at least v2.7.4 and v2.8.1. It may have worked
>> before, but I'm not totally certain.
>
> don't assume cygwin programs are able to process windows path.
> Most don't. Use Posix paths

But I think the OP is correct in pointing out that git should have given
an error, as it does when a Posix path points to a non-existent file:

$ git add foo
fatal: pathspec 'foo' did not match any files

Ken

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

RE: git and absolute Windows-style paths

Bill Smith
In reply to this post by silverwind


> $ git add C:\\test\\file         <-- this fails despite exit code 0
[Bill Smith]
Does it work if you do:

git add c:/test/file

We use the mixed mode paths extensively with Cygwin in our environment and it works well.  We have the issue of having to work with non-Cygwin aware Windows programs.
Reply | Threaded
Open this post in threaded view
|

Re: git and absolute Windows-style paths

Adam Dinwoodie-2
In reply to this post by Ken Brown-6
On Tue, Apr 19, 2016 at 05:58:18PM -0400, Ken Brown wrote:

> On 4/19/2016 5:31 PM, Marco Atzeri wrote:
> >On 19/04/2016 22:34, silverwind wrote:
> >>Hey,
> >>
> >>I noticed that Cygwin's git does not seem to correctly process
> >>Windows-style paths in at least v2.7.4 and v2.8.1. It may have worked
> >>before, but I'm not totally certain.
> >
> >don't assume cygwin programs are able to process windows path.
> >Most don't. Use Posix paths
>
> But I think the OP is correct in pointing out that git should have
> given an error, as it does when a Posix path points to a
> non-existent file:
>
> $ git add foo
> fatal: pathspec 'foo' did not match any files

I wouldn't expect Windows-style paths to work, but I agree that I'd
expect them to error out rather than silently fail.  I can't immediately
see what's going wrong, so I'm going to report this upstream.

Some data points, from some quick experimentation:

- `git add 'c:\tmp\file'` silently fails to add `file` if it exists.
- `git add 'c:\tmp\file'` correctly errors out if `file` doesn't exist.
- `git add 'subdir\file'` (i.e. using relative paths with back-slashes)
  has the same behaviour.
- `git add 'c:/tmp/file'` also shows the same behaviour.

Adam

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: git and absolute Windows-style paths

silverwind
In reply to this post by Bill Smith
Hey,

> Does it work if you do:
>
> git add c:/test/file

Nope, won't work either. No file is added, exit code 0 is given.

 > I can't immediately see what's going wrong, so I'm going to report
this upstream.

Thanks. I came upon this issue through npm which is using these Windows
paths for certain git operations. Unfortunately, The npm team is very
reluctant when it comes to merging Cygwin-specific patches, so chances
of landing a fix on their side are rather slim.

Is there a public repository for the git package used by Cygwin?

Regards,
Roman

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: git and absolute Windows-style paths

Eliot Moss
On 4/20/2016 11:44 AM, silverwind wrote:

> Hey,
>
>> Does it work if you do:
>>
>> git add c:/test/file
>
> Nope, won't work either. No file is added, exit code 0 is given.
>
>  > I can't immediately see what's going wrong, so I'm going to report this upstream.
>
> Thanks. I came upon this issue through npm which is using these Windows paths for certain git
> operations. Unfortunately, The npm team is very reluctant when it comes to merging Cygwin-specific
> patches, so chances of landing a fix on their side are rather slim.
>
> Is there a public repository for the git package used by Cygwin?

I think that tackling this with a script/function is a better approach ...

Eliot Moss

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: git and absolute Windows-style paths

Brian Clifton
I agree completely-

Faking out git by wrapping it as a function in your .bashrc would be an ideal approach.  I was the person championing that PR which got rejected, unfortunately. The NPM folks were recommending to use mingw which *is* supported... but I haven't seen any updates to that project since 2013... and I prefer the approach Cygwin takes :)

Eliot, I would be all about taking you up on fixing that psuedo-code example I shared earlier. I have a lot to learn about shell scripting and while I am sure I can figure it out, having help would be extremely appreciated :)

The example I shared in my intro thread:
#####
function git {
    for var in "$@"
    do
        if [[ $var == *":\\"* ]]; then
            $var="$(cygpath $var)" #this doesn't work, but the idea is to do something like this
        fi
    done
    command git "$@"
}
#####
________________________________________
From: [hidden email] <[hidden email]> on behalf of Eliot Moss <[hidden email]>
Sent: Wednesday, April 20, 2016 8:52 AM
To: [hidden email]
Subject: Re: git and absolute Windows-style paths

On 4/20/2016 11:44 AM, silverwind wrote:

> Hey,
>
>> Does it work if you do:
>>
>> git add c:/test/file
>
> Nope, won't work either. No file is added, exit code 0 is given.
>
>  > I can't immediately see what's going wrong, so I'm going to report this upstream.
>
> Thanks. I came upon this issue through npm which is using these Windows paths for certain git
> operations. Unfortunately, The npm team is very reluctant when it comes to merging Cygwin-specific
> patches, so chances of landing a fix on their side are rather slim.
>
> Is there a public repository for the git package used by Cygwin?

I think that tackling this with a script/function is a better approach ...

Eliot Moss

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: git and absolute Windows-style paths

silverwind
In reply to this post by Eliot Moss
Hey,

> I think that tackling this with a script/function is a better approach ...

That's seems like a bandaid solution from which the general user base
would not be able to profit. I think a floating patch to Cygwin's git
package would be more appropriate, unless it can be addressed in
Cygwin's system calls (which I'm sure has been attempted).

Why can I

   cat c:\\file.txt

but can't

   git add c:\\file.txt

? Where is this path normalization magic happening?

Regards,
Roman

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: git and absolute Windows-style paths

Adam Dinwoodie-2
In reply to this post by silverwind
On Wed, Apr 20, 2016 at 05:44:47PM +0200, silverwind wrote:
> > I can't immediately see what's going wrong, so I'm going to report
> this upstream.
>
> Thanks. I came upon this issue through npm which is using these
> Windows paths for certain git operations. Unfortunately, The npm
> team is very reluctant when it comes to merging Cygwin-specific
> patches, so chances of landing a fix on their side are rather slim.
>
> Is there a public repository for the git package used by Cygwin?

The main Git repository[0] includes a bunch of Cygwin specific code
already, and I maintain a repository of the packaging paraphernalia[1]
which includes a couple of patches that aren't yet in the upstream code.

[0]: https://git.kernel.org/cgit/git/git.git/
[1]: http://github.com/me-and/Cygwin-Git

On Wed, Apr 20, 2016 at 06:21:53PM +0200, silverwind wrote:
> I think a floating patch to Cygwin's git
> package would be more appropriate, unless it can be addressed in
> Cygwin's system calls (which I'm sure has been attempted).

As the Git maintainer for Cygwin, I'm not willing to maintain a
downstream patch to make Cygwin Git handle Windows-style paths, and I
don't think there's much chance of one being accepted into the upstream
Git source code (although you're obviously welcome to try getting such a
patch accepted).

If you need to be able to pass Windows-style paths to Cygwin
applications, you should write a wrapper function or script that calls
`cygpath` to do the conversion.  Anything else is liable to work
intermittently at best; Cygwin applications in general expect
POSIX-style paths, given the aim of the Cygwin project is to provide a
POSIX-like environment.

Adam

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: git and absolute Windows-style paths

Ernie Rael
In reply to this post by Brian Clifton
On 4/20/2016 9:10 AM, Brian Clifton wrote:

> I agree completely-
>
> Faking out git by wrapping it as a function in your .bashrc would be an ideal approach.  I was the person championing that PR which got rejected, unfortunately. The NPM folks were recommending to use mingw which *is* supported... but I haven't seen any updates to that project since 2013... and I prefer the approach Cygwin takes :)
>
> Eliot, I would be all about taking you up on fixing that psuedo-code example I shared earlier. I have a lot to learn about shell scripting and while I am sure I can figure it out, having help would be extremely appreciated :)
>
> The example I shared in my intro thread:
> #####
> function git {
>      for var in "$@"
>      do
>          if [[ $var == *":\\"* ]]; then
>              $var="$(cygpath $var)" #this doesn't work, but the idea is to do something like this
>          fi
>      done
>      command git "$@"
> }
> #####

This extract from a bash function, using an array assignment, might be
of interest.

       IFS=$'\n'
       args=($(cygpath -m -- "$@"))
       IFS=$' \t\n'
       gvim "${args[@]}"

> ________________________________________
> From: [hidden email] <[hidden email]> on behalf of Eliot Moss <[hidden email]>
> Sent: Wednesday, April 20, 2016 8:52 AM
> To: [hidden email]
> Subject: Re: git and absolute Windows-style paths
>
> On 4/20/2016 11:44 AM, silverwind wrote:
>> Hey,
>>
>>> Does it work if you do:
>>>
>>> git add c:/test/file
>> Nope, won't work either. No file is added, exit code 0 is given.
>>
>>   > I can't immediately see what's going wrong, so I'm going to report this upstream.
>>
>> Thanks. I came upon this issue through npm which is using these Windows paths for certain git
>> operations. Unfortunately, The npm team is very reluctant when it comes to merging Cygwin-specific
>> patches, so chances of landing a fix on their side are rather slim.
>>
>> Is there a public repository for the git package used by Cygwin?
> I think that tackling this with a script/function is a better approach ...
>
> Eliot Moss
>
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>
>
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>
>
>


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: git and absolute Windows-style paths

Eliot Moss
In reply to this post by Brian Clifton
I think this will do it:

function git {
   declare -a ARGS
   for n in "$@" ; do ARGS+=("$(cygpath -u -- "${n}")") ; done
   command git "${ARGS[@]}"
}

The reason this is a little more complicated than some other approaches
might be is that it will also work for arguments that have space, e.g.,

git add "C:/My Documents/foo.doc"

Regards -- Eliot

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: git and absolute Windows-style paths

Adam Dinwoodie-2
On Wed, Apr 20, 2016 at 04:37:34PM -0400, Eliot Moss wrote:

> I think this will do it:
>
> function git {
>   declare -a ARGS
>   for n in "$@" ; do ARGS+=("$(cygpath -u -- "${n}")") ; done
>   command git "${ARGS[@]}"
> }
>
> The reason this is a little more complicated than some other approaches
> might be is that it will also work for arguments that have space, e.g.,
>
> git add "C:/My Documents/foo.doc"

For a marginally simpler, or at least shorter, version, use `for n; do
...` rather than `for n in "$@"; do` -- Bash loops over positional
arguments by default if you don't specify a list with `in`.

Perfect for confusing anyone else (or indeed yourself at some point in
the future) who isn't familiar with the many, many idiosyncrasies of
shell languages.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: git and absolute Windows-style paths

Ernie Rael
In reply to this post by Eliot Moss
On 4/20/2016 1:37 PM, Eliot Moss wrote:

> I think this will do it:
>
> function git {
>   declare -a ARGS
>   for n in "$@" ; do ARGS+=("$(cygpath -u -- "${n}")") ; done
>   command git "${ARGS[@]}"
> }
>
> The reason this is a little more complicated than some other approaches
> might be is that it will also work for arguments that have space, e.g.,
>
> git add "C:/My Documents/foo.doc"

Notice that
    IFS=$'\n'; args=($(cygpath -m -- "$@")); IFS=$' \t\n'
also handles arguments with spaces. You don't need the shell for loop.

-ernie

>
> Regards -- Eliot
>
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>
>
>


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: git and absolute Windows-style paths

Eliot Moss
On 4/20/2016 7:14 PM, Ernie Rael wrote:

> On 4/20/2016 1:37 PM, Eliot Moss wrote:
>> I think this will do it:
>>
>> function git {
>>   declare -a ARGS
>>   for n in "$@" ; do ARGS+=("$(cygpath -u -- "${n}")") ; done
>>   command git "${ARGS[@]}"
>> }
>>
>> The reason this is a little more complicated than some other approaches
>> might be is that it will also work for arguments that have space, e.g.,
>>
>> git add "C:/My Documents/foo.doc"
>
> Notice that
>     IFS=$'\n'; args=($(cygpath -m -- "$@")); IFS=$' \t\n'
> also handles arguments with spaces. You don't need the shell for loop.

Ok ... but I would save the previous value of IFS and restore it -- never
know what a user might be using there ...

Best -- E

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: git and absolute Windows-style paths

Ray Donnelly
Here's a patch for git 2.8.1 that I wrote for MSYS2 to address the
same issue. Because I'd read this thread before I started working on
it (and generally since it's good to) I kept it in mind to make it
work for Cygwin in-case you wanted to use it:

https://raw.githubusercontent.com/Alexpux/MSYS2-packages/6b7aceea4ad2e5bd28143a2de8c4a0d7453013dc/git/git-2.8.1-Cygwin-Allow-DOS-paths.patch

I'm running the test-suite now which takes an age, but I don't see any
problems with it so far. I didn't add any tests covering using DOS
paths though. I've tested it with git add and clone with DOS relative
and absolute paths.

Best regards,

Ray.

On Thu, Apr 21, 2016 at 12:40 AM, Eliot Moss <[hidden email]> wrote:

> On 4/20/2016 7:14 PM, Ernie Rael wrote:
>>
>> On 4/20/2016 1:37 PM, Eliot Moss wrote:
>>>
>>> I think this will do it:
>>>
>>> function git {
>>>   declare -a ARGS
>>>   for n in "$@" ; do ARGS+=("$(cygpath -u -- "${n}")") ; done
>>>   command git "${ARGS[@]}"
>>> }
>>>
>>> The reason this is a little more complicated than some other approaches
>>> might be is that it will also work for arguments that have space, e.g.,
>>>
>>> git add "C:/My Documents/foo.doc"
>>
>>
>> Notice that
>>     IFS=$'\n'; args=($(cygpath -m -- "$@")); IFS=$' \t\n'
>> also handles arguments with spaces. You don't need the shell for loop.
>
>
> Ok ... but I would save the previous value of IFS and restore it -- never
> know what a user might be using there ...
>
> Best -- E
>
>
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: git and absolute Windows-style paths

Ray Donnelly
On Thu, Apr 21, 2016 at 2:11 PM, Ray Donnelly <[hidden email]> wrote:

> Here's a patch for git 2.8.1 that I wrote for MSYS2 to address the
> same issue. Because I'd read this thread before I started working on
> it (and generally since it's good to) I kept it in mind to make it
> work for Cygwin in-case you wanted to use it:
>
> https://raw.githubusercontent.com/Alexpux/MSYS2-packages/6b7aceea4ad2e5bd28143a2de8c4a0d7453013dc/git/git-2.8.1-Cygwin-Allow-DOS-paths.patch
>
> I'm running the test-suite now which takes an age, but I don't see any
> problems with it so far. I didn't add any tests covering using DOS
> paths though. I've tested it with git add and clone with DOS relative
> and absolute paths.

FYI, the test results were the same before and after this patch.

>
> Best regards,
>
> Ray.
>
> On Thu, Apr 21, 2016 at 12:40 AM, Eliot Moss <[hidden email]> wrote:
>> On 4/20/2016 7:14 PM, Ernie Rael wrote:
>>>
>>> On 4/20/2016 1:37 PM, Eliot Moss wrote:
>>>>
>>>> I think this will do it:
>>>>
>>>> function git {
>>>>   declare -a ARGS
>>>>   for n in "$@" ; do ARGS+=("$(cygpath -u -- "${n}")") ; done
>>>>   command git "${ARGS[@]}"
>>>> }
>>>>
>>>> The reason this is a little more complicated than some other approaches
>>>> might be is that it will also work for arguments that have space, e.g.,
>>>>
>>>> git add "C:/My Documents/foo.doc"
>>>
>>>
>>> Notice that
>>>     IFS=$'\n'; args=($(cygpath -m -- "$@")); IFS=$' \t\n'
>>> also handles arguments with spaces. You don't need the shell for loop.
>>
>>
>> Ok ... but I would save the previous value of IFS and restore it -- never
>> know what a user might be using there ...
>>
>> Best -- E
>>
>>
>> --
>> Problem reports:       http://cygwin.com/problems.html
>> FAQ:                   http://cygwin.com/faq/
>> Documentation:         http://cygwin.com/docs.html
>> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>>

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Reply | Threaded
Open this post in threaded view
|

Re: git and absolute Windows-style paths

Andrey Repin
In reply to this post by Adam Dinwoodie-2
Greetings, Adam Dinwoodie!

> On Wed, Apr 20, 2016 at 04:37:34PM -0400, Eliot Moss wrote:
>> I think this will do it:
>>
>> function git {
>>   declare -a ARGS
>>   for n in "$@" ; do ARGS+=("$(cygpath -u -- "${n}")") ; done
>>   command git "${ARGS[@]}"
>> }
>>
>> The reason this is a little more complicated than some other approaches
>> might be is that it will also work for arguments that have space, e.g.,
>>
>> git add "C:/My Documents/foo.doc"

> For a marginally simpler, or at least shorter, version, use `for n; do
> ...` rather than `for n in "$@"; do` -- Bash loops over positional
> arguments by default if you don't specify a list with `in`.

> Perfect for confusing anyone else (or indeed yourself at some point in
> the future) who isn't familiar with the many, many idiosyncrasies of
> shell languages.

There's no chance you could confuse anyone with this functionality, as it is
mandated by POSIX.


--
With best regards,
Andrey Repin
Thursday, April 21, 2016 19:33:42

Sorry for my terrible english...


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple