git-rebase.shon commit [PATCH] Provide access to git_dir through get_git_dir(). (5da1606)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano.
   4#
   5
   6. git-sh-setup || die "Not a git archive."
   7
   8usage="usage: $0 "'<upstream> [<head>]
   9
  10Uses output from git-cherry to rebase local commits to the new head of
  11upstream tree.'
  12
  13case "$#,$1" in
  141,*..*)
  15    upstream=$(expr "$1" : '\(.*\)\.\.') ours=$(expr "$1" : '.*\.\.\(.*\)$')
  16    set x "$upstream" "$ours"
  17    shift ;;
  18esac
  19
  20git-update-index --refresh || exit
  21
  22case "$#" in
  231) ours_symbolic=HEAD ;;
  242) ours_symbolic="$2" ;;
  25*) die "$usage" ;;
  26esac
  27
  28upstream=`git-rev-parse --verify "$1"` &&
  29ours=`git-rev-parse --verify "$ours_symbolic"` || exit
  30different1=$(git-diff-index --name-only --cached "$ours") &&
  31different2=$(git-diff-index --name-only "$ours") &&
  32test "$different1$different2" = "" ||
  33die "Your working tree does not match $ours_symbolic."
  34
  35git-read-tree -m -u $ours $upstream &&
  36git-rev-parse --verify "$upstream^0" >"$GIT_DIR/HEAD" || exit
  37
  38tmp=.rebase-tmp$$
  39fail=$tmp-fail
  40trap "rm -rf $tmp-*" 1 2 3 15
  41
  42>$fail
  43
  44git-cherry -v $upstream $ours |
  45while read sign commit msg
  46do
  47        case "$sign" in
  48        -)
  49                echo >&2 "* Already applied: $msg"
  50                continue ;;
  51        esac
  52        echo >&2 "* Applying: $msg"
  53        S=`cat "$GIT_DIR/HEAD"` &&
  54        git-cherry-pick --replay $commit || {
  55                echo >&2 "* Not applying the patch and continuing."
  56                echo $commit >>$fail
  57                git-reset --hard $S
  58        }
  59done
  60if test -s $fail
  61then
  62        echo >&2 Some commits could not be rebased, check by hand:
  63        cat >&2 $fail
  64        echo >&2 "(the same list of commits are found in $tmp)"
  65        exit 1
  66else
  67        rm -f $fail
  68fi