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)
48 test_expect_success
'rewrite one branch, keeping a side branch' '
49 git branch modD oldD &&
50 git-filter-branch -f --tree-filter "mv b boh || :" D..modD
53 test_expect_success
'common ancestor is still common (unchanged)' '
54 test "$(git merge-base modD D)" = "$(git rev-parse B)"
57 test_expect_success
'filter subdirectory only' '
62 git commit -m "subdir" &&
65 git commit -m "not subdir" a &&
66 echo A > subdir/new &&
68 git commit -m "again subdir" subdir/new &&
71 git commit -m "again not subdir" &&
73 git-filter-branch -f --subdirectory-filter subdir refs/heads/sub
76 test_expect_success
'subdirectory filter result looks okay' '
77 test 2 = $(git rev-list sub | wc -l) &&
82 test_expect_success
'setup and filter history that requires --full-history' '
83 git checkout master &&
85 echo A > subdir/new &&
88 git commit -m "subdir on master" subdir/new &&
91 git commit -m "again subdir on master" &&
93 git branch sub-master &&
94 git-filter-branch -f --subdirectory-filter subdir sub-master
97 test_expect_success
'subdirectory filter result looks okay' '
98 test 3 = $(git rev-list -1 --parents sub-master | wc -w) &&
99 git show sub-master^:new &&
100 git show sub-master^2:new &&
101 ! git show sub:subdir
104 test_expect_success
'use index-filter to move into a subdirectory' '
105 git branch directorymoved &&
106 git-filter-branch -f --index-filter \
107 "git ls-files -s | sed \"s-\\t-&newsubdir/-\" |
108 GIT_INDEX_FILE=\$GIT_INDEX_FILE.new \
109 git update-index --index-info &&
110 mv \$GIT_INDEX_FILE.new \$GIT_INDEX_FILE" directorymoved &&
111 test -z "$(git diff HEAD directorymoved:newsubdir)"'
113 test_expect_success
'stops when msg filter fails' '
114 old=$(git rev-parse HEAD) &&
115 ! git-filter-branch -f --msg-filter false &&
116 test $old = $(git rev-parse HEAD) &&
120 test_expect_success
'author information is preserved' '
124 GIT_AUTHOR_NAME="B V Uips" git commit -m bvuips &&
125 git branch preserved-author &&
126 git-filter-branch -f --msg-filter "cat; \
127 test \$GIT_COMMIT != $(git rev-parse master) || \
130 test 1 = $(git rev-list --author="B V Uips" preserved-author | wc -l)
133 test_expect_success
"remove a certain author's commits" '
137 git branch removed-author &&
138 git-filter-branch -f --commit-filter "\
139 if [ \"\$GIT_AUTHOR_NAME\" = \"B V Uips\" ];\
143 git commit-tree \"\$@\";\
144 fi" removed-author &&
145 cnt1=$(git rev-list master | wc -l) &&
146 cnt2=$(git rev-list removed-author | wc -l) &&
147 test $cnt1 -eq $(($cnt2 + 1)) &&
148 test 0 = $(git rev-list --author="B V Uips" removed-author | wc -l)
151 test_expect_success
'barf on invalid name' '
152 ! git filter-branch -f master xy-problem &&
153 ! git filter-branch -f HEAD^
156 test_expect_success
'"map" works in commit filter' '
157 git filter-branch -f --commit-filter "\
158 parent=\$(git rev-parse \$GIT_COMMIT^) &&
159 mapped=\$(map \$parent) &&
160 actual=\$(echo \"\$@\" | sed \"s/^.*-p //\") &&
161 test \$mapped = \$actual &&
162 git commit-tree \"\$@\";" master~2..master &&
163 git rev-parse --verify master