]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7003-filter-branch.sh
rebase -i: mention the option to split commits in the man page
[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' '
dfd05e38 44 test d = $(git show HEAD:doh)
6f6826c5
JS
45'
46
dfd05e38 47git tag oldD HEAD~4
98409060 48test_expect_success 'rewrite one branch, keeping a side branch' '
dfd05e38
JS
49 git branch modD oldD &&
50 git-filter-branch -f --tree-filter "mv b boh || :" D..modD
98409060
JS
51'
52
53test_expect_success 'common ancestor is still common (unchanged)' '
5be60078 54 test "$(git merge-base modD D)" = "$(git rev-parse B)"
98409060
JS
55'
56
685ef546
JS
57test_expect_success 'filter subdirectory only' '
58 mkdir subdir &&
59 touch subdir/new &&
60 git add subdir/new &&
61 test_tick &&
62 git commit -m "subdir" &&
63 echo H > a &&
64 test_tick &&
65 git commit -m "not subdir" a &&
66 echo A > subdir/new &&
67 test_tick &&
68 git commit -m "again subdir" subdir/new &&
69 git rm a &&
70 test_tick &&
71 git commit -m "again not subdir" &&
dfd05e38
JS
72 git branch sub &&
73 git-filter-branch -f --subdirectory-filter subdir refs/heads/sub
685ef546
JS
74'
75
76test_expect_success 'subdirectory filter result looks okay' '
5be60078 77 test 2 = $(git rev-list sub | wc -l) &&
685ef546
JS
78 git show sub:new &&
79 ! git show sub:subdir
80'
81
cfabd6ee
JS
82test_expect_success 'setup and filter history that requires --full-history' '
83 git checkout master &&
84 mkdir subdir &&
85 echo A > subdir/new &&
86 git add subdir/new &&
87 test_tick &&
88 git commit -m "subdir on master" subdir/new &&
89 git rm a &&
90 test_tick &&
91 git commit -m "again subdir on master" &&
92 git merge branch &&
dfd05e38
JS
93 git branch sub-master &&
94 git-filter-branch -f --subdirectory-filter subdir sub-master
cfabd6ee
JS
95'
96
97test_expect_success 'subdirectory filter result looks okay' '
5be60078 98 test 3 = $(git rev-list -1 --parents sub-master | wc -w) &&
cfabd6ee
JS
99 git show sub-master^:new &&
100 git show sub-master^2:new &&
101 ! git show sub:subdir
102'
103
55f22ff2 104test_expect_success 'use index-filter to move into a subdirectory' '
dfd05e38
JS
105 git branch directorymoved &&
106 git-filter-branch -f --index-filter \
5be60078 107 "git ls-files -s | sed \"s-\\t-&newsubdir/-\" |
55f22ff2 108 GIT_INDEX_FILE=\$GIT_INDEX_FILE.new \
5be60078 109 git update-index --index-info &&
55f22ff2
JS
110 mv \$GIT_INDEX_FILE.new \$GIT_INDEX_FILE" directorymoved &&
111 test -z "$(git diff HEAD directorymoved:newsubdir)"'
112
8c1ce0f4 113test_expect_success 'stops when msg filter fails' '
dfd05e38
JS
114 old=$(git rev-parse HEAD) &&
115 ! git-filter-branch -f --msg-filter false &&
116 test $old = $(git rev-parse HEAD) &&
117 rm -rf .git-rewrite
8c1ce0f4
JS
118'
119
f6b78c6e
JS
120test_expect_success 'author information is preserved' '
121 : > i &&
122 git add i &&
123 test_tick &&
124 GIT_AUTHOR_NAME="B V Uips" git commit -m bvuips &&
dfd05e38
JS
125 git branch preserved-author &&
126 git-filter-branch -f --msg-filter "cat; \
8c1ce0f4 127 test \$GIT_COMMIT != $(git rev-parse master) || \
f6b78c6e
JS
128 echo Hallo" \
129 preserved-author &&
130 test 1 = $(git rev-list --author="B V Uips" preserved-author | wc -l)
131'
132
133test_expect_success "remove a certain author's commits" '
134 echo i > i &&
135 test_tick &&
136 git commit -m i i &&
dfd05e38
JS
137 git branch removed-author &&
138 git-filter-branch -f --commit-filter "\
f6b78c6e
JS
139 if [ \"\$GIT_AUTHOR_NAME\" = \"B V Uips\" ];\
140 then\
141 shift;\
142 while [ -n \"\$1\" ];\
143 do\
144 shift;\
145 echo \"\$1\";\
146 shift;\
147 done;\
148 else\
149 git commit-tree \"\$@\";\
150 fi" removed-author &&
151 cnt1=$(git rev-list master | wc -l) &&
152 cnt2=$(git rev-list removed-author | wc -l) &&
153 test $cnt1 -eq $(($cnt2 + 1)) &&
154 test 0 = $(git rev-list --author="B V Uips" removed-author | wc -l)
155'
156
dfd05e38
JS
157test_expect_success 'barf on invalid name' '
158 ! git filter-branch -f master xy-problem &&
159 ! git filter-branch -f HEAD^
160'
161
6f6826c5 162test_done