3 test_description
='git p4 rename'
7 test_expect_success
'start p4d' '
11 # We rely on this behavior to detect for p4 move availability.
12 test_expect_success
'p4 help unknown returns 1' '
16 p4 help client >errs 2>&1
20 test_cmp expected retval &&
23 p4 help nosuchcommand >errs 2>&1
27 test_cmp expected retval &&
32 test_expect_success
'create files' '
35 p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
38 in file1 that will generate
39 enough context so that rename
40 and copy detection will find
41 something interesting to do.
45 * This blob looks a bit
48 int main(int argc, char **argv)
52 strcpy(text, "copy/rename this");
53 printf("text is %s\n", text);
58 p4 submit -d "add files"
62 # Rename a file and confirm that rename is not detected in P4.
63 # Rename the new file again with detectRenames option enabled and confirm that
64 # this is detected in P4.
65 # Rename the new file again adding an extra line, configure a big threshold in
66 # detectRenames and confirm that rename is not detected in P4.
67 # Repeat, this time with a smaller threshold and confirm that the rename is
69 test_expect_success
'detect renames' '
70 git p4 clone --dest="$git" //depot@all &&
71 test_when_finished cleanup_git &&
74 git config git-p4.skipSubmitEdit true &&
77 git commit -a -m "Rename file1 to file4" &&
78 git diff-tree -r -M HEAD &&
80 p4 filelog //depot/file4 >filelog &&
81 ! grep " from //depot" filelog &&
84 git commit -a -m "Rename file4 to file5" &&
85 git diff-tree -r -M HEAD &&
86 git config git-p4.detectRenames true &&
88 p4 filelog //depot/file5 >filelog &&
89 grep " from //depot/file4" filelog &&
92 echo update >>file6 &&
94 git commit -a -m "Rename file5 to file6 with changes" &&
95 git diff-tree -r -M HEAD &&
96 level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
97 test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
98 git config git-p4.detectRenames $(($level + 2)) &&
100 p4 filelog //depot/file6 >filelog &&
101 ! grep " from //depot" filelog &&
103 git mv file6 file7 &&
104 echo update >>file7 &&
106 git commit -a -m "Rename file6 to file7 with changes" &&
107 git diff-tree -r -M HEAD &&
108 level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
109 test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
110 git config git-p4.detectRenames $(($level - 2)) &&
112 p4 filelog //depot/file7 >filelog &&
113 grep " from //depot/file6" filelog
117 # Copy a file and confirm that copy is not detected in P4.
118 # Copy a file with detectCopies option enabled and confirm that copy is not
120 # Modify and copy a file with detectCopies option enabled and confirm that copy
122 # Copy a file with detectCopies and detectCopiesHarder options enabled and
123 # confirm that copy is detected in P4.
124 # Modify and copy a file, configure a bigger threshold in detectCopies and
125 # confirm that copy is not detected in P4.
126 # Modify and copy a file, configure a smaller threshold in detectCopies and
127 # confirm that copy is detected in P4.
128 test_expect_success
'detect copies' '
129 git p4 clone --dest="$git" //depot@all &&
130 test_when_finished cleanup_git &&
133 git config git-p4.skipSubmitEdit true &&
135 echo "file8" >>file2 &&
136 git commit -a -m "Differentiate file2" &&
140 git commit -a -m "Copy file2 to file8" &&
141 git diff-tree -r -C HEAD &&
143 p4 filelog //depot/file8 &&
144 ! p4 filelog //depot/file8 | grep -q "branch from" &&
146 echo "file9" >>file2 &&
147 git commit -a -m "Differentiate file2" &&
152 git commit -a -m "Copy file2 to file9" &&
153 git diff-tree -r -C HEAD &&
154 git config git-p4.detectCopies true &&
156 p4 filelog //depot/file9 &&
157 ! p4 filelog //depot/file9 | grep -q "branch from" &&
159 echo "file10" >>file2 &&
160 git commit -a -m "Differentiate file2" &&
163 echo "file2" >>file2 &&
165 git add file2 file10 &&
166 git commit -a -m "Modify and copy file2 to file10" &&
167 git diff-tree -r -C HEAD &&
168 src=$(git diff-tree -r -C HEAD | sed 1d | sed 2d | cut -f2) &&
169 test "$src" = file2 &&
171 p4 filelog //depot/file10 &&
172 p4 filelog //depot/file10 | grep -q "branch from //depot/file2" &&
174 echo "file11" >>file2 &&
175 git commit -a -m "Differentiate file2" &&
180 git commit -a -m "Copy file2 to file11" &&
181 git diff-tree -r -C --find-copies-harder HEAD &&
182 src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
183 test "$src" = file2 &&
184 git config git-p4.detectCopiesHarder true &&
186 p4 filelog //depot/file11 &&
187 p4 filelog //depot/file11 | grep -q "branch from //depot/file2" &&
189 echo "file12" >>file2 &&
190 git commit -a -m "Differentiate file2" &&
194 echo "some text" >>file12 &&
196 git commit -a -m "Copy file2 to file12 with changes" &&
197 git diff-tree -r -C --find-copies-harder HEAD &&
198 level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
199 test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
200 src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
201 test "$src" = file2 &&
202 git config git-p4.detectCopies $(($level + 2)) &&
204 p4 filelog //depot/file12 &&
205 ! p4 filelog //depot/file12 | grep -q "branch from" &&
207 echo "file13" >>file2 &&
208 git commit -a -m "Differentiate file2" &&
212 echo "different text" >>file13 &&
214 git commit -a -m "Copy file2 to file13 with changes" &&
215 git diff-tree -r -C --find-copies-harder HEAD &&
216 level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
217 test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
218 src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
219 test "$src" = file2 &&
220 git config git-p4.detectCopies $(($level - 2)) &&
222 p4 filelog //depot/file13 &&
223 p4 filelog //depot/file13 | grep -q "branch from //depot/file2"
227 # See if configurables can be set, and in particular if the run.move.allow
228 # variable exists, which allows admins to disable the "p4 move" command.
229 test_lazy_prereq P4D_HAVE_CONFIGURABLE_RUN_MOVE_ALLOW
'
230 p4 configure show run.move.allow >out &&
231 egrep ^run.move.allow: out
234 # If move can be disabled, turn it off and test p4 move handling
235 test_expect_success P4D_HAVE_CONFIGURABLE_RUN_MOVE_ALLOW \
236 'do not use p4 move when administratively disabled' '
237 test_when_finished "p4 configure set run.move.allow=1" &&
238 p4 configure set run.move.allow=0 &&
241 echo move-disallow-file >move-disallow-file &&
242 p4 add move-disallow-file &&
243 p4 submit -d "add move-disallow-file"
245 test_when_finished cleanup_git &&
246 git p4 clone --dest="$git" //depot &&
249 git config git-p4.skipSubmitEdit true &&
250 git config git-p4.detectRenames true &&
251 git mv move-disallow-file move-disallow-file-moved &&
252 git commit -m "move move-disallow-file" &&
257 test_expect_success
'kill p4d' '