Skip to content

Instantly share code, notes, and snippets.

@lwe
Created July 28, 2010 07:15
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lwe/493669 to your computer and use it in GitHub Desktop.
Save lwe/493669 to your computer and use it in GitHub Desktop.
Replacement for `brew update` which uses rebase.
#!/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
Copy link

adamv commented Nov 2, 2010

Line 4 can be:
_git_repo=$(brew --repository)

@lwe
Copy link
Author

lwe commented Nov 2, 2010

@adamv, thanks

@Zearin
Copy link

Zearin commented Jun 7, 2011

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.)

@lwe
Copy link
Author

lwe commented Jun 8, 2011

Clean commit History

@samueljohn
Copy link

@Zearin http://progit.org/book/ch3-6.html

Nice work. Would it be possible to integrate this into the main homebrew?

@lwe
Copy link
Author

lwe commented Sep 22, 2011

feel free to create a pull request and submit it to homebrew :)

@samueljohn
Copy link

I fear, I do not know enough about homebrew and git to handle that :(

@lwe
Copy link
Author

lwe commented Sep 22, 2011

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 :)

@jacknagel
Copy link

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.

@samueljohn
Copy link

@jacknagel, great! I just noticed it yesterday while scanning through man brew :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment