1#!/bin/sh
2
3test_description='merge simplification'
4
5. ./test-lib.sh
6
7note () {
8 git tag "$1"
9}
10
11unnote () {
12 git name-rev --tags --stdin | sed -e "s|$OID_REGEX (tags/\([^)]*\)) |\1 |g"
13}
14
15test_expect_success setup '
16 echo "Hi there" >file &&
17 echo "initial" >lost &&
18 git add file lost &&
19 test_tick && git commit -m "Initial file and lost" &&
20 note A &&
21
22 git branch other-branch &&
23
24 echo "Hello" >file &&
25 echo "second" >lost &&
26 git add file lost &&
27 test_tick && git commit -m "Modified file and lost" &&
28 note B &&
29
30 git checkout other-branch &&
31
32 echo "Hello" >file &&
33 >lost &&
34 git add file lost &&
35 test_tick && git commit -m "Modified the file identically" &&
36 note C &&
37
38 echo "This is a stupid example" >another-file &&
39 git add another-file &&
40 test_tick && git commit -m "Add another file" &&
41 note D &&
42
43 test_tick &&
44 test_must_fail git merge -m "merge" master &&
45 >lost && git commit -a -m "merge" &&
46 note E &&
47
48 echo "Yet another" >elif &&
49 git add elif &&
50 test_tick && git commit -m "Irrelevant change" &&
51 note F &&
52
53 git checkout master &&
54 echo "Yet another" >elif &&
55 git add elif &&
56 test_tick && git commit -m "Another irrelevant change" &&
57 note G &&
58
59 test_tick && git merge -m "merge" other-branch &&
60 note H &&
61
62 echo "Final change" >file &&
63 test_tick && git commit -a -m "Final change" &&
64 note I &&
65
66 git symbolic-ref HEAD refs/heads/unrelated &&
67 git rm -f "*" &&
68 echo "Unrelated branch" >side &&
69 git add side &&
70 test_tick && git commit -m "Side root" &&
71 note J &&
72
73 git checkout master &&
74 test_tick && git merge --allow-unrelated-histories -m "Coolest" unrelated &&
75 note K &&
76
77 echo "Immaterial" >elif &&
78 git add elif &&
79 test_tick && git commit -m "Last" &&
80 note L
81'
82
83FMT='tformat:%P %H | %s'
84
85check_outcome () {
86 outcome=$1
87 shift
88 for c in $1
89 do
90 echo "$c"
91 done >expect &&
92 shift &&
93 param="$*" &&
94 test_expect_$outcome "log $param" '
95 git log --pretty="$FMT" --parents $param |
96 unnote >actual &&
97 sed -e "s/^.* \([^ ]*\) .*/\1/" >check <actual &&
98 test_cmp expect check
99 '
100}
101
102check_result () {
103 check_outcome success "$@"
104}
105
106check_result 'L K J I H G F E D C B A' --full-history
107check_result 'K I H E C B A' --full-history -- file
108check_result 'K I H E C B A' --full-history --topo-order -- file
109check_result 'K I H E C B A' --full-history --date-order -- file
110check_result 'I E C B A' --simplify-merges -- file
111check_result 'I B A' -- file
112check_result 'I B A' --topo-order -- file
113check_result 'H' --first-parent -- another-file
114
115check_result 'E C B A' --full-history E -- lost
116test_expect_success 'full history simplification without parent' '
117 printf "%s\n" E C B A >expect &&
118 git log --pretty="$FMT" --full-history E -- lost |
119 unnote >actual &&
120 sed -e "s/^.* \([^ ]*\) .*/\1/" >check <actual &&
121 test_cmp expect check
122'
123
124test_expect_success '--full-diff is not affected by --parents' '
125 git log -p --pretty="%H" --full-diff -- file >expected &&
126 git log -p --pretty="%H" --full-diff --parents -- file >actual &&
127 test_cmp expected actual
128'
129
130test_done