【问题标题】:How do I write a hook around mercurial's "push creates new remote head"?如何围绕 mercurial 的“推送创建新的远程头”编写一个钩子?
【发布时间】:2020-06-18 18:06:02
【问题描述】:

我想做一个钩子,当有人推送到远程时,如果他们收到abort: push creates new remote head 错误消息,钩子将尝试合并远程和本地头(如果容易合并,即没有冲突的文件)并推送再次。

我该怎么做?我尝试在pre-push 上添加一个钩子,但我不知道如何仅获取当前分支的远程头部哈希。

这是我一直在尝试的,虽然它没有经过打磨。

currbranch=$(hg branch)
hg pull
numheads=$(hg heads --template "." $currbranch)
if test ${#numheads} -gt 1; then
    echo "Merge needed."
    head1=$(hg heads --template "{node}\n" $currbranch | head -n 1)
    head2=$(hg heads --template "{node}\n" $currbranch | tail -n 1)
    overlap=$((hg status --change $head1 --no-status ; hg status --change $head2 --no-status) | sort | uniq --repeated)
    if [ -z "$overlap" ]; then
        echo "Attempting automatic merge..."
        hg merge "$head1"  # Fails when merging the wrong head
        hg merge "$head2"  # But how do we know which one is wrong?
        hg commit -m "Merge"
        echo "Completed."
    else
        echo "Cannot automatically merge"
        exit 1
    fi
fi

需要明确的是,前面不起作用的是合并两个头。如何知道哪个头是本地的,哪个头是远程的?

另外,这是正确的钩子吗?

【问题讨论】:

    标签: bash mercurial mercurial-hook


    【解决方案1】:
    1. 您可以尝试添加和使用remotenames extension(它相当旧,自 2018 年以来没有积极维护,但可能会工作),以便在您的 repo 中命名所有远程对等点 /strong>(在这种情况下,您将在拉取后知道远程头的名称)
    2. 您可以(在拉取之前)检查传入的变更集中是否存在头部,smth。喜欢

    hg in -r "head()" -T "{node|short}\n"(待定!)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多