]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7003-filter-branch.sh
unquote_c_style: fix off-by-one.
[thirdparty/git.git] / t / t7003-filter-branch.sh
CommitLineData
6f6826c5
JS
1#!/bin/sh
2
3test_description='git-filter-branch'
4. ./test-lib.sh
5
6make_commit () {
7 lower=$(echo $1 | tr A-Z a-z)
8 echo $lower > $lower
9 git add $lower
aee078bf 10 test_tick
6f6826c5
JS
11 git commit -m $1
12 git tag $1
13}
14
15test_expect_success 'setup' '
16 make_commit A
17 make_commit B
18 git checkout -b branch B
19 make_commit D
20 make_commit E
21 git checkout master
22 make_commit C
23 git checkout branch
24 git merge C
25 git tag F
26 make_commit G
27 make_commit H
28'
29
5be60078 30H=$(git rev-parse H)
6f6826c5
JS
31
32test_expect_success 'rewrite identically' '
dfd05e38 33 git-filter-branch branch
6f6826c5 34'
6f6826c5 35test_expect_success 'result is really identical' '
dfd05e38 36 test $H = $(git rev-parse HEAD)
6f6826c5
JS
37'
38
39test_expect_success 'rewrite, renaming a specific file' '
dfd05e38 40 git-filter-branch -f --tree-filter "mv d doh || :" HEAD
6f6826c5
JS
41'
42
43test_expect_success 'test that the file was renamed' '
46eb449c
JS
44 test d = $(git show HEAD:doh) &&
45 test -f doh &&
46 test d = $(cat doh)
6f6826c5
JS
47'
48
dfd05e38 49git tag oldD HEAD~4
98409060 50test_expect_success 'rewrite one branch, keeping a side branch' '
dfd05e38
JS
51 git branch modD oldD &&
52 git-filter-branch -f --tree-filter "mv b boh || :" D..modD
98409060
JS
53'
54
55test_expect_success 'common ancestor is still common (unchanged)' '
5be60078 56 test "$(git merge-base modD D)" = "$(git rev-parse B)"
98409060
JS
57'
58
685ef546
JS
59test_expect_success 'filter subdirectory only' '
60 mkdir subdir &&
61 touch subdir/new &&
62 git add subdir/new &&
63 test_tick &&
64 git commit -m "subdir" &&
65 echo H > a &&
66 test_tick &&
67 git commit -m "not subdir" a &&
68 echo A > subdir/new &&
69 test_tick &&
70 git commit -m "again subdir" subdir/new &&
71 git rm a &&
72 test_tick &&
73 git commit -m "again not subdir" &&
dfd05e38
JS
74 git branch sub &&
75 git-filter-branch -f --subdirectory-filter subdir refs/heads/sub
685ef546
JS
76'
77
78test_expect_success 'subdirectory filter result looks okay' '
5be60078 79 test 2 = $(git rev-list sub | wc -l) &&
685ef546
JS
80 git show sub:new &&
81 ! git show sub:subdir
82'
83
cfabd6ee
JS
84test_expect_success 'setup and filter history that requires --full-history' '
85 git checkout master &&
86 mkdir subdir &&
87 echo A > subdir/new &&
88 git add subdir/new &&
89 test_tick &&
90 git commit -m "subdir on master" subdir/new &&
91 git rm a &&
92 test_tick &&
93 git commit -m "again subdir on master" &&
94 git merge branch &&
dfd05e38
JS
95 git branch sub-master &&
96 git-filter-branch -f --subdirectory-filter subdir sub-master
cfabd6ee
JS
97'
98
99test_expect_success 'subdirectory filter result looks okay' '
5be60078 100 test 3 = $(git rev-list -1 --parents sub-master | wc -w) &&
cfabd6ee
JS
101 git show sub-master^:new &&
102 git show sub-master^2:new &&
103 ! git show sub:subdir
104'
105
55f22ff2 106test_expect_success 'use index-filter to move into a subdirectory' '
dfd05e38
JS
107 git branch directorymoved &&
108 git-filter-branch -f --index-filter \
5be60078 109 "git ls-files -s | sed \"s-\\t-&newsubdir/-\" |
55f22ff2 110 GIT_INDEX_FILE=\$GIT_INDEX_FILE.new \
5be60078 111 git update-index --index-info &&
55f22ff2
JS
112 mv \$GIT_INDEX_FILE.new \$GIT_INDEX_FILE" directorymoved &&
113 test -z "$(git diff HEAD directorymoved:newsubdir)"'
114
8c1ce0f4 115test_expect_success 'stops when msg filter fails' '
dfd05e38 116 old=$(git rev-parse HEAD) &&
fdd7d48d 117 ! git-filter-branch -f --msg-filter false HEAD &&
dfd05e38
JS
118 test $old = $(git rev-parse HEAD) &&
119 rm -rf .git-rewrite
8c1ce0f4
JS
120'
121
f6b78c6e
JS
122test_expect_success 'author information is preserved' '
123 : > i &&
124 git add i &&
125 test_tick &&
126 GIT_AUTHOR_NAME="B V Uips" git commit -m bvuips &&
dfd05e38
JS
127 git branch preserved-author &&
128 git-filter-branch -f --msg-filter "cat; \
8c1ce0f4 129 test \$GIT_COMMIT != $(git rev-parse master) || \
f6b78c6e
JS
130 echo Hallo" \
131 preserved-author &&
132 test 1 = $(git rev-list --author="B V Uips" preserved-author | wc -l)
133'
134
135test_expect_success "remove a certain author's commits" '
136 echo i > i &&
137 test_tick &&
138 git commit -m i i &&
dfd05e38
JS
139 git branch removed-author &&
140 git-filter-branch -f --commit-filter "\
f6b78c6e
JS
141 if [ \"\$GIT_AUTHOR_NAME\" = \"B V Uips\" ];\
142 then\
f95eef15 143 skip_commit \"\$@\";
f6b78c6e
JS
144 else\
145 git commit-tree \"\$@\";\
146 fi" removed-author &&
147 cnt1=$(git rev-list master | wc -l) &&
148 cnt2=$(git rev-list removed-author | wc -l) &&
149 test $cnt1 -eq $(($cnt2 + 1)) &&
150 test 0 = $(git rev-list --author="B V Uips" removed-author | wc -l)
151'
152
dfd05e38
JS
153test_expect_success 'barf on invalid name' '
154 ! git filter-branch -f master xy-problem &&
155 ! git filter-branch -f HEAD^
156'
157
7e0f1704
JS
158test_expect_success '"map" works in commit filter' '
159 git filter-branch -f --commit-filter "\
160 parent=\$(git rev-parse \$GIT_COMMIT^) &&
161 mapped=\$(map \$parent) &&
162 actual=\$(echo \"\$@\" | sed \"s/^.*-p //\") &&
163 test \$mapped = \$actual &&
164 git commit-tree \"\$@\";" master~2..master &&
165 git rev-parse --verify master
166'
167
1fe32cb9
JH
168test_expect_success 'Name needing quotes' '
169
170 git checkout -b rerere A &&
171 mkdir foo &&
172 name="れれれ" &&
173 >foo/$name &&
174 git add foo &&
175 git commit -m "Adding a file" &&
176 git filter-branch --tree-filter "rm -fr foo" &&
177 ! git ls-files --error-unmatch "foo/$name" &&
178 test $(git rev-parse --verify rerere) != $(git rev-parse --verify A)
179
180'
181
6f6826c5 182test_done