代码之家  ›  专栏  ›  技术社区  ›  Marc W

mercurial hook执行不正确

  •  7
  • Marc W  · 技术社区  · 17 年前

    这应该是一个运行起来非常简单的事情,但是由于某种原因,它不能与我的Mercurial存储库一起工作。我只想让远程回购自动运行 hg update 每当有人推它。所以我的.hg/hgrc文件中有这个:

    [hook]
    changegroup = hg update
    

    简单,对吧?但出于某种原因,这永远不会执行。我还试着写一个这样的shell脚本。.hg/hgrc如下所示:

    [hooks]
    changegroup = /home/marc/bin/hg-update
    

    hg更新如下:

    #!/bin/sh
    hg help >> /home/marc/works.txt;
    hg update >> /home/marc/works.txt;
    exit 0;
    

    但同样,这不会更新。内容 hg help 写给 works.txt 但是没有写出来 汞更新 . 有什么明显的我不见了吗?这让我苦恼了好几天,但我似乎无法让它发挥作用。

    更新

    好的,所以再次使用 -v 从我的工作站打开命令行,将其推到远程repo不会打印任何详细消息,即使我有这些消息。 echo 线在 .hg/hgrc . 但是,当我从同一个文件系统上的repo克隆进行推送时(我通过ssh登录),我得到的是:

    bash-3.00$ hg -v push ../test-repo/
    pushing to ../test-repo/
    searching for changes
    1 changesets found
    running hook prechangegroup: echo "Remote repo is at `hg tip -q`"
    echo "Remote repo wdir is at `hg parents -q`"
    Remote repo is at 821:1f2656753c98
    Remote repo wdir is at 821:1f2656753c98
    adding changesets
    adding manifests
    adding file changes
    added 1 changesets with 1 changes to 1 files
    running hook changegroup: echo "Updating.... `hg update -v`"
    echo "Remote repo is at `hg tip -q`"
    echo "Remote repo wdir is at `hg parents -q`"
    Updating.... resolving manifests
    getting license.txt
    1 files updated, 0 files merged, 0 files removed, 0 files unresolved
    Remote repo is at 822:389a6c7276c6
    Remote repo wdir is at 822:389a6c7276c6
    

    所以它可以工作,但同样只有当我从同一个文件系统推送时。如果我尝试通过网络从另一个工作站推到repo,它就不起作用。

    9 回复  |  直到 9 年前
        1
  •  10
  •   Vadim Kotov First Zero    9 年前

    我自己花了一些时间研究这个问题。我认为问题的答案描述得很简洁 here :

    输出必须重定向到stderr(或/dev/null),因为stdout 用于数据流。

    基本上,您不会重定向到stderr,因此会污染stdout。

        2
  •  10
  •   smf68    16 年前

    好吧,在经历了和Marc W前一段时间同样的挫折之后,我终于找到了解决问题的方法,至少当远程服务用hgwebdir wsgi脚本完成时。

    我发现,当通过HTTP或HTTPS使用这种远程推送时,Mercurial只会忽略您写入.hg/hgrc文件或存储库中的所有内容。但是,进入钩子 在hgwebdir配置中 做这个把戏。

    所以如果你的底线 HGWebDR.WSGI 脚本类似于

    application = hgwebdir('hgweb.config')
    

    [hooks]配置部分需要进入上述 HgWeb.CONFIG .

    一个缺点是这些钩子是为 每个存储库 列在该配置的[路径]部分。尽管hg提供了另一个支持wsgi的函数(hgweb而不是hgwebdir),只为一个存储库服务,但它似乎不支持任何挂钩(它也没有任何配置)。 但是,可以通过使用上面描述的hgwebdir并让一些apache rewriterule将所有内容映射到所需的子目录中来规避这一点。这个适合我:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/reponame
    RewriteRule ^(.*)$ reponame/$2 [QSA]
    

    在http:d上使用远程钩子玩得开心

        3
  •  3
  •   Aamir    17 年前

    首先,我想更正上面的一些评论。

    • 在推送文件系统时也会调用挂钩。
    • 你不需要把钩子放在你想让他们操作的回购中。您也可以在用户端编写与问题相同的钩子。您必须将事件从changegroup更改为outgoing,还必须使用-r开关指定远程repo的URL。然后,如果推送用户在远程回购上有足够的权限,钩子将成功执行。

    Hg/HGRC

    [hooks]
    outgoing = hg update -R $HG_URL
    

    现在向你的问题……我建议创建prechangegroup和changegroup挂钩,并打印一些调试输出。

    Hg/HGRC

    [hooks]
    prechangegroup = echo "Remote repo is at `hg tip -q`"
                     echo "Remote repo wdir is at `hg parents -q`"
    changegroup    = echo "Updating.... `hg update -v`"
                     echo "Remote repo is at `hg tip -q`"
                     echo "Remote repo wdir is at `hg parents -q`"
    

    同时按下-v开关,这样你就可以知道哪个钩子在运行。如果您仍然无法确定,请发布输出。我也许能帮上忙。

        4
  •  3
  •   flowblok    14 年前

    我的问题是,我的hgwebdir应用程序以“hg”用户的身份运行,但存储库归我所有,所以我必须将这个配置添加到hgweb.config中,才能让它运行钩子:

    [trusted]
    users = me
    
        5
  •  2
  •   Macke    17 年前

    你需要把它放在 遥远的 休息区的HGRC。听起来好像是在你的本地回购中。

    编辑:这也取决于你是如何推动的。有些方法不调用右侧的挂钩。(ssh可以,我认为http可以,文件系统可以 )

    如果你在远程回购的电脑上按“本地”怎么办?在webserver和hgrc文件之间,您可能拥有不同的用户/权限。(请参阅[Server]和HGRC的可信指令。)

        6
  •  2
  •   EdChum Arthur G    14 年前

    我在通过HTTP从WindowsEclipse推送时遇到了同样的问题,但是在捕获了stderr之后,我发现hg.bat文件需要完整的路径。我的钩部分现在看起来像:

    [hooks]
    incoming = c:\Python27\Scripts\hg.bat update > hg_log.txt 2>>hg_err.txt
    

    希望这能帮助别人。 斯蒂威

        7
  •  1
  •   John Weldon user3678248    17 年前

    尝试 turning on hook debugging 看看它为什么不跑。

    可能是权限问题或类似的问题。

        8
  •  1
  •   Pete Brumm    15 年前

    花了一段时间,但我成功了。

    我从开始

    [hooks]
    tag=set >&2
    commit=set >&2
    

    >&2将其传输到标准错误,以便远程控制台显示它。

    远程时,如果控制台正在运行,则应在控制台中输出

    hg push https://host/hg   -v
    

    事实并非如此。

    我使用的是hgweb.cgi,所以我切换到了hgweb.wsgi,没有区别。

    我发现有些钩子在遥控器上不会被呼叫。

    当我切换到

    [hooks]
    incoming= set >&2
    

    hooks标记和commit似乎没有被调用,但是incoming和changeset确实被调用。我还没有确认其他人。

    现在我开始工作了,我切换回hgweb.cgi,所有的工作都是一样的。

        9
  •  1
  •   arhak Martin Nycander    10 年前

    我发现这与重定向无关。 stdout stderr . 正如您在wiki页面中看到的,它没有在wiki的当前版本中指定。 https://www.mercurial-scm.org/wiki/FAQ#FAQ.2FCommonProblems.Any_way_to_.27hg_push.27_and_have_an_automatic_.27hg_update.27_on_the_remote_server.3F

    我发现的问题就在附近 权限 .

    在我最初的设置中,我有一个用户,比如说 hguser 在它的家里有一个回购协议和一个脚本 /etc/init.d/hg.init 发射 hg serve . 问题是 HG发球 正在被运行 root ,而报告中的大多数文件都与 高格用户 (他们中的一些转到了 在某一点上,但不介意,因为我会用 chown )

    解决方案:

    • chown -R hguser:hguser /home/hguser/repo (要更正所有文件,请返回hguser)
    • 发射 su hguser -c "hg serve ..." (就我而言,从 /等/init.d/hg.init )
    • changegroup = hg update -C 在下面 [hooks] 在里面 repo/.hg/hgrc 像往常一样

    现在应该开始工作了 push

    PS:在我的例子中,我宁愿更新到特定分支的头,所以我使用 hg update -C -r staging ,使临时服务器仅更新到目标分支的头,即使 tip 来自另一个分支(比如 development 例如)

    顺便说一句 hg.init 脚本的结尾是这样的:(注意 su hguser 部分)

    #!/bin/sh
    #
    # Startup script for mercurial server.
    #
    # @see http://jf.blogs.teximus.com/2011/01/running-mercurial-hg-serve-on-linux.html
    
    HG=/usr/bin/hg
    CONF=/etc/mercurial/hgweb.config
    # Path to PID file of running mercurial process.
    PID_FILE=/etc/mercurial/hg.pid
    
    state=$1
    
    case "$state" in
    'start')
        echo "Mecurial Server service starting."
        (su hguser -c "${HG} serve -d --webdir-conf ${CONF} -p 8000 --pid-file ${PID_FILE}")
      ;;
    
    'stop')
      if [ -f "${PID_FILE}" ]; then
        PID=`cat "${PID_FILE}"`
        if [ "${PID}" -gt 1 ]; then
          kill -TERM ${PID}
          echo "Stopping the Mercurial service PID=${PID}."
        else
          echo Bad PID for Mercurial -- \"${PID}\"
        fi
      else
    
        echo No PID file recorded for mercurial
      fi
      ;;
    
    *)
      echo "$0 {start|stop}"
      exit 1
      ;;
    esac
    

    PS:应付账款 http://jf.blogs.teximus.com/2011/01/running-mercurial-hg-serve-on-linux.html

    推荐文章