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 other head is given. Make sure it is valid. 25other=$(git-rev-parse --verify "$1^0")|| usage 26 27# Make sure we have HEAD that is valid. 28head=$(git-rev-parse --verify "HEAD^0")||exit 29 30# The tree must be really really clean. 31git-update-index --refresh||exit 32diff=$(git-diff-index --cached --name-status -r HEAD) 33case"$different"in 34?*)echo"$diff" 35exit1 36;; 37esac 38 39# If the branch to rebase is given, first switch to it. 40case"$#"in 412) 42head=$(git-rev-parse --verify "$2^")|| usage 43 git-checkout"$2"|| usage 44esac 45 46# If the HEAD is a proper descendant of $other, we do not even need 47# to rebase. Make sure we do not do needless rebase. In such a 48# case, merge-base should be the same as "$other". 49mb=$(git-merge-base "$other" "$head") 50iftest"$mb"="$other" 51then 52echo>&2"Current branch `git-symbolic-ref HEAD` is up to date." 53exit0 54fi 55 56# Rewind the head to "$other" 57git-reset --hard"$other" 58git-format-patch -k --stdout --full-index"$other" ORIG_HEAD | 59git am --binary -3 -k