Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows git-worktree cannot read the /c/path syntax (a worktree created by cygwin git) #1946

Closed
lefth opened this issue Nov 22, 2018 · 4 comments
Labels

Comments

@lefth
Copy link

lefth commented Nov 22, 2018

  • I found no similar reported issue
  • I am using 2.19.2.windows.1 and cygwin git version 2.17.0
  • I am using Windows 10 home [Version 10.0.17134.407]
  • I installed Git for Windows with the default options, except enabling symlinks
$ '/d/Program Files/Git/bin/git.exe' --version --build-options
git version 2.19.2.windows.1
cpu: x86_64
built from commit: 26dcaa1b6b5fd862db3ec40983e33ff3432f1166
sizeof-long: 4
sizeof-size_t: 8
Editor Option: VIM
Custom Editor Path:
Path Option: Cmd
SSH Option: OpenSSH
CURL Option: OpenSSL
CRLF Option: CRLFCommitAsIs
Bash Terminal Option: MinTTY
Performance Tweaks FSCache: Enabled
Use Credential Manager: Enabled
Enable Symlinks: Enabled

Details

A worktree created by Cygwin's Git cannot be used by Git for Windows. This comes up because it's a reasonable workflow to use Git for Windows and Cygwin Git tools at the same time, for example to use the Windows GUI tools but Cygwin for everything else. This issue will also affect repositories on dual-boot systems if the user tries to use a worktree from both OSs.

Cygwin's Git cannot read a Windows-style path, and Git for Windows cannot read a POSIX path. Since the release notes say Git for Windows usually tries to recognize POSIX paths, the most obvious solution is for Git to also recognize POSIX paths in this case. Note: the path is written in

  • What commands did you run to trigger this issue?
$ mkdir testcase
$ cd testcase/
$ /usr/bin/git init
Initialized empty Git repository in /f/Projects/testcase/.git/

Note: the steps and results are identical if I initialize in /cygdrive/f/Projects/testcase/. The folders are the same, and the POSIX version of the path points to the same directory as the Cygwin path.

$ /usr/bin/git commit -m "First commit" --allow-empty
[master (root-commit) d81570d] First commit
$ /usr/bin/git worktree add my-worktree
Preparing my-worktree (identifier my-worktree)
HEAD is now at d81570d First commit
$ cd my-worktree
$ '/d/Program Files/Git/bin/git.exe' status
  • What did you expect to occur after running these commands?
On branch my-worktree
nothing to commit, working tree clean
  • What actually happened instead?

fatal: not a git repository: /f/Projects/testcase/.git/worktrees/my-worktree

The file which lists the path is:

$ cat /f/Projects/testcase/my-worktree/.git
gitdir: /f/Projects/testcase/.git/worktrees/my-worktree
@dscho
Copy link
Member

dscho commented Nov 22, 2018

I fear that this will never by a use case supported by Git for Windows: you have modified your Cygwin setup to not use the /cygdrive/ prefix. So your setup is really too special to special-case in a software that tries to cater to millions of users.

What you could do is to create the worktree using Git for Windows instead of Cygwin Git. Cygwin can handle paths of the form F:/Projects/testcase/.git/worktrees/my-worktree, which is exactly what Git for Windows would have written to the .git file.

@dscho dscho closed this as completed Nov 22, 2018
@dscho dscho added the question label Nov 22, 2018
@lefth
Copy link
Author

lefth commented Nov 23, 2018

@dscho Sorry, my path indeed did not start with /cygdrive/DRIVE. I tested, and the result is the same whether I use a POSIX or Cygwin path. Both are valid and point at the same repository, due to a bind mount. Furthermore, this is a necessary change to support repositories on external drives and dual-boot systems. Would you re-open it if you find it worthwhile to support these cases? I suspect many people use both a Windows Git and a Unix-style Git.

The reason I used a "/c" style path is that this is the POSIX variant. According to your release notes, Git tries to understand that path in most cases. I am just suggesting you extend that to one more situation. Supporting "/cygdrive/c" would be a hack, but supporting "/c" would be a further step along the path you've chosen. Yes, in that case there would be a burden on Cygwin users to make a bind mount that would make it work from Cygwin. But it's Git's job to read (POSIX) paths, not to ensure that the path actually exists.

Workaround for Cygwin (but not Git on Linux): I just discovered both Windows Git and Cygwin Git can read the following type of path:
gitdir: //?/F:/Projects/testcase/.git/worktrees/my-worktree

@lefth
Copy link
Author

lefth commented Nov 23, 2018

Note: my workaround does not work, because git rebase --interactive (or perhaps the default editor, gVim) does not support that path. git rebase --interactive prints "hint: Waiting for your editor to close the file..." and hangs. The editor does not open.

It seems POSIX-style relative paths work. I'm not yet sure if it causes any other problem.

@tboegi
Copy link

tboegi commented Nov 23, 2018

Does gVim support this path:
F:/Projects/testcase/.git/worktrees/my-worktree
If yes, it may be possible to update Git so that cygwin understands a DOS path.
If you want to work on it, this may help:
https://public-inbox.org/git/[email protected]/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants