【发布时间】: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