[英]Mercurial (HG) pull parameters: username and password
I have to write a script that automates pulling from a mercurial repo. 我必须编写一个脚本,自动从一个mercurial repo中提取。 Is there anyway I can perform an hg pull -u
that includes passing the requested username and password in the same command? 无论如何我可以执行一个hg pull -u
,包括在同一个命令中传递请求的用户名和密码? I know there's an interactive method which is the default behaviour, and I don't want to save the username and password in hgrc or elsewhere because it will be used by multiple users, so is there a way to pass the username and password via the command line? 我知道有一个交互式方法是默认行为,我不想在hgrc或其他地方保存用户名和密码,因为它将由多个用户使用,所以有没有办法通过用户名和密码传递命令行? I tried using proc_open
in PHP but that wasn't working as well as echoing out to STDIN. 我尝试在PHP中使用proc_open
,但这并不像回应STDIN那样有效。
I found two solutions: 我找到了两个解决方案
1. Explicitly provide the URL, including full credentials: 1.明确提供URL,包括完整凭据:
hg pull -u https://user:pass@host/path
2. Provide the credentials with --config, using * as a prefix (from Victor's answer): 2.使用--config提供凭证,使用*作为前缀(来自Victor的答案):
hg pull -u --config auth.x.prefix=* --config auth.x.username=user --config auth.x.password=pass
Passing the password on the command line is insecure since other users can see it using ps
and similar. 在命令行上传递密码是不安全的,因为其他用户可以使用ps
和类似的东西看到它。 What you should do is either: 你应该做的是:
Communicate with hg
on the pipes you get back from proc_open
. 在从proc_open
返回的管道上与hg
通信。 You'll need to carefully parse the output from Mercurial and feed it the username and password on stdin. 您需要仔细解析Mercurial的输出并在stdin上输入用户名和密码。 Run Mercurial as: 将Mercurial运行为:
hg --config ui.interactive=yes
to make sure that it will talk to you — otherwise I'm afraid that it detects that there is no TTY and wont prompt you at all. 确保它会与你交谈 - 否则我担心它会检测到没有TTY并且根本不会提示你。
Write a temporary configuration file with an [auth]
section . 使用[auth]
部分编写临时配置文件。 It will look like this: 它看起来像这样:
[auth] x.prefix = output of "hg paths default" x.username = USERNAME x.password = PASSWORD
(The x
is not important, it can be anything.) Make sure that the file is only readable by the user you're running the script as. ( x
并不重要,它可以是任何东西。)确保该文件只能由您运行脚本的用户读取。 Then set the HGRCPATH
environment variable to point to the file and execute Mercurial. 然后将HGRCPATH
环境变量设置为指向该文件并执行Mercurial。 Delete the file when you're done! 完成后删除文件!
There is a libhg PHP library for the command server , but I don't see anything about usernames or passwords for pull or clone in that library. 有一个libhg PHP库用于命令服务器 ,但我没有看到任何关于该库中的pull或clone的用户名或密码。 The library is work in progress, but when it's more mature I suggest using it. 该库正在进行中,但是当它更成熟时,我建议使用它。 But for now the above approaches should help you along. 但是现在上述方法应该可以帮助你。
Solution 2 is specific to a repository. 解决方案2特定于存储库。 Do 做
[auth]
x.prefix = *
x.username = USERNAME
x.password = PASSWORD
to make it apply to all repositories. 使其适用于所有存储库。 Also, if you put this in "~/.hgrc" and give that permission of 600 you don't have to do the HGRCPATH trick. 此外,如果你把它放在“〜/ .hgrc”并给予600的许可,你就不必做HGRCPATH技巧了。 Just leave it there. 把它留在那里吧。
这工作:
hg --config auth.rc.prefix=http://host/ --config auth.rc.username=user --config auth.rc.password=password pull -u http://host/full/path/to/repo
You might be able to use the --config
switch to do that like this: 您可以使用--config
开关来执行以下操作:
hg --config auth.username=USERNAME --config auth.password=PASSWORD pull -u
I personally have never done this, but hopefully this helps. 我个人从未这样做过,但希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.