t / t3402-rebase-merge.shon commit Merge branch 'jk/skip-prefix' (e91ae32)
   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 "reference merge" HEAD 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 'merge and rebase should match' '
  89        git diff-tree -r test-rebase test-merge >difference &&
  90        if test -s difference
  91        then
  92                cat difference
  93                (exit 1)
  94        else
  95                echo happy
  96        fi
  97'
  98
  99test_expect_success 'picking rebase' '
 100        git reset --hard side &&
 101        git rebase --merge --onto master side^^ &&
 102        mb=$(git merge-base master HEAD) &&
 103        if test "$mb" = "$(git rev-parse master)"
 104        then
 105                echo happy
 106        else
 107                git show-branch
 108                (exit 1)
 109        fi &&
 110        f=$(git diff-tree --name-only HEAD^ HEAD) &&
 111        g=$(git diff-tree --name-only HEAD^^ HEAD^) &&
 112        case "$f,$g" in
 113        newfile,newfile)
 114                echo happy ;;
 115        *)
 116                echo "$f"
 117                echo "$g"
 118                (exit 1)
 119        esac
 120'
 121
 122test_expect_success 'rebase -s funny -Xopt' '
 123        test_when_finished "rm -fr test-bin funny.was.run" &&
 124        mkdir test-bin &&
 125        cat >test-bin/git-merge-funny <<-EOF &&
 126        #!$SHELL_PATH
 127        case "\$1" in --opt) ;; *) exit 2 ;; esac
 128        shift &&
 129        >funny.was.run &&
 130        exec git merge-recursive "\$@"
 131        EOF
 132        chmod +x test-bin/git-merge-funny &&
 133        git reset --hard &&
 134        git checkout -b test-funny master^ &&
 135        test_commit funny &&
 136        (
 137                PATH=./test-bin:$PATH
 138                git rebase -s funny -Xopt master
 139        ) &&
 140        test -f funny.was.run
 141'
 142
 143test_expect_success 'rebase --skip works with two conflicts in a row' '
 144        git checkout second-side  &&
 145        tr "[A-Z]" "[a-z]" <newfile >tmp &&
 146        mv tmp newfile &&
 147        git commit -a -m"edit conflicting with side" &&
 148        tr "[d-f]" "[D-F]" <newfile >tmp &&
 149        mv tmp newfile &&
 150        git commit -a -m"another edit conflicting with side" &&
 151        test_must_fail git rebase --merge test-conflicts &&
 152        test_must_fail git rebase --skip &&
 153        git rebase --skip
 154'
 155
 156test_done