hg archive to Remote Directory

人盡茶涼 提交于 2019-12-23 15:34:51

问题


Is there any way to archive a Mercurial repository to a remote directory over SSH? For example, it would be nice if one could do the following:

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

However, that does not appear to work. It instead creates a directory called ssh: in the current directory.

I made the following quick-and-dirty script that emulates the desired behavior by creating a temporary ZIP archive, copying it over SSH, and unzipping the destination directory. However, I would like to know if there is a better way.

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

Edit: clone-and-push would be ideal, but unfortunately the remote server does not have Mercurial installed.


回答1:


Nope, this is not possible -- we always assume that there is a functioning Mercurial installation on the remote host.

I definitely agree with you that this functionality would be nice, but I think it would have to be made in an extension. Mercurial is not a general SCP/FTP/rsync file-copying program, so don't expect to see this functionality in the core.

This reminds me... perhaps you can built on the FTP extension to make it do what you want. Good luck! :-)




回答2:


Have you considered simply having a clone on the remote and doing hg push to archive?




回答3:


Could you use a ssh tunnel to mount a remote directory on your local machine and then just do standard hg clone and hg push operations 'locally' (as far as HG knows) but where they actually write to a filesystem which is on the remote computer?

It looks like there are several stackoverflow questions about doing this:

  • How do I mount a remote Linux folder in Windows through SSH?
  • Map SSH drive in Windows
  • How can I mount a remote directory on my computer?



回答4:


I am often in a similar situation. The way I get around it is with 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

The only disadvantage is sshfs is slower than nfs, samba or rsync. Generally I don't notice as I only rarely need to do anything in the remote file-system.




回答5:


You could also simply execute hg on the remote host:

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


来源:https://stackoverflow.com/questions/2338480/hg-archive-to-remote-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!