1#!/bin/sh 2# 3# Copyright (c) 2005 Junio C Hamano. 4# 5 6USAGE='<upstream> [<head>]' 7. git-sh-setup 8 9case$#in1|2) ;; *) usage ;;esac 10 11# Make sure we do not have .dotest 12ifmkdir .dotest 13then 14rmdir .dotest 15else 16echo>&2' 17It seems that I cannot create a .dotest directory, and I wonder if you 18are in the middle of patch application or another rebase. If that is not 19the case, please rm -fr .dotest and run me again. I am stopping in case 20you still have something valuable there.' 21exit1 22fi 23 24# The tree must be really really clean. 25git-update-index --refresh||exit 26diff=$(git-diff-index --cached --name-status -r HEAD) 27case"$diff"in 28?*)echo"$diff" 29exit1 30;; 31esac 32 33# The other head is given. Make sure it is valid. 34other=$(git-rev-parse --verify "$1^0")|| usage 35 36# Make sure the branch to rebase is valid. 37head=$(git-rev-parse --verify "${2-HEAD}^0")||exit 38 39# If the branch to rebase is given, first switch to it. 40case"$#"in 412) 42 git-checkout"$2"|| usage 43esac 44 45mb=$(git-merge-base "$other" "$head") 46 47# Check if we are already based on $other. 48iftest"$mb"="$other" 49then 50echo>&2"Current branch `git-symbolic-ref HEAD` is up to date." 51exit0 52fi 53 54# Rewind the head to "$other" 55git-reset --hard"$other" 56 57# If the $other is a proper descendant of the tip of the branch, then 58# we just fast forwarded. 59iftest"$mb"="$head" 60then 61echo>&2"Fast-forwarded$headto$other." 62exit0 63fi 64 65git-format-patch -k --stdout --full-index"$other" ORIG_HEAD | 66git am --binary -3 -k