t / t3432-rebase-fast-forward.shon commit Merge branch 'bw/rebase-autostash-keep-current-branch' (974bdb0)
   1#!/bin/sh
   2#
   3# Copyright (c) 2019 Denton Liu
   4#
   5
   6test_description='ensure rebase fast-forwards commits when possible'
   7
   8. ./test-lib.sh
   9
  10test_expect_success setup '
  11        test_commit A &&
  12        test_commit B &&
  13        test_commit C &&
  14        test_commit D &&
  15        git checkout -t -b side
  16'
  17
  18test_rebase_same_head () {
  19        status_n="$1" &&
  20        shift &&
  21        what_n="$1" &&
  22        shift &&
  23        cmp_n="$1" &&
  24        shift &&
  25        status_f="$1" &&
  26        shift &&
  27        what_f="$1" &&
  28        shift &&
  29        cmp_f="$1" &&
  30        shift &&
  31        test_rebase_same_head_ $status_n $what_n $cmp_n "" "$*" &&
  32        test_rebase_same_head_ $status_f $what_f $cmp_f " --no-ff" "$*"
  33}
  34
  35test_rebase_same_head_ () {
  36        status="$1" &&
  37        shift &&
  38        what="$1" &&
  39        shift &&
  40        cmp="$1" &&
  41        shift &&
  42        flag="$1"
  43        shift &&
  44        test_expect_$status "git rebase$flag $* with $changes is $what with $cmp HEAD" "
  45                oldhead=\$(git rev-parse HEAD) &&
  46                test_when_finished 'git reset --hard \$oldhead' &&
  47                git rebase$flag $* >stdout &&
  48                if test $what = work
  49                then
  50                        # Must check this case first, for 'is up to
  51                        # date, rebase forced[...]rewinding head' cases
  52                        test_i18ngrep 'rewinding head' stdout
  53                elif test $what = noop
  54                then
  55                        test_i18ngrep 'is up to date' stdout &&
  56                        test_i18ngrep ! 'rebase forced' stdout
  57                elif test $what = noop-force
  58                then
  59                        test_i18ngrep 'is up to date, rebase forced' stdout
  60                fi &&
  61                newhead=\$(git rev-parse HEAD) &&
  62                if test $cmp = same
  63                then
  64                        test_cmp_rev \$oldhead \$newhead
  65                elif test $cmp = diff
  66                then
  67                        ! test_cmp_rev \$oldhead \$newhead
  68                fi
  69        "
  70}
  71
  72changes='no changes'
  73test_rebase_same_head success noop same success work same
  74test_rebase_same_head success noop same success noop-force same master
  75test_rebase_same_head success noop same success noop-force diff --onto B B
  76test_rebase_same_head success noop same success noop-force diff --onto B... B
  77test_rebase_same_head success noop same success noop-force same --onto master... master
  78test_rebase_same_head success noop same success noop-force same --keep-base master
  79test_rebase_same_head success noop same success noop-force same --keep-base
  80test_rebase_same_head success noop same success noop-force same --no-fork-point
  81test_rebase_same_head success noop same success noop-force same --keep-base --no-fork-point
  82test_rebase_same_head success noop same success work same --fork-point master
  83test_rebase_same_head success noop same success work diff --fork-point --onto B B
  84test_rebase_same_head success noop same success work diff --fork-point --onto B... B
  85test_rebase_same_head success noop same success work same --fork-point --onto master... master
  86test_rebase_same_head success noop same success work same --keep-base --keep-base master
  87
  88test_expect_success 'add work same to side' '
  89        test_commit E
  90'
  91
  92changes='our changes'
  93test_rebase_same_head success noop same success work same
  94test_rebase_same_head success noop same success noop-force same master
  95test_rebase_same_head success noop same success noop-force diff --onto B B
  96test_rebase_same_head success noop same success noop-force diff --onto B... B
  97test_rebase_same_head success noop same success noop-force same --onto master... master
  98test_rebase_same_head success noop same success noop-force same --keep-base master
  99test_rebase_same_head success noop same success noop-force same --keep-base
 100test_rebase_same_head success noop same success noop-force same --no-fork-point
 101test_rebase_same_head success noop same success noop-force same --keep-base --no-fork-point
 102test_rebase_same_head success noop same success work same --fork-point master
 103test_rebase_same_head success noop same success work diff --fork-point --onto B B
 104test_rebase_same_head success noop same success work diff --fork-point --onto B... B
 105test_rebase_same_head success noop same success work same --fork-point --onto master... master
 106test_rebase_same_head success noop same success work same --fork-point --keep-base master
 107
 108test_expect_success 'add work same to upstream' '
 109        git checkout master &&
 110        test_commit F &&
 111        git checkout side
 112'
 113
 114changes='our and their changes'
 115test_rebase_same_head success noop same success noop-force diff --onto B B
 116test_rebase_same_head success noop same success noop-force diff --onto B... B
 117test_rebase_same_head success noop same success work diff --onto master... master
 118test_rebase_same_head success noop same success work diff --keep-base master
 119test_rebase_same_head success noop same success work diff --keep-base
 120test_rebase_same_head failure work same success work diff --fork-point --onto B B
 121test_rebase_same_head failure work same success work diff --fork-point --onto B... B
 122test_rebase_same_head success noop same success work diff --fork-point --onto master... master
 123test_rebase_same_head success noop same success work diff --fork-point --keep-base master
 124
 125test_done