File: test-flip-flop

package info (click to toggle)
git-imerge 1.2.0-5
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 428 kB
  • sloc: python: 2,909; javascript: 516; sh: 478; makefile: 7
file content (119 lines) | stat: -rwxr-xr-x 2,859 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#! /bin/sh

# Test a bunch of scenarios where branch `b` has a pair of commits,
# the first of which conflicts with branch `a`, and the second of
# which reverts that change. This tests the code for backtracking when
# outlining. We try placing the conflict-revert pair at the beginning,
# the middle, and the end of branch `b`, and we try merging both `b`
# into `a` and `a` into `b`.

set -ex

BASE="$(dirname "$(cd $(dirname "$0") && pwd)")"
. "$BASE/t/test-lib.sh"

GIT_IMERGE="git-imerge"

test_merge() {
    # The name of this test:
    local name=$1

    # The name of the branch being merged into:
    local dst=$2

    # The name of the branch being merged from:
    local src=$3

    # The indexes of the first and second conflicting micromerges
    # (e.g., "2-1"):
    local conflict1=$4
    local conflict2=$5

    # Test merging branch `$dst` into `$src`:
    git checkout $dst
    "$GIT_IMERGE" merge --branch=$name $src 2>&1 | tee imerge-$name-1.out

    "$GIT_IMERGE" diagram --commits --frontier

    if ! grep -q "There was a conflict merging commit $conflict1" imerge-$name-1.out
    then
        echo "conflict at $conflict1 not detected"
        exit 1
    fi

    # Fix the first conflict:
    echo 1 >a.txt
    git add a.txt
    "$GIT_IMERGE" continue --no-edit 2>&1 | tee imerge-$name-2.out

    "$GIT_IMERGE" diagram --commits --frontier

    if ! grep -q "There was a conflict merging commit $conflict2" imerge-$name-2.out
    then
        echo "conflict at $conflict2 not detected"
        exit 1
    fi

    # Fix the second conflict:
    echo 1 >a.txt
    git add a.txt
    "$GIT_IMERGE" continue --no-edit 2>&1 | tee imerge-$name-3.out
    if ! grep -q 'Merge is complete' imerge-$name-3.out
    then
        echo "merge failed"
        exit 1
    fi

    "$GIT_IMERGE" diagram --commits --frontier

    GIT_EDITOR=cat "$GIT_IMERGE" finish
}

flip_flop_test () {
    local n="$1"

    TMP="$BASE/t/tmp/flip-flop-$n"
    DESCRIPTION="git-imerge test repository with a commit and its revert at n=$n"

    init_test_repo "$TMP" "$DESCRIPTION"
    cd "$TMP"

    modify a.txt 0
    commit -m 'm⇒0'

    git checkout -b a --
    for i in 1 2 3
    do
        modify a.txt $i
        commit -m "a⇒$i on branch a"
    done

    git checkout -b b master --
    for i in 1 2 3 4
    do
        modify b.txt $i
        msg="b⇒$i"
        if test $i = $n
        then
            modify a.txt X
            msg="$msg and a⇒X"
        fi
        if test $i = $(( n + 1 ))
        then
            modify a.txt 0
            msg="$msg and a⇒0"
        fi
        commit -m "$msg on branch b"
    done

    # Test merging `b` into `a`:
    test_merge "b-into-a-$n" a b "1-$n" "1-$(( n + 1 ))"

    # Test merging `a` into `b`:
    test_merge "a-into-b-$n" b a "$n-1" "$(( n + 1 ))-1"
}

for n in 1 2 3
do
    flip_flop_test $n
done