d9f20fa07c47d2c2da1867ef802c4c0ab6f1f876
   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="$1" &&
  20        shift &&
  21        what="$1" &&
  22        shift &&
  23        cmp="$1" &&
  24        shift &&
  25        test_expect_$status "git rebase $* with $changes is $what" "
  26                oldhead=\$(git rev-parse HEAD) &&
  27                test_when_finished 'git reset --hard \$oldhead' &&
  28                git rebase $* >stdout &&
  29                if test $what = work
  30                then
  31                        test_i18ngrep 'rewinding head' stdout
  32                elif test $what = noop
  33                then
  34                        test_i18ngrep 'is up to date' stdout
  35                fi &&
  36                newhead=\$(git rev-parse HEAD) &&
  37                if test $cmp = same
  38                then
  39                        test_cmp_rev \$oldhead \$newhead
  40                elif test $cmp = diff
  41                then
  42                        ! test_cmp_rev \$oldhead \$newhead
  43                fi
  44        "
  45}
  46
  47changes='no changes'
  48test_rebase_same_head success work same
  49test_rebase_same_head success noop same master
  50test_rebase_same_head success noop same --onto B B
  51test_rebase_same_head success noop same --onto B... B
  52test_rebase_same_head success noop same --onto master... master
  53test_rebase_same_head success noop same --no-fork-point
  54test_rebase_same_head success work same --fork-point master
  55test_rebase_same_head failure noop same --fork-point --onto B B
  56test_rebase_same_head failure work same --fork-point --onto B... B
  57test_rebase_same_head success work same --fork-point --onto master... master
  58
  59test_expect_success 'add work same to side' '
  60        test_commit E
  61'
  62
  63changes='our changes'
  64test_rebase_same_head success work same
  65test_rebase_same_head success noop same master
  66test_rebase_same_head success noop same --onto B B
  67test_rebase_same_head success noop same --onto B... B
  68test_rebase_same_head success noop same --onto master... master
  69test_rebase_same_head success noop same --no-fork-point
  70test_rebase_same_head success work same --fork-point master
  71test_rebase_same_head failure work same --fork-point --onto B B
  72test_rebase_same_head failure work same --fork-point --onto B... B
  73test_rebase_same_head success work same --fork-point --onto master... master
  74
  75test_expect_success 'add work same to upstream' '
  76        git checkout master &&
  77        test_commit F &&
  78        git checkout side
  79'
  80
  81changes='our and their changes'
  82test_rebase_same_head success noop same --onto B B
  83test_rebase_same_head success noop same --onto B... B
  84test_rebase_same_head failure work same --onto master... master
  85test_rebase_same_head failure work same --fork-point --onto B B
  86test_rebase_same_head failure work same --fork-point --onto B... B
  87test_rebase_same_head failure work same --fork-point --onto master... master
  88
  89test_done