Skip to content

Instantly share code, notes, and snippets.

@martialboniou
Created January 12, 2012 15:40
Show Gist options
  • Save martialboniou/1601173 to your computer and use it in GitHub Desktop.
Save martialboniou/1601173 to your computer and use it in GitHub Desktop.
homebrew mxcl master sync script for github fork in default remote AKA origin
#!/usr/bin/env zsh
# Sync mxcl homebrew with a forked version
#
# Usage: upgrade_forked_brew.sh && git push origin
emulate -L zsh
local FORK_GITHUB_USER=martialboniou
github_urls(){
g="github.com"
a=(git://$g/$1/$2.git git@$g:$1/$2.git https://$g/$1/$2.git)
print $a
}
test_remote_array() {
declare -a rmts
eval "rmts=( $1 )" && [ ${#rmts[*]} -ne 0 ] || ( echo "malformed array" && exit )
rmt=$(git remote -v &> /dev/null | grep "^origin" | head -1 | awk '{print $2}')
for i in $rmts; do
[ "$rmt" = "$i" ] && return 0
done
return 1
}
enable_remote_for() {
declare -a a
s=$(github_urls $1 $2)
# create new origin if different
test_remote_array $s || ( a=( ${=s} ) && git remote add origin $a[1] )
}
() {
cd `brew --prefix` &&
() {
declare -a mxcls_url
# check origin
enable_remote_for "$FORK_GITHUB_USER" "homebrew"
mxcls=$(github_urls "mxcl" "homebrew")
mxcl_urls=( ${=mxcls} ) && local mxcl_url=$mxcl_urls[1] || exit
# create a mxcl if none
(git ls-remote --heads $mxcl_url &> /dev/null || git remote add mxcl $mxcl_url) \
&& git checkout master 2> /dev/null \
&& git pull mxcl master
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment