]> git.ipfire.org Git - thirdparty/git.git/blame - git-rebase.sh
documentation: git-tag
[thirdparty/git.git] / git-rebase.sh
CommitLineData
59e6b23a
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano.
4#
5
ae2b0f15 6. git-sh-setup
4282c4fb 7
7f4bd5d8
JH
8# Make sure we do not have .dotest
9if mkdir .dotest
10then
11 rmdir .dotest
12else
13 echo >&2 '
14It seems that I cannot create a .dotest directory, and I wonder if you
15are in the middle of patch application or another rebase. If that is not
16the case, please rm -fr .dotest and run me again. I am stopping in case
17you still have something valuable there.'
18 exit 1
19fi
20
21# The other head is given. Make sure it is valid.
7f59dbbb 22other=$(git-rev-parse --verify "$1^0") || exit
59e6b23a 23
7f4bd5d8
JH
24# Make sure we have HEAD that is valid.
25head=$(git-rev-parse --verify "HEAD^0") || exit
26
7f59dbbb 27# The tree must be really really clean.
215a7ad1 28git-update-index --refresh || exit
7f59dbbb
JH
29diff=$(git-diff-index --cached --name-status -r HEAD)
30case "$different" in
31?*) echo "$diff"
32 exit 1
33 ;;
34esac
99a92f92 35
7f59dbbb 36# If the branch to rebase is given, first switch to it.
59e6b23a 37case "$#" in
7f59dbbb
JH
382)
39 git-checkout "$2" || exit
59e6b23a
JH
40esac
41
7f4bd5d8
JH
42# If the HEAD is a proper descendant of $other, we do not even need
43# to rebase. Make sure we do not do needless rebase. In such a
44# case, merge-base should be the same as "$other".
45mb=$(git-merge-base "$other" "$head")
46if test "$mb" = "$other"
47then
48 echo >&2 "Current branch `git-symbolic-ref HEAD` is up to date."
49 exit 0
50fi
51
7f59dbbb
JH
52# Rewind the head to "$other"
53git-reset --hard "$other"
54git-format-patch -k --stdout --full-index "$other" ORIG_HEAD |
55git am --binary -3 -k