-
-
Save lwe/493669 to your computer and use it in GitHub Desktop.
| #!/bin/sh | |
| # DISCLAIMER: | |
| # | |
| # brew update now has a --rebase switch, thus this script is certainly obsolet. | |
| # | |
| # USAGE: brew-rebase [--verbose|-v] [remote] [branch] | |
| # | |
| # Fetches upstream and rebases HOMEBREW_REPOSITORY ($_git_repo) | |
| # Remote defaults to 'upstream', branch defaults to 'master' | |
| # | |
| # If no remote has been added, mxcl/homebrew is added as default. | |
| # | |
| # Copyright (c) 2011 Lukas Westermann | |
| # | |
| # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation | |
| # files (the "Software"), to # deal in the Software without restriction, including without limitation the rights to use, copy, | |
| # modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software | |
| # is furnished to do so, subject to the following conditions: | |
| # | |
| # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
| # | |
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | |
| # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
| # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR | |
| # IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
| _verbose=$HOMEBREW_VERBOSE | |
| _git_repo=$(brew --repository) | |
| # some options and simple usage | |
| case $1 in | |
| -h|--help) | |
| echo "Usage: brew-rebase [--verbose|-v] [remote] [branch]" | |
| echo " Fetches upstream and rebases HOMEBREW_REPOSITORY ($_git_repo)" | |
| echo " Remote defaults to 'upstream', branch defaults to 'master'" | |
| exit 0;; | |
| -v|--verbose) | |
| _verbose="yes" | |
| shift | |
| ;; | |
| esac | |
| # move into HOMEBREW_REPOSITORY | |
| cd $_git_repo | |
| # get git binary | |
| _git_bin=$(/usr/bin/which git | head -1) | |
| # additional git args if verbose | |
| _git_args= | |
| [ -n "$_verbose" ] && _git_args="--verbose" | |
| # get git remote, defaults to "upstream" | |
| _remote=$1 | |
| [ ${_remote}"-none" == "-none" ] && _remote="upstream" | |
| # get branch, defaults to "master" | |
| _branch=$2 | |
| [ ${_branch}"-none" == "-none" ] && _branch="master" | |
| # if remote not added, add remote | |
| if [ $($_git_bin remote | grep "$_remote")"-notadded" == "-notadded" ]; then | |
| echo "[brew-rebase]: adding git://github.com/mxcl/homebrew.git as $_git_remote" | |
| $_git_bin remote add "$_remote" "git://github.com/mxcl/homebrew.git" | |
| fi | |
| # fetch & rebase from $_remote/$_branch | |
| echo "[brew-rebase] fetch and rebasing homebrew ($_git_repo) => $_remote/$_branch" | |
| $_git_bin fetch $_git_args "$_remote" | |
| $_git_bin rebase $_git_args "$_remote/$_branch" |
@adamv, thanks
Could you add a comment explaining the rationale for using rebase over brew’s default update? (I’m intrigued, just confused about what prompted the creation of this.)
Clean commit History
@Zearin http://progit.org/book/ch3-6.html
Nice work. Would it be possible to integrate this into the main homebrew?
feel free to create a pull request and submit it to homebrew :)
I fear, I do not know enough about homebrew and git to handle that :(
uhm, I see... well AFAIK getting accepted as core command might not be that easy and considering there are already like ~270 pull requests open, I'll keep it here :)
FYI, brew update now has a --rebase option (introduced by Homebrew/legacy-homebrew@dec4b73).
Though if you do your work using topic branches and avoid committing on master, brew update will always result in a fast-forward and the history will be clean anyway.
@jacknagel, great! I just noticed it yesterday while scanning through man brew :-)
Line 4 can be:
_git_repo=$(brew --repository)