3 test_description
='git-filter-branch'
7 lower
=$
(echo $1 |
tr A-Z a-z
)
15 test_expect_success
'setup' '
18 git checkout -b branch B
32 test_expect_success
'rewrite identically' '
33 git-filter-branch branch
35 test_expect_success
'result is really identical' '
36 test $H = $(git rev-parse HEAD)
39 test_expect_success
'rewrite, renaming a specific file' '
40 git-filter-branch -f --tree-filter "mv d doh || :" HEAD
43 test_expect_success
'test that the file was renamed' '
44 test d = $(git show HEAD:doh) &&
50 test_expect_success
'rewrite one branch, keeping a side branch' '
51 git branch modD oldD &&
52 git-filter-branch -f --tree-filter "mv b boh || :" D..modD
55 test_expect_success
'common ancestor is still common (unchanged)' '
56 test "$(git merge-base modD D)" = "$(git rev-parse B)"
59 test_expect_success
'filter subdirectory only' '
64 git commit -m "subdir" &&
67 git commit -m "not subdir" a &&
68 echo A > subdir/new &&
70 git commit -m "again subdir" subdir/new &&
73 git commit -m "again not subdir" &&
75 git-filter-branch -f --subdirectory-filter subdir refs/heads/sub
78 test_expect_success
'subdirectory filter result looks okay' '
79 test 2 = $(git rev-list sub | wc -l) &&
84 test_expect_success
'setup and filter history that requires --full-history' '
85 git checkout master &&
87 echo A > subdir/new &&
90 git commit -m "subdir on master" subdir/new &&
93 git commit -m "again subdir on master" &&
95 git branch sub-master &&
96 git-filter-branch -f --subdirectory-filter subdir sub-master
99 test_expect_success
'subdirectory filter result looks okay' '
100 test 3 = $(git rev-list -1 --parents sub-master | wc -w) &&
101 git show sub-master^:new &&
102 git show sub-master^2:new &&
103 ! git show sub:subdir
106 test_expect_success
'use index-filter to move into a subdirectory' '
107 git branch directorymoved &&
108 git-filter-branch -f --index-filter \
109 "git ls-files -s | sed \"s-\\t-&newsubdir/-\" |
110 GIT_INDEX_FILE=\$GIT_INDEX_FILE.new \
111 git update-index --index-info &&
112 mv \$GIT_INDEX_FILE.new \$GIT_INDEX_FILE" directorymoved &&
113 test -z "$(git diff HEAD directorymoved:newsubdir)"'
115 test_expect_success
'stops when msg filter fails' '
116 old=$(git rev-parse HEAD) &&
117 ! git-filter-branch -f --msg-filter false &&
118 test $old = $(git rev-parse HEAD) &&
122 test_expect_success
'author information is preserved' '
126 GIT_AUTHOR_NAME="B V Uips" git commit -m bvuips &&
127 git branch preserved-author &&
128 git-filter-branch -f --msg-filter "cat; \
129 test \$GIT_COMMIT != $(git rev-parse master) || \
132 test 1 = $(git rev-list --author="B V Uips" preserved-author | wc -l)
135 test_expect_success
"remove a certain author's commits" '
139 git branch removed-author &&
140 git-filter-branch -f --commit-filter "\
141 if [ \"\$GIT_AUTHOR_NAME\" = \"B V Uips\" ];\
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)
153 test_expect_success
'barf on invalid name' '
154 ! git filter-branch -f master xy-problem &&
155 ! git filter-branch -f HEAD^
158 test_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