Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 42 lines (35 sloc) 1.18 KB
#!/bin/sh
#
# Usage: push
#
# Send your local branch changes to the remote branch,
# and copy the relevant GitHub 'compare' URL to your clipboard (!)
# This is Mac-only for the time being
#
remote=origin
branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
# Push & save output
push=$(git push $remote $branch 2>&1)
exit_code=$?
if [ $exit_code != 0 ]; then
echo "Ouch, push failed! code=$exit_code, output=$push"
exit $exit_code
fi
# Cleanly exit if nothing was pushed
if echo $push | grep "Everything up-to-date" >/dev/null; then
echo "git says everything is up-to-date! "
exit 0
fi
# Parse output into sexy GitHub compare URL!
echo $push
remote_url=$(git remote show $remote -n | grep Push | awk '{ print $3 }')
echo $remote_url
repo_name=$(echo $remote_url | sed 's/.*\:\(.*\)\.git/\1/')
echo $repo_name
refs=$(echo $push | awk '{ print $3}' | sed 's/\.\./\.\.\./')
echo $refs
github_url="https://github.com/$repo_name/compare/$refs"
echo $github_url
[ -n $(which pbcopy) ] && echo $github_url | pbcopy || echo "no 'pbcopy' command, skipping clipboard copy"
[ -n $(which open) ] && open -g $github_url || echo "no 'open' command, skipping browser open"
exit 0
Jump to Line
Something went wrong with that request. Please try again.