publish: Publish a copy of the current repository on a remote machine

Usage:
  eg publish [-b|--bypass-modification-check] [-g|--group GROUP]
             [REMOTE_ALIAS] SSH_URL

Description:
  Publishes a copy of the current repository on a remote machine.  Note
  that local changes will be ignored; only committed changes will be
  published.  You must have ssh access to the remote machine and must have
  both git and ssh installed on both local and remote machines.

  After publishing the repository, it is accessible via the remote
  REMOTE_ALIAS, thus allowing you to use REMOTE_ALIAS to push and pull
  commands.  If REMOTE_ALIAS is not specified, it defaults to 'origin'.

  If the --group (or -g) option is specified, the given GROUP must be a
  valid unix group on the remote machine, and the user must be a member of
  that group.  When this option is passed, eg publish will ensure that all
  files are readable and writable by members of that group.

  Note that the remote location is specified using a ssh url; see 'eg help
  topic remote_urls' for a full list of valid possibilities, but the
  general case is to use scp(1) syntax: [[USER@]MACHINE]:REMOTE_PATH.  Note
  that if any files or directories exist below the specified remote
  directory, publish will abort.

Examples:
  Publish a copy of the current repository on the machine myserver.com in
  the directory /var/scratch/git-stuff/my-repo.git, and make it readable
  and writable by the unix group 'gitters'.  Then immediately make a clone
  of the remote repository
      $ eg publish -g gitters myserver.com:/var/scratch/git-stuff/my-repo.git
      $ cd ..
      $ eg clone myserver.com:/var/scratch/git-stuff/my-repo.git

  Publish a copy of the current repository on the machine www.gnome.org, in
  the public_html/myproj subdirectory of the home directory of the remote
  user fake, then immediately clone it again into a separate directory
  named another-myproj.
      $ eg publish fake@www.gnome.org:public_html/myproj
      $ cd ..
      $ eg clone http://www.gnome.org/~fake/myproj another-myproj

Options
  --bypass-modification-check, -b
    To prevent you from publishing an incomplete set of changes, publish
    typically checks whether you have new unknown files or modified files
    present and aborts if so.  You can bypass these checks with this
    option.

Differences from git publish:
  eg publish is unique to eg, designed to condense the multiple necessary
  steps with git into one (or a few) commands.  The steps that eg publish
  performs are essentially:
      if ( git config --get remote.REMOTE_ALIAS.url > /dev/null); then
        echo "REMOTE_ALIAS already defined"; false;
      fi &&
      ssh [USER@]MACHINE "
        test -d REMOTE_PATH && echo "REMOTE_PATH already exists!" && exit 1;
        if (! groups | grep "\bGROUP\b" > /dev/null); then
          echo "Cannot change to group GROUP";  exit 1;
        fi;
        if (! type -p git>/dev/null);then echo "Cannot find git"; exit 1; fi &&
        newgrp GROUP;
        mkdir -p REMOTE_PATH &&
        cd REMOTE_PATH &&
        git init [--shared] --bare &&
        touch git-daemon-export-ok &&
        (mv hooks/post-update.sample hooks/post-update || true) &&
        chmod u+x hooks/post-update" &&
      git remote add REMOTE_ALIAS [USER@]MACHINE:REMOTE_PATH &&
      git push
  Note that the command involving git-daemon-export-ok is only needed if
  you will be cloning/pulling from the repository via the git:// protocol
  (in which case you are responsible for running git-daemon on the remote
  machine), and the post-update hook related stuff is only necessary if you
  are trying to clone/pull via the http:// protocol (in which case you are
  responsible for running a webserver such as httpd on the remote machine);
  neither of these steps are needed if you are cloning/pulling via ssh, but
  they do not cause problems either.

  MULTI-USER NOTE: If you want multiple people to be able to push to the
  resulting repository, you will need to ensure that they all have ssh
  access to the machine, that they are all part of the same unix group, and
  that you use the --group option to ensure that the repository is set up
  to be shared by the relevant group.