Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
executable file 108 lines (97 sloc) 3.077 kb
#!/usr/bin/env bash
set -e
if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
echo "usage: git sync [remote-name]"
echo
echo "Sync's the current repository to another remote host, using git,"
echo "but not using this repository."
echo
echo "You must set sync.default.repo (the path to store the repository)"
echo "and git.default.remote (the remote repository to push to). Example:"
echo " $ git config --add sync.default.repo .remote-repo"
echo " $ git config --add sync.default.remote git@hostname:/path.git"
echo "And optionally:"
echo " $ git config --add sync.default.branch gh-pages"
exit
fi
if [ -z "$1" ] ; then
dest=default
else
dest="$1"
fi
repo_location="$(git config --get --path sync.${dest}.repo || true)"
if [ -z "$repo_location" ] ; then
repo_location="$(git config --get --path sync.repo || true)"
if [ -z "$repo_location" ] ; then
repo_location=/tmp/repos
fi
repo_location="${repo_location}/$(basename $(pwd))"
fi
remote_branch="$(git config --get sync.${dest}.branch || true)"
if [ ! -e $repo_location ] ; then
remote="$(git config --get sync.${dest}.remote || true)"
if [ -z "$remote" ] ; then
echo "You must set sync.${dest}.remote"
echo "Like:"
echo " git config --add sync.${dest}.remote git@host.com:/path.git"
exit 2
fi
if [ -z "$remote_branch" ] ; then
git_op=""
git_msg=""
else
git_op="-b $remote_branch"
git_msg=" from branch $remote_branch"
fi
echo "making git repo in $repo_location$git_msg"
mkdir -p "$(basename $repo_location)"
echo git clone $git_op $remote $repo_location
git clone $git_op $remote $repo_location
else
# pull from master to ensure we're uptodate
(
cd $repo_location
if [ -z "$remote_branch" ] ; then
git_op=""
else
git_op="$remote_branch:$remote_branch"
fi
echo cd $repo_location "&&" git pull origin $git_op
git pull origin $git_op
)
fi
if [ -e .syncignore ] ; then
rsync_option="--exclude-from=.syncignore"
else
rsync_option=""
fi
## FIXME: should I exclude untracked files? Seems like it
# per discussion over build tools issue, rsync everything
rsync --recursive --delete --exclude .git --exclude $repo_location . $repo_location
if [ -e .syncignore ] ; then
cat .syncignore >> $repo_location/.gitignore
fi
build_command="$(git config --get sync.${dest}.build || true)"
if [ -n "$build_command" ] ; then
echo "Running $build_command"
(
cd $repo_location
$build_command
)
fi
version="$(git describe --always --dirty)"
(
cd $repo_location
adds="$(git status -s | awk '/^\?\?/ {print $2}')"
if [ -n "$adds" ] ; then
git add $adds
fi
git commit -a -m "deployment $version"
if [ -z "$remote_branch" ] ; then
git_op=""
else
git_op="$remote_branch:$remote_branch"
fi
echo cd $repo_location "&&" git push origin $git_op
git push origin $git_op
)
Jump to Line
Something went wrong with that request. Please try again.