#!/bin/sh # # Copyright (c) 2007 José Fonseca # Copyright (c) 2005 Junio C Hamano # # Fetch a remote ref and rebase the current HEAD on top of it. USAGE='[-s strategy]... [] ' LONG_USAGE='Fetch a remote ref and rebase the current HEAD onto it.' SUBDIRECTORY_OK=Yes . git-sh-setup set_reflog_action "fetch-rebase $*" require_work_tree cd_to_toplevel test -z "$(git ls-files -u)" || die "You are in the middle of a conflicted merge." strategy_args= while : do case "$1" in -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\ --strateg=*|--strategy=*|\ -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy) case "$#,$1" in *,*=*) strategy=`expr "z$1" : 'z-[^=]*=\(.*\)'` ;; 1,*) usage ;; *) strategy="$2" shift ;; esac strategy_args="${strategy_args}-s $strategy " ;; -h|--h|--he|--hel|--help) usage ;; *) # Pass thru anything that may be meant for fetch. break ;; esac shift done orig_head=$(git rev-parse --verify HEAD 2>/dev/null) git-fetch "$@" || exit 1 merge_head=$(sed -e '/ not-for-merge /d' \ -e 's/ .*//' "$GIT_DIR"/FETCH_HEAD | \ tr '\012' ' ') case "$merge_head" in '') curr_branch=$(git symbolic-ref -q HEAD) case $? in 0) ;; 1) echo >&2 "You are not currently on a branch; you must explicitly" echo >&2 "specify which branch you wish to rebase onto:" echo >&2 " git fetch-rebase " exit 1;; *) exit $?;; esac curr_branch=${curr_branch#refs/heads/} echo >&2 "You asked me to rebase without telling me which branch you" echo >&2 "want to rebase, and 'branch.${curr_branch}.merge' in" echo >&2 "your configuration file does not tell me either. Please" echo >&2 "name which branch you want to rebase on the command line and" echo >&2 "try again (e.g. 'git fetch-rebase ')." echo >&2 "See git-pull(1) for details on the refspec." echo >&2 echo >&2 "If you often rebase to the same branch, you may want to" echo >&2 "configure the following variables in your configuration" echo >&2 "file:" echo >&2 echo >&2 " branch.${curr_branch}.remote = " echo >&2 " branch.${curr_branch}.merge = " echo >&2 " remote..url = " echo >&2 " remote..fetch = " echo >&2 echo >&2 "See git-config(1) for details." exit 1 ;; ?*' '?*) echo >&2 "Cannot rebase onto multiple branches" exit 1 ;; esac if test -z "$orig_head" then echo >&2 "Cannot rebase empty head" exit 1 fi exec git-rebase $strategy_args $merge_head