【问题标题】:hg archive to Remote Directoryhg 存档到远程目录
【发布时间】:2011-01-21 06:17:36
【问题描述】:

有没有办法通过 SSH 将 Mercurial 存储库归档到远程目录?例如,如果能做到以下几点就更好了:

hg archive ssh://user@example.com/path/to/archive

但是,这似乎不起作用。相反,它会在当前目录中创建一个名为 ssh: 的目录。

我制作了以下快速而简单的脚本,通过创建临时 ZIP 存档、通过 SSH 复制并解压缩目标目录来模拟所需行为。但是,我想知道是否有更好的方法。

if [[ $# != 1 ]]; then
  echo "Usage: $0 [user@]hostname:remote_dir"
  exit
fi

arg=$1

arg=${arg%/} # remove trailing slash
host=${arg%%:*}
remote_dir=${arg##*:}
# zip named to match lowest directory in $remote_dir
zip=${remote_dir##*/}.zip 

# root of archive will match zip name
hg archive -t zip $zip  
# make $remote_dir if it doesn't exist
ssh $host mkdir --parents $remote_dir
# copy zip over ssh into destination
scp $zip $host:$remote_dir  
# unzip into containing directory (will prompt for overwrite)
ssh $host unzip $remote_dir/$zip -d $remote_dir/..
# clean up zips
ssh $host rm $remote_dir/$zip 
rm $zip

编辑clone-and-push 比较理想,但不幸的是远程服务器没有安装 Mercurial。

【问题讨论】:

  • @Brett Daniel:我打算发布 Paul Nathan 发布的答案。简单的 "hg push ssh://user@example.com/hg/" 不适合你吗?

标签: mercurial ssh dvcs archive


【解决方案1】:

您也可以简单地在远程主机上执行 hg:

ssh user@example.com "cd /path/to/repo; hg archive -r 123 /path/to/archive"

【讨论】:

    【解决方案2】:

    我经常遇到类似的情况。我解决它的方法是使用sshfs

    1. sshfs me@somewhere-else:path/to/repo local/path/to/somewhere-else
    2. hg archive local/path/to/somewhere-else
    3. fusermount -r somewhere-else

    唯一的缺点是 sshfs 比 nfs、samba 或 rsync 慢。通常我不会注意到,因为我很少需要在远程文件系统中做任何事情。

    【讨论】:

      【解决方案3】:

      您是否可以使用 ssh 隧道在本地计算机上挂载远程目录,然后在“本地”(据 HG 所知)执行标准的 hg clonehg push 操作,但它们实际写入文件系统的位置是否在远程计算机上?

      看起来有几个关于这样做的stackoverflow问题:

      【讨论】:

        【解决方案4】:

        不,这是不可能的——我们总是假设远程主机上有一个正常运行的 Mercurial 安装。

        我绝对同意你的观点,这个功能会很好,但我认为它必须在扩展中实现。 Mercurial 不是通用的 SCP/FTP/rsync 文件复制程序,因此不要期望在核心中看到此功能。

        这提醒了我……也许你可以在FTP extension 的基础上让它做你想做的事。祝你好运! :-)

        【讨论】:

        • 感谢您的明确答复。很高兴直接听取 Mercurial 开发人员的意见。
        【解决方案5】:

        您是否考虑过简单地在遥控器上进行克隆并使用hg push 进行存档?

        【讨论】:

        • 那将是理想的,但不幸的是远程主机没有安装 Mercurial。
        • @Brett:是否可以在本地安装 hg?我以前在几个地方都这样做过。
        • 那行得通,但我仍然很好奇是否有办法远程存档,如果没有,为什么?
        猜你喜欢
        • 2013-04-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-19
        • 2011-12-17
        • 1970-01-01
        相关资源
        最近更新 更多