t / t3402-rebase-merge.shon commit Merge branch 'rj/sparse-flags' (fe8e686)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Junio C Hamano
   4#
   5
   6test_description='git rebase --merge test'
   7
   8. ./test-lib.sh
   9
  10T="A quick brown fox
  11jumps over the lazy dog."
  12for i in 1 2 3 4 5 6 7 8 9 10
  13do
  14        echo "$i $T"
  15done >original
  16
  17test_expect_success setup '
  18        git add original &&
  19        git commit -m"initial" &&
  20        git branch side &&
  21        echo "11 $T" >>original &&
  22        git commit -a -m"master updates a bit." &&
  23
  24        echo "12 $T" >>original &&
  25        git commit -a -m"master updates a bit more." &&
  26
  27        git checkout side &&
  28        (echo "0 $T" && cat original) >renamed &&
  29        git add renamed &&
  30        git update-index --force-remove original &&
  31        git commit -a -m"side renames and edits." &&
  32
  33        tr "[a-z]" "[A-Z]" <original >newfile &&
  34        git add newfile &&
  35        git commit -a -m"side edits further." &&
  36        git branch second-side &&
  37
  38        tr "[a-m]" "[A-M]" <original >newfile &&
  39        rm -f original &&
  40        git commit -a -m"side edits once again." &&
  41
  42        git branch test-rebase side &&
  43        git branch test-rebase-pick side &&
  44        git branch test-reference-pick side &&
  45        git branch test-conflicts side &&
  46        git checkout -b test-merge side
  47'
  48
  49test_expect_success 'reference merge' '
  50        git merge -s recursive -m "reference merge" master
  51'
  52
  53PRE_REBASE=$(git rev-parse test-rebase)
  54test_expect_success rebase '
  55        git checkout test-rebase &&
  56        GIT_TRACE=1 git rebase --merge master
  57'
  58
  59test_expect_success 'test-rebase@{1} is pre rebase' '
  60        test $PRE_REBASE = $(git rev-parse test-rebase@{1})
  61'
  62
  63test_expect_success 'merge and rebase should match' '
  64        git diff-tree -r test-rebase test-merge >difference &&
  65        if test -s difference
  66        then
  67                cat difference
  68                (exit 1)
  69        else
  70                echo happy
  71        fi
  72'
  73
  74test_expect_success 'rebase the other way' '
  75        git reset --hard master &&
  76        git rebase --merge side
  77'
  78
  79test_expect_success 'rebase -Xtheirs' '
  80        git checkout -b conflicting master~2 &&
  81        echo "AB $T" >> original &&
  82        git commit -mconflicting original &&
  83        git rebase -Xtheirs master &&
  84        grep AB original &&
  85        ! grep 11 original
  86'
  87
  88test_expect_success 'rebase -Xtheirs from orphan' '
  89        git checkout --orphan orphan-conflicting master~2 &&
  90        echo "AB $T" >> original &&
  91        git commit -morphan-conflicting original &&
  92        git rebase -Xtheirs master &&
  93        grep AB original &&
  94        ! grep 11 original
  95'
  96
  97test_expect_success 'merge and rebase should match' '
  98        git diff-tree -r test-rebase test-merge >difference &&
  99        if test -s difference
 100        then
 101                cat difference
 102                (exit 1)
 103        else
 104                echo happy
 105        fi
 106'
 107
 108test_expect_success 'picking rebase' '
 109        git reset --hard side &&
 110        git rebase --merge --onto master side^^ &&
 111        mb=$(git merge-base master HEAD) &&
 112        if test "$mb" = "$(git rev-parse master)"
 113        then
 114                echo happy
 115        else
 116                git show-branch
 117                (exit 1)
 118        fi &&
 119        f=$(git diff-tree --name-only HEAD^ HEAD) &&
 120        g=$(git diff-tree --name-only HEAD^^ HEAD^) &&
 121        case "$f,$g" in
 122        newfile,newfile)
 123                echo happy ;;
 124        *)
 125                echo "$f"
 126                echo "$g"
 127                (exit 1)
 128        esac
 129'
 130
 131test_expect_success 'rebase -s funny -Xopt' '
 132        test_when_finished "rm -fr test-bin funny.was.run" &&
 133        mkdir test-bin &&
 134        cat >test-bin/git-merge-funny <<-EOF &&
 135        #!$SHELL_PATH
 136        case "\$1" in --opt) ;; *) exit 2 ;; esac
 137        shift &&
 138        >funny.was.run &&
 139        exec git merge-recursive "\$@"
 140        EOF
 141        chmod +x test-bin/git-merge-funny &&
 142        git reset --hard &&
 143        git checkout -b test-funny master^ &&
 144        test_commit funny &&
 145        (
 146                PATH=./test-bin:$PATH &&
 147                git rebase -s funny -Xopt master
 148        ) &&
 149        test -f funny.was.run
 150'
 151
 152test_expect_success 'rebase --skip works with two conflicts in a row' '
 153        git checkout second-side  &&
 154        tr "[A-Z]" "[a-z]" <newfile >tmp &&
 155        mv tmp newfile &&
 156        git commit -a -m"edit conflicting with side" &&
 157        tr "[d-f]" "[D-F]" <newfile >tmp &&
 158        mv tmp newfile &&
 159        git commit -a -m"another edit conflicting with side" &&
 160        test_must_fail git rebase --merge test-conflicts &&
 161        test_must_fail git rebase --skip &&
 162        git rebase --skip
 163'
 164
 165test_done