bash - 如何在 Mercurial 的 "push creates new remote head"周围编写一个钩子(Hook)?

标签 bash mercurial mercurial-hook

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

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

这是我一直在尝试的,尽管还没有完善。

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

需要明确的是, merge 两个头是行不通的。我如何知道哪个头是本地的,哪个头是远程的?

此外,这是使用正确的钩子(Hook)吗?

最佳答案

  1. 您可以尝试添加并使用 remotenames extension (它相当旧,自 2018 年以来就没有积极维护,但可能有效),以便让所有远程对等点在您的存储库中命名(在这种情况下,您将在拉取后知道远程头的名称) )
  2. 您可以(在拉取之前)检查传入的变更集中是否存在头部。喜欢

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

关于bash - 如何在 Mercurial 的 "push creates new remote head"周围编写一个钩子(Hook)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62456594/

相关文章:

mercurial - 如何为 Mercurial MQ 命令添加 Hook ?

bash - 颠倒单词但保持顺序 Bash

macos - 在 OS X 上停止 hg 服务

version-control - Mercurial - 我能做得更好吗?

mercurial - 如何在提交标签之前提交文件?

Mercurial:如何在changegroup Hook 中获取项目的根文件夹名称?

c - 使用 C 样式转义序列转义二进制文件

bash - Crontab 不执行 bash 脚本

bash - 通过 docker-compose 拉取 ssh-client 容器

Mercurial:从所有变更集中删除文件