Skip to content

Instantly share code, notes, and snippets.

@samv
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samv/bb1e77a8c68733631cff to your computer and use it in GitHub Desktop.
Save samv/bb1e77a8c68733631cff to your computer and use it in GitHub Desktop.
'git wcpush'
#!/bin/bash
remote=$1
ssh_target=$(git config remote.$remote.url)
echo "remote $remote, ssh is $ssh_target"
cdup="$(git rev-parse --show-cdup)"
if [ -n "$cdup" ]
then
cd "$cdup"
fi
fn="$(mktemp)"
(git ls-files -o --exclude-standard
git diff --name-only HEAD) | tee "$fn"
(set -x; rsync -vc -R --files-from="$fn" . $ssh_target)
hostname="$(expr "$ssh_target" : "\(.*\):.*")"
path="$(expr "$ssh_target" : ".*:\(.*\)")"
rem_rev=$(ssh "$hostname" "cd \"$path\" && git rev-parse HEAD" | cut -c1-7)
local_rev=$(git rev-parse HEAD | cut -c1-7)
if [ "$rem_rev" != "$local_rev" ]
then
echo "Blast, remote is on $rem_rev and we're on $local_rev"
branch=$(git symbolic-ref HEAD | sed 's!refs/heads/!!')
(set -x; git push $remote +HEAD)
(set -x; ssh $hostname "cd \"$path\"; git checkout -f $branch")
(set -x; rsync -vc -R --files-from="$fn" . $ssh_target)
fi
rm "$fn"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment