title: hg archive to Remote Directory
body: <p>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:</p>
  
  <pre><code>hg archive ssh://user@example.com/path/to/archive
  </code></pre>
  
  <p>However, that does not appear to work. It instead creates a directory called <code>ssh:</code> in the current directory. </p>
  
  <p>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. </p>
  
  <pre><code>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
  </code></pre>
  
  <p><strong>Edit</strong>: <code>clone</code>-and-<code>push</code> would be ideal, but unfortunately the remote server does not have Mercurial installed. </p>