Merge branch 'jc/ci-upload-artifact-and-linux32'
[git/gitster.git] / t / t9814-git-p4-rename.sh
blob00df6ebd3bdc03f3ebef6cd20af66325e6ee713a
1 #!/bin/sh
3 test_description='git p4 rename'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./lib-git-p4.sh
8 test_expect_success 'start p4d' '
9 start_p4d
12 # We rely on this behavior to detect for p4 move availability.
13 test_expect_success '"p4 help unknown" errors out' '
15 cd "$cli" &&
16 p4 help client &&
17 ! p4 help nosuchcommand
21 test_expect_success 'create files' '
23 cd "$cli" &&
24 p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
25 cat >file1 <<-EOF &&
26 A large block of text
27 in file1 that will generate
28 enough context so that rename
29 and copy detection will find
30 something interesting to do.
31 EOF
32 cat >file2 <<-EOF &&
34 * This blob looks a bit
35 * different.
37 int main(int argc, char **argv)
39 char text[200];
41 strcpy(text, "copy/rename this");
42 printf("text is %s\n", text);
43 return 0;
45 EOF
46 p4 add file1 file2 &&
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
57 # detected in P4.
58 test_expect_success 'detect renames' '
59 git p4 clone --dest="$git" //depot@all &&
60 test_when_finished cleanup_git &&
62 cd "$git" &&
63 git config git-p4.skipSubmitEdit true &&
65 git mv file1 file4 &&
66 git commit -a -m "Rename file1 to file4" &&
67 git diff-tree -r -M HEAD &&
68 git p4 submit &&
69 p4 filelog //depot/file4 >filelog &&
70 ! grep " from //depot" filelog &&
72 git mv file4 file5 &&
73 git commit -a -m "Rename file4 to file5" &&
74 git diff-tree -r -M HEAD &&
75 git config git-p4.detectRenames true &&
76 git p4 submit &&
77 p4 filelog //depot/file5 >filelog &&
78 grep " from //depot/file4" filelog &&
80 git mv file5 file6 &&
81 echo update >>file6 &&
82 git add 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)) &&
88 git p4 submit &&
89 p4 filelog //depot/file6 >filelog &&
90 ! grep " from //depot" filelog &&
92 git mv file6 file7 &&
93 echo update >>file7 &&
94 git add 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)) &&
100 git p4 submit &&
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
108 # detected in P4.
109 # Modify and copy a file with detectCopies option enabled and confirm that copy
110 # is detected in P4.
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 &&
121 cd "$git" &&
122 git config git-p4.skipSubmitEdit true &&
124 echo "file8" >>file2 &&
125 git commit -a -m "Differentiate file2" &&
126 git p4 submit &&
127 cp file2 file8 &&
128 git add file8 &&
129 git commit -a -m "Copy file2 to file8" &&
130 git diff-tree -r -C HEAD &&
131 git p4 submit &&
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" &&
137 git p4 submit &&
139 cp file2 file9 &&
140 git add file9 &&
141 git commit -a -m "Copy file2 to file9" &&
142 git diff-tree -r -C HEAD &&
143 git config git-p4.detectCopies true &&
144 git p4 submit &&
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" &&
150 git p4 submit &&
152 echo "file2" >>file2 &&
153 cp file2 file10 &&
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 &&
159 git p4 submit &&
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" &&
165 git p4 submit &&
167 cp file2 file11 &&
168 git add file11 &&
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 &&
174 git p4 submit &&
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" &&
180 git p4 submit &&
182 cp file2 file12 &&
183 echo "some text" >>file12 &&
184 git add 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)) &&
192 git p4 submit &&
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" &&
198 git p4 submit &&
200 cp file2 file13 &&
201 echo "different text" >>file13 &&
202 git add 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)) &&
210 git p4 submit &&
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 &&
229 cd "$cli" &&
230 echo move-disallow-file >move-disallow-file &&
231 p4 add move-disallow-file &&
232 p4 submit -d "add move-disallow-file"
233 ) &&
234 test_when_finished cleanup_git &&
235 git p4 clone --dest="$git" //depot &&
237 cd "$git" &&
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" &&
242 git p4 submit
246 test_done