Created
February 25, 2014 20:48
-
-
Save agordon/9217404 to your computer and use it in GitHub Desktop.
This file contains 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/sh | |
## This script imports (cherry-picks) commits from HomeBrew into LinuxBrew. | |
## | |
## This script automatically find the commits which updates ONLY | |
## formulas in "/Library/Formulas" from HomeBrew, | |
## and cherry-pick them into a new branch. | |
## | |
## It is assumed that the current directory is setup in the following way: | |
## | |
## # Your forked LinuxBrew repository: | |
## $ git clone https://github.com/agordon/linuxbrew.git | |
## | |
## # Add LinuxBrew as 'upstream' | |
## git remote add upstream https://github.com/Homebrew/linuxbrew.git | |
## | |
## # Add HomeBrew as 'upstream_homebrew' | |
## git remote add upstream_homebrew https://github.com/Homebrew/homebrew.git | |
## | |
## | |
## | |
## | |
BRANCH=homebrew_import_$(date +%F-%H%M%S) | |
git checkout -b "$BRANCH" upstream/master || exit 1 | |
git fetch upstream # upstream for us is LinuxBrew | |
git fetch upstream_homebrew # the Mac OS-X homebrew | |
## Find the differences between LinuxBrew and HomeBrew | |
## | |
## The git format "---%n%H" will produce the following output: | |
## | |
## --- | |
## 9fe155d2690064eae442aa340d1a8b0e2b51dd60 | |
## 1 0 Library/Formula/libmemcached.rb | |
## | |
## --- | |
## 3bb66a90bf3b2338ce4159fb62157f67acee7754 | |
## 7 0 Library/Formula/libmemcached.rb | |
## | |
## --- | |
## 2609f61fa41fe67248127facf76c9daef9ccf757 | |
## 30 11 Library/Formula/libmemcached.rb | |
## | |
## --- | |
## | |
## | |
( git log --pretty=format:"---%n%H" --no-abbrev-commit --numstat \ | |
upstream/master..upstream_homebrew/master ; echo --- ) | | |
awk '$0 == "---" { if (commit_sha1 && formula_commit) { | |
print commit_sha1 | |
} | |
formula_commit = 1 | |
} | |
length($0)==40 && $0 ~ /^[0-9a-f]*$/ { commit_sha1 = $0 } | |
NF==3 { insertions = $1 | |
deletions = $2 | |
filename = $3 | |
i = index(filename,"Library/Formula/") | |
if ( i != 1 ) { | |
# This commit has at least one changed file | |
# which is not a formula, do not use it | |
formula_commit = 0 | |
} }' | tac | xargs -I{} git cherry-pick {} | |
echo "Done!" | |
echo "The imported branch is:" | |
echo " $BRANCH" | |
echo "" | |
echo "To push it back to github:" | |
echo " git push origin $BRANCH" | |
echo "" | |
echo "Then send a Pull-Request on GitHub" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment