Merge branch 'jc/clone'
[git/mingw/4msysgit/wingit-dll.git] / t / t7003-filter-branch.sh
blobbc6e2ddb19093fbdc9e4f94cbec71d369f0251ed
1 #!/bin/sh
3 test_description='git-filter-branch'
4 . ./test-lib.sh
6 make_commit () {
7 lower=$(echo $1 | tr A-Z a-z)
8 echo $lower > $lower
9 git add $lower
10 test_tick
11 git commit -m $1
12 git tag $1
15 test_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
30 H=$(git rev-parse H)
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)
47 git tag oldD HEAD~4
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' '
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" &&
72 git branch sub &&
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) &&
78 git show sub:new &&
79 ! git show sub:subdir
82 test_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 &&
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) &&
117 rm -rf .git-rewrite
120 test_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 &&
125 git branch preserved-author &&
126 git-filter-branch -f --msg-filter "cat; \
127 test \$GIT_COMMIT != $(git rev-parse master) || \
128 echo Hallo" \
129 preserved-author &&
130 test 1 = $(git rev-list --author="B V Uips" preserved-author | wc -l)
133 test_expect_success "remove a certain author's commits" '
134 echo i > i &&
135 test_tick &&
136 git commit -m i i &&
137 git branch removed-author &&
138 git-filter-branch -f --commit-filter "\
139 if [ \"\$GIT_AUTHOR_NAME\" = \"B V Uips\" ];\
140 then\
141 shift;\
142 while [ -n \"\$1\" ];\
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)
157 test_expect_success 'barf on invalid name' '
158 ! git filter-branch -f master xy-problem &&
159 ! git filter-branch -f HEAD^
162 test_done