]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3419-rebase-patch-id.sh
The third batch
[thirdparty/git.git] / t / t3419-rebase-patch-id.sh
1 #!/bin/sh
2
3 test_description='git rebase - test patch id computation'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 scramble () {
12 i=0
13 while read x
14 do
15 if test $i -ne 0
16 then
17 echo "$x"
18 fi
19 i=$((($i+1) % 10))
20 done <"$1" >"$1.new"
21 mv -f "$1.new" "$1"
22 }
23
24 test_expect_success 'setup' '
25 git commit --allow-empty -m initial &&
26 git tag root
27 '
28
29 test_expect_success 'setup: 500 lines' '
30 rm -f .gitattributes &&
31 git checkout -q -f main &&
32 git reset --hard root &&
33 test_seq 500 >file &&
34 git add file &&
35 git commit -q -m initial &&
36 git branch -f other &&
37
38 scramble file &&
39 git add file &&
40 git commit -q -m "change big file" &&
41
42 git checkout -q other &&
43 : >newfile &&
44 git add newfile &&
45 git commit -q -m "add small file" &&
46
47 git cherry-pick main >/dev/null 2>&1 &&
48
49 git branch -f squashed main &&
50 git checkout -q -f squashed &&
51 git reset -q --soft HEAD~2 &&
52 git commit -q -m squashed &&
53
54 git branch -f mode main &&
55 git checkout -q -f mode &&
56 test_chmod +x file &&
57 git commit -q -a --amend &&
58
59 git branch -f modeother other &&
60 git checkout -q -f modeother &&
61 test_chmod +x file &&
62 git commit -q -a --amend
63 '
64
65 test_expect_success 'detect upstream patch' '
66 git checkout -q main^{} &&
67 scramble file &&
68 git add file &&
69 git commit -q -m "change big file again" &&
70 git checkout -q other^{} &&
71 git rebase main &&
72 git rev-list main...HEAD~ >revs &&
73 test_must_be_empty revs
74 '
75
76 test_expect_success 'detect upstream patch binary' '
77 echo "file binary" >.gitattributes &&
78 git checkout -q other^{} &&
79 git rebase main &&
80 git rev-list main...HEAD~ >revs &&
81 test_must_be_empty revs &&
82 test_when_finished "rm .gitattributes"
83 '
84
85 test_expect_success 'detect upstream patch modechange' '
86 git checkout -q modeother^{} &&
87 git rebase mode &&
88 git rev-list mode...HEAD~ >revs &&
89 test_must_be_empty revs
90 '
91
92 test_expect_success 'do not drop patch' '
93 git checkout -q other^{} &&
94 test_must_fail git rebase squashed &&
95 test_when_finished "git rebase --abort"
96 '
97
98 test_expect_success 'do not drop patch binary' '
99 echo "file binary" >.gitattributes &&
100 git checkout -q other^{} &&
101 test_must_fail git rebase squashed &&
102 test_when_finished "git rebase --abort" &&
103 test_when_finished "rm .gitattributes"
104 '
105
106 test_expect_success 'do not drop patch modechange' '
107 git checkout -q modeother^{} &&
108 git rebase other &&
109 cat >expected <<-\EOF &&
110 diff --git a/file b/file
111 old mode 100644
112 new mode 100755
113 EOF
114 git diff HEAD~ >modediff &&
115 test_cmp expected modediff
116 '
117
118 test_done