英文:
Cygwin uses relative and absolute path for environment variables
问题
当我在Cygwin中使用以下命令时:
$ go get github.com/gorilla/mux
我收到以下错误:
# cd .; git clone https://github.com/gorilla/mux C:\cygwin64\home\USER\Go\src\github.com\gorilla\mux
正在克隆到 'C:\cygwin64\home\USER\Go\src\github.com\gorilla\mux'...
fatal: 无效路径 '/home/USER/C:\cygwin64\home\USER\Go\src\github.com\gorilla\mux':没有这样的文件或目录
package github.com/gorilla/mux: 退出状态 128
当我使用命令:
cd $GOPATH
正确的文件夹会打开。
有人知道我如何解决这个问题吗?
英文:
When I use the below command in Cygwin:
$ go get github.com/gorilla/mux
I receive the below error:
# cd .; git clone https://github.com/gorilla/mux C:\cygwin64\home\USER\Go\src\github.com\gorilla\mux
Cloning into 'C:\cygwin64\home\USER\Go\src\github.com\gorilla\mux'...
fatal: Invalid path '/home/USER/C:\cygwin64\home\USER\Go\src\github.com\gorilla\mux': No such file or directory
package github.com/gorilla/mux: exit status 128
When I use the command:
cd $GOPATH
The correct folder opens.
Does anyone how I can solve this?
答案1
得分: 1
请尝试使用安装了Git 2.21(2019年第一季度)的相同命令。
参见提交1cadad6(2018年12月15日)由Torsten Bögershausen(tboegi
)进行的更改。受到Johannes Schindelin(dscho
)的帮助。
>## git clone <url> C:\cygwin\home\USER\repo
现在可以正常工作了
>在提交05b458c(2012年12月,Git v2.12.0-rc0)中引入了一个针对cygwin用户的回归问题,即“real_path
:手动解析符号链接”。
(有关原始提交的更多信息,请参见“如何在主存储库及其所有子模块中使用git grep
?”)
>在提交消息中,我们可以看到:
> > 当前的real_path
实现使用chdir()
来解析符号链接。不幸的是,这不是线程安全的,因为chdir()
会影响整个进程...
>旧的(非线程安全的)操作系统调用chdir()
/pwd()
已被字符串操作替换。
cygwin层“知道”“C:\cygwin
”是一个绝对路径,但新的字符串操作不知道。
>git clone <url> C:\cygwin\home\USER\repo
会失败,显示以下错误消息:
fatal: Invalid path '/home/USER/repo/C:\cygwin\home/USER/repo';
(这是与原帖中提到的错误消息类似的错误消息)
>解决方法是在cygwin中实现has_dos_drive_prefix()
、skip_dos_drive_prefix()
、is_dir_sep()
、offset_1st_component()
和convert_slashes()
,并以与“Git for Windows”中的compat/mingw.[ch]
相同的方式使用它。
>将所需的代码提取到compat/win32/path-utils.[ch]
中,并在cygwin中使用它。
注意:Git 2.22(2019年第二季度)进一步改进了该命令,因为之前的更新意外破坏了MSVC构建,这个问题已经修复。
参见提交22c3634(2019年4月8日)由Sven Strickroth(apotek
)进行的更改。
>## MSVC:对于MSVC,也要包含compat/win32/path-utils.h
以进行real_path()
。
>例如,路径c:/somepath/submodule/../.git/modules/submodule
无法正确解析,因为使用了*nix版本的offset_1st_component
而不是特定于Win32的版本。
>在提交1cadad6中引入了回归问题,当时mingw_offset_1st_component
从mingw.c
移动到了一个单独的文件中。然后,在git-compat-util.h
中,只为__CYGWIN__
和__MINGW32__
的情况包含了新文件“compat/win32/path-utils.h
”,而缺少了_MSC_VER
的情况。
另外:
>## git clone <url> C:\cygwin\home\USER\repo
现在可以正常工作了
>在提交05b458c(2016年12月,Git v2.12.0-rc0)中引入了一个针对cygwin用户的回归问题,即“real_path:手动解析符号链接”。
>在提交消息中,我们可以看到:
> > 当前的real_path
实现使用chdir()
来解析符号链接。不幸的是,这不是线程安全的,因为chdir()
会影响整个进程...
>旧的(非线程安全的)操作系统调用chdir()
/pwd()
已被字符串操作替换。
cygwin层“知道”“C:\cygwin
”是一个绝对路径,但新的字符串操作不知道。
>git clone <url> C:\cygwin\home\USER\repo
会失败,显示以下错误消息:
> fatal: Invalid path '/home/USER/repo/C:\cygwin\home/USER/repo';
>解决方法是在cygwin中实现has_dos_drive_prefix()
、skip_dos_drive_prefix()
、is_dir_sep()
、offset_1st_component()
和convert_slashes()
,并以与“Git for Windows”中的compat/mingw.[ch]
相同的方式使用它。
>将所需的代码提取到compat/win32/path-utils.[ch]
中,并在cygwin中使用它。
注意:通过在调用方进行一些代码重构,real_path()
便利函数很容易被误用。从Git 2.27(2020年第二季度)开始,已经消除了对它的使用。
参见提交49d3c4b、提交4530a85、提交3d7747e(2020年3月10日)和提交0915a5b(2020年3月6日)由Alexandr Miloslavskiy(SyntevoAlex
)进行的更改。
>## real_path
:删除不安全的API
> <sup>由Alexandr Miloslavskiy签署</sup>
>返回共享缓冲区会因可重入性或多线程而导致非常微妙的错误,正如之前的补丁所示。
>之前有一个未完成的努力来废除它。
>让我们最终摆脱real_path()
,改用strbuf_realpath()
。
>此补丁在大多数以前调用real_path()
的地方使用了本地的strbuf
。
>然而,有两个地方将real_path()
的值返回给调用者。对于它们,添加了一个static
本地的strbuf
,实际上将问题推高了一个级别:
> read_gitfile_gently()
get_superproject_working_tree()
英文:
Try the same command with Git 2.21 (Q1 2019) installed.
See commit 1cadad6 (15 Dec 2018) by Torsten Bögershausen (tboegi
).
Helped-by: Johannes Schindelin (dscho
).
<sup>(Merged by Junio C Hamano -- gitster
-- in commit 25d90d1, 14 Jan 2019)</sup>
> ## git clone <url> C:\cygwin\home\USER\repo
is working (again)
> A regression for cygwin users was introduced with commit 05b458c, Git v2.12.0-rc0, Dec. 2012, "real_path
: resolve symlinks by hand".
(See "How to git grep
the main repository and all its submodules?" for more on that original commit)
> In the the commit message we read:
> > The current implementation of real_path uses chdir()
in order to resolve symlinks. Unfortunately this isn't thread-safe as chdir()
affects a process as a whole...
> The old (and non-thread-save) OS calls chdir()
/pwd()
had been replaced by a string operation.
The cygwin layer "knows" that "C:\cygwin
" is an absolute path, but the new string operation does not.
> "git clone <url> C:\cygwin\home\USER\repo" fails like this:
fatal: Invalid path '/home/USER/repo/C:\cygwin\home\USER\repo'
(which is an error message similar to what the OP mentions)
> The solution is to implement has_dos_drive_prefix()
, skip_dos_drive_prefix()
is_dir_sep()
, offset_1st_component()
and convert_slashes()
for cygwin
in the same way as it is done in 'Git for Windows' in compat/mingw.[ch]
.
> Extract the needed code into compat/win32/path-utils.[ch]
and use it for cygwin as well.
Note: Git 2.22 (Q2 2019) further improves the command, as an earlier update for MinGW and Cygwin accidentally broke MSVC build, which has been fixed.
See commit 22c3634 (08 Apr 2019) by Sven Strickroth (apotek
).
<sup>(Merged by Junio C Hamano -- gitster
-- in commit 70542df, 08 May 2019)</sup>
> ## MSVC: include compat/win32/path-utils.h for MSVC, too, for real_path()
> A path such as 'c:/somepath/submodule/../.git/modules/submodule
' wasn't
resolved correctly any more, because the *nix variant of offset_1st_component
is used instead of the Win32 specific version.
> Regression was introduced in commit 1cadad6 when mingw_offset_1st_component
was moved from mingw.c
, which is included by msvc.c
to a separate file.
Then, the new file "compat/win32/path-utils.h
" was only included for the __CYGWIN__
and __MINGW32__
cases in git-compat-util.h
, the case for _MSC_VER
was missing.
And:
> ## git clone <url> C:\cygwin\home\USER\repo
is working (again)
> A regression for cygwin users was introduced with commit 05b458c, "real_path: resolve symlinks by hand", Dec. 2016, Git v2.12.0-rc0.
> In the the commit message we read:
> > The current implementation of real_path uses chdir() in order to resolve symlinks.
Unfortunately this isn't thread-safe as chdir() affects a process as a whole...
> The old (and non-thread-save) OS calls chdir()
/pwd()
had been
replaced by a string operation.
The cygwin layer "knows" that "C:\cygwin
" is an absolute path,
but the new string operation does not.
> "git clone <url> C:\cygwin\home\USER\repo
" fails like this:
> fatal: Invalid path '/home/USER/repo/C:\cygwin\home\USER\repo'
> The solution is to implement has_dos_drive_prefix()
, skip_dos_drive_prefix()
is_dir_sep()
, offset_1st_component()
and convert_slashes()
for cygwin
in the same way as it is done in 'Git for Windows' in compat/mingw.[ch]
> Extract the needed code into compat/win32/path-utils.[ch]
and use it
for cygwin as well.
Note: The real_path()
convenience function can easily be misused; with a bit of code refactoring in the callers' side, its use has been eliminated, with Git 2.27 (Q2 2020).
See commit 49d3c4b, commit 4530a85, commit 3d7747e (10 Mar 2020), and commit 0915a5b (06 Mar 2020) by Alexandr Miloslavskiy (SyntevoAlex
).
<sup>(Merged by Junio C Hamano -- gitster
-- in commit 4d0e899, 25 Mar 2020)</sup>
> ## real_path
: remove unsafe API
> <sup>Signed-off-by: Alexandr Miloslavskiy</sup>
> Returning a shared buffer invites very subtle bugs due to reentrancy or multi-threading, as demonstrated by the previous patch.
> There was an unfinished effort to abolish this.
> Let's finally rid of real_path()
, using strbuf_realpath()
instead.
> This patch uses a local strbuf
for most places where real_path()
was previously called.
> However, two places return the value of real_path()
to the caller. For them, a static
local strbuf
was added, effectively pushing the problem one level higher:
> read_gitfile_gently()
get_superproject_working_tree()
答案2
得分: 0
我认为这是因为你在本地和Cygwin中都安装了git。对我来说,在git命令提示符中运行go get
命令有所帮助。
英文:
I think this comes if you have git both installed locally and in cygwin. For me it helped running the go get
command in the git cmd
答案3
得分: 0
尽管使用Windows的git-bash.exe是一种解决方法,但有些人可能觉得在cygwin环境中保持一致性很重要。要在cygwin中使其正常工作,请按照以下步骤操作:
不要使用:
go get -u -v github.com/golang/example/hello
而是使用以下命令:
git clone https://github.com/golang/example $(cygpath -u $GOPATH)/src/github.com/golang/example
英文:
Although by using Windows' git-bash.exe is a work around, yet some might find it fundamental to stay in their cygwin environment. To make it work in cygwin, do this:
Instead of:
go get -u -v github.com/golang/example/hello
You need to instead do it by:
git clone https://github.com/golang/example $(cygpath -u $GOPATH)/src/github.com/golang/example
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论