3 test_description
='git p4 rename'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success
'start p4d' '
12 # We rely on this behavior to detect for p4 move availability.
13 test_expect_success
'"p4 help unknown" errors out' '
17 ! p4 help nosuchcommand
21 test_expect_success
'create files' '
24 p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
27 in file1 that will generate
28 enough context so that rename
29 and copy detection will find
30 something interesting to do.
34 * This blob looks a bit
37 int main(int argc, char **argv)
41 strcpy(text, "copy/rename this");
42 printf("text is %s\n", text);
47 p4 submit -d "add files"
51 # Rename a file and confirm that rename is not detected in P4.
52 # Rename the new file again with detectRenames option enabled and confirm that
53 # this is detected in P4.
54 # Rename the new file again adding an extra line, configure a big threshold in
55 # detectRenames and confirm that rename is not detected in P4.
56 # Repeat, this time with a smaller threshold and confirm that the rename is
58 test_expect_success
'detect renames' '
59 git p4 clone --dest="$git" //depot@all &&
60 test_when_finished cleanup_git &&
63 git config git-p4.skipSubmitEdit true &&
66 git commit -a -m "Rename file1 to file4" &&
67 git diff-tree -r -M HEAD &&
69 p4 filelog //depot/file4 >filelog &&
70 ! grep " from //depot" filelog &&
73 git commit -a -m "Rename file4 to file5" &&
74 git diff-tree -r -M HEAD &&
75 git config git-p4.detectRenames true &&
77 p4 filelog //depot/file5 >filelog &&
78 grep " from //depot/file4" filelog &&
81 echo update >>file6 &&
83 git commit -a -m "Rename file5 to file6 with changes" &&
84 git diff-tree -r -M HEAD &&
85 level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
86 test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
87 git config git-p4.detectRenames $(($level + 2)) &&
89 p4 filelog //depot/file6 >filelog &&
90 ! grep " from //depot" filelog &&
93 echo update >>file7 &&
95 git commit -a -m "Rename file6 to file7 with changes" &&
96 git diff-tree -r -M HEAD &&
97 level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
98 test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
99 git config git-p4.detectRenames $(($level - 2)) &&
101 p4 filelog //depot/file7 >filelog &&
102 grep " from //depot/file6" filelog
106 # Copy a file and confirm that copy is not detected in P4.
107 # Copy a file with detectCopies option enabled and confirm that copy is not
109 # Modify and copy a file with detectCopies option enabled and confirm that copy
111 # Copy a file with detectCopies and detectCopiesHarder options enabled and
112 # confirm that copy is detected in P4.
113 # Modify and copy a file, configure a bigger threshold in detectCopies and
114 # confirm that copy is not detected in P4.
115 # Modify and copy a file, configure a smaller threshold in detectCopies and
116 # confirm that copy is detected in P4.
117 test_expect_success
'detect copies' '
118 git p4 clone --dest="$git" //depot@all &&
119 test_when_finished cleanup_git &&
122 git config git-p4.skipSubmitEdit true &&
124 echo "file8" >>file2 &&
125 git commit -a -m "Differentiate file2" &&
129 git commit -a -m "Copy file2 to file8" &&
130 git diff-tree -r -C HEAD &&
132 p4 filelog //depot/file8 &&
133 ! p4 filelog //depot/file8 | grep -q "branch from" &&
135 echo "file9" >>file2 &&
136 git commit -a -m "Differentiate file2" &&
141 git commit -a -m "Copy file2 to file9" &&
142 git diff-tree -r -C HEAD &&
143 git config git-p4.detectCopies true &&
145 p4 filelog //depot/file9 &&
146 ! p4 filelog //depot/file9 | grep -q "branch from" &&
148 echo "file10" >>file2 &&
149 git commit -a -m "Differentiate file2" &&
152 echo "file2" >>file2 &&
154 git add file2 file10 &&
155 git commit -a -m "Modify and copy file2 to file10" &&
156 git diff-tree -r -C HEAD &&
157 src=$(git diff-tree -r -C HEAD | sed 1d | sed 2d | cut -f2) &&
158 test "$src" = file2 &&
160 p4 filelog //depot/file10 &&
161 p4 filelog //depot/file10 | grep -q "branch from //depot/file2" &&
163 echo "file11" >>file2 &&
164 git commit -a -m "Differentiate file2" &&
169 git commit -a -m "Copy file2 to file11" &&
170 git diff-tree -r -C --find-copies-harder HEAD &&
171 src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
172 test "$src" = file2 &&
173 git config git-p4.detectCopiesHarder true &&
175 p4 filelog //depot/file11 &&
176 p4 filelog //depot/file11 | grep -q "branch from //depot/file2" &&
178 echo "file12" >>file2 &&
179 git commit -a -m "Differentiate file2" &&
183 echo "some text" >>file12 &&
185 git commit -a -m "Copy file2 to file12 with changes" &&
186 git diff-tree -r -C --find-copies-harder HEAD &&
187 level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
188 test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
189 src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
190 test "$src" = file2 &&
191 git config git-p4.detectCopies $(($level + 2)) &&
193 p4 filelog //depot/file12 &&
194 ! p4 filelog //depot/file12 | grep -q "branch from" &&
196 echo "file13" >>file2 &&
197 git commit -a -m "Differentiate file2" &&
201 echo "different text" >>file13 &&
203 git commit -a -m "Copy file2 to file13 with changes" &&
204 git diff-tree -r -C --find-copies-harder HEAD &&
205 level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
206 test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
207 src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
208 test "$src" = file2 &&
209 git config git-p4.detectCopies $(($level - 2)) &&
211 p4 filelog //depot/file13 &&
212 p4 filelog //depot/file13 | grep -q "branch from //depot/file2"
216 # See if configurables can be set, and in particular if the run.move.allow
217 # variable exists, which allows admins to disable the "p4 move" command.
218 test_lazy_prereq P4D_HAVE_CONFIGURABLE_RUN_MOVE_ALLOW
'
219 p4 configure show run.move.allow >out &&
220 grep -E ^run.move.allow: out
223 # If move can be disabled, turn it off and test p4 move handling
224 test_expect_success P4D_HAVE_CONFIGURABLE_RUN_MOVE_ALLOW \
225 'do not use p4 move when administratively disabled' '
226 test_when_finished "p4 configure set run.move.allow=1" &&
227 p4 configure set run.move.allow=0 &&
230 echo move-disallow-file >move-disallow-file &&
231 p4 add move-disallow-file &&
232 p4 submit -d "add move-disallow-file"
234 test_when_finished cleanup_git &&
235 git p4 clone --dest="$git" //depot &&
238 git config git-p4.skipSubmitEdit true &&
239 git config git-p4.detectRenames true &&
240 git mv move-disallow-file move-disallow-file-moved &&
241 git commit -m "move move-disallow-file" &&