Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hg archive to Remote Directory

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://[email protected]/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.

like image 282
Brett Daniel Avatar asked Dec 30 '22 00:12

Brett Daniel


2 Answers

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! :-)

like image 105
Martin Geisler Avatar answered Dec 31 '22 12:12

Martin Geisler


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

like image 25
Paul Nathan Avatar answered Dec 31 '22 14:12

Paul Nathan