Last active
August 29, 2015 14:24
-
-
Save samv/bb1e77a8c68733631cff to your computer and use it in GitHub Desktop.
'git wcpush'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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