如何在汞的"push creates new remote head"周围写一个钩子?



我想做一个钩子,当有人推送到远程时,如果他们收到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

需要明确的是,未来不起作用的是合并两个头。我怎么知道哪个头是本地的,哪个头是远程的?

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

  1. 您可以尝试添加和使用 remotenames 扩展(它相当旧,自 2018 年以来没有积极维护,但可能会起作用(,以便在您的存储库中命名所有远程对等体(在这种情况下,您将在拉取后知道远程头的名称(
  2. 您可以(在拉动之前(检查传入的变更集中是否存在头部,就像

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

相关内容

最新更新