t / t3411-rebase-preserve-around-merges.shon commit Merge branch 'maint-1.6.0' into maint-1.6.1 (0d50556)
   1#!/bin/sh
   2#
   3# Copyright (c) 2008 Stephen Haberman
   4#
   5
   6test_description='git rebase preserve merges
   7
   8This test runs git rebase with and tries to squash a commit from after a merge
   9to before the merge.
  10'
  11. ./test-lib.sh
  12
  13# Copy/paste from t3404-rebase-interactive.sh
  14echo "#!$SHELL_PATH" >fake-editor.sh
  15cat >> fake-editor.sh <<\EOF
  16case "$1" in
  17*/COMMIT_EDITMSG)
  18        test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1"
  19        test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1"
  20        exit
  21        ;;
  22esac
  23test -z "$EXPECT_COUNT" ||
  24        test "$EXPECT_COUNT" = $(sed -e '/^#/d' -e '/^$/d' < "$1" | wc -l) ||
  25        exit
  26test -z "$FAKE_LINES" && exit
  27grep -v '^#' < "$1" > "$1".tmp
  28rm -f "$1"
  29cat "$1".tmp
  30action=pick
  31for line in $FAKE_LINES; do
  32        case $line in
  33        squash|edit)
  34                action="$line";;
  35        *)
  36                echo sed -n "${line}s/^pick/$action/p"
  37                sed -n "${line}p" < "$1".tmp
  38                sed -n "${line}s/^pick/$action/p" < "$1".tmp >> "$1"
  39                action=pick;;
  40        esac
  41done
  42EOF
  43
  44test_set_editor "$(pwd)/fake-editor.sh"
  45chmod a+x fake-editor.sh
  46
  47# set up two branches like this:
  48#
  49# A1 - B1 - D1 - E1 - F1
  50#       \        /
  51#        -- C1 --
  52
  53test_expect_success 'setup' '
  54        touch a &&
  55        touch b &&
  56        git add a &&
  57        git commit -m A1 &&
  58        git tag A1
  59        git add b &&
  60        git commit -m B1 &&
  61        git tag B1 &&
  62        git checkout -b branch &&
  63        touch c &&
  64        git add c &&
  65        git commit -m C1 &&
  66        git checkout master &&
  67        touch d &&
  68        git add d &&
  69        git commit -m D1 &&
  70        git merge branch &&
  71        touch f &&
  72        git add f &&
  73        git commit -m F1 &&
  74        git tag F1
  75'
  76
  77# Should result in:
  78#
  79# A1 - B1 - D2 - E2
  80#       \        /
  81#        -- C1 --
  82#
  83test_expect_success 'squash F1 into D1' '
  84        FAKE_LINES="1 squash 3 2" git rebase -i -p B1 &&
  85        test "$(git rev-parse HEAD^2)" = "$(git rev-parse branch)" &&
  86        test "$(git rev-parse HEAD~2)" = "$(git rev-parse B1)" &&
  87        git tag E2
  88'
  89
  90# Start with:
  91#
  92# A1 - B1 - D2 - E2
  93#  \
  94#   G1 ---- L1 ---- M1
  95#    \             /
  96#     H1 -- J1 -- K1
  97#      \         /
  98#        -- I1 --
  99#
 100# And rebase G1..M1 onto E2
 101
 102test_expect_success 'rebase two levels of merge' '
 103        git checkout -b branch2 A1 &&
 104        touch g &&
 105        git add g &&
 106        git commit -m G1 &&
 107        git checkout -b branch3 &&
 108        touch h
 109        git add h &&
 110        git commit -m H1 &&
 111        git checkout -b branch4 &&
 112        touch i &&
 113        git add i &&
 114        git commit -m I1 &&
 115        git tag I1 &&
 116        git checkout branch3 &&
 117        touch j &&
 118        git add j &&
 119        git commit -m J1 &&
 120        git merge I1 --no-commit &&
 121        git commit -m K1 &&
 122        git tag K1 &&
 123        git checkout branch2 &&
 124        touch l &&
 125        git add l &&
 126        git commit -m L1 &&
 127        git merge K1 --no-commit &&
 128        git commit -m M1 &&
 129        GIT_EDITOR=: git rebase -i -p E2 &&
 130        test "$(git rev-parse HEAD~3)" = "$(git rev-parse E2)" &&
 131        test "$(git rev-parse HEAD~2)" = "$(git rev-parse HEAD^2^2~2)" &&
 132        test "$(git rev-parse HEAD^2^1^1)" = "$(git rev-parse HEAD^2^2^1)"
 133'
 134
 135test_done