Using Mercurial with Cygwin?

陌路散爱 提交于 2020-01-02 09:54:32

问题


We've been trying to use Mercurial with Cygwin (on Windows) but run into an error as Cygwin uses forward slashes and Mercurial seems to require backslashes. Is there a workaround?

Example of issue:

hg status 
M src\myfile.java

hg ci src\myfile.java   <-- Error: abort: srcmyfile.java: The system cannot find the file specified

??


回答1:


I don't have such a problem because I use two Mercurials:

  • mercurial bundled with TortoiseHG for use in windows cmd shell (usually I don't use it directly but it's used by TortoiseHG GUI tools).
  • cygwin's mercurial which I can use in cygwin.

You can safely use both of them because both versions store version history in the same .hg folder. Mercurial stores info about paths in .hg folder is some OS-independent way.

To be safe use the same version for both Mercurials.




回答2:


Add this to your .hgrc:

[ui]
slash = true

Now TortoiseHg will use proper slashes too:

C:> hg status
M src/myfile.java



回答3:


I solved a similar problem for bzr by using a shell script that converts the slashes using the cygpath command. It may require some tweaking for your needs, but here's my script:

#!/usr/bin/bash
COMMAND="/c/Python27/python.exe c:\\\\Python27\\\\Scripts\\\\bzr"
for i in "$@"
do
    COMMAND+=" "
    if [[ "$i" =~ ^- || "$i" =~ // ]]
    then
        COMMAND+="$i"
    else
        COMMAND+=$(cygpath -m "$i" | sed -e 's/ /\\ /g')
    fi
done
eval $COMMAND

It cycles through all the command line arguments. If it starts with a minus sign (bzr option), it just appends the argument as is. Otherwise, it runs it through cygpath and escapes all the spaces. I don't remember what the "$i" =~ // is for. It doesn't match up what I thought it was. Hope that helps.




回答4:


Ian Lewis suggests:

Uninstall the cygwin mercurial package and put TortoiseHG's path in my PATH environment variable (well it was already there) and everything's dandy. TortoiseHG just magically works on windows (though mercurial repos on the windows network are sloooooow). It's nice to be able to just type 'hg push' and have it work as well as "hg merge" the same way I do at home on my linux machine ("hg view" is "hgtk log" though).

Which amounts to "don't use cygwin's hg if your going to also use Tortoise HG", which seems like the best solution to me.



来源:https://stackoverflow.com/questions/4629617/using-mercurial-with-cygwin

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!