1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
|
#!/bin/sh
test_description='git p4 rename'
. ./lib-git-p4.sh
test_expect_success 'start p4d' '
start_p4d
'
# We rely on this behavior to detect for p4 move availability.
test_expect_success 'p4 help unknown returns 1' '
(
cd "$cli" &&
(
p4 help client >errs 2>&1
echo $? >retval
)
echo 0 >expected &&
test_cmp expected retval &&
rm retval &&
(
p4 help nosuchcommand >errs 2>&1
echo $? >retval
)
echo 1 >expected &&
test_cmp expected retval &&
rm retval
)
'
test_expect_success 'create files' '
(
cd "$cli" &&
p4 client -o | sed "/LineEnd/s/:.*/:unix/" | p4 client -i &&
cat >file1 <<-EOF &&
A large block of text
in file1 that will generate
enough context so that rename
and copy detection will find
something interesting to do.
EOF
cat >file2 <<-EOF &&
/*
* This blob looks a bit
* different.
*/
int main(int argc, char **argv)
{
char text[200];
strcpy(text, "copy/rename this");
printf("text is %s\n", text);
return 0;
}
EOF
p4 add file1 file2 &&
p4 submit -d "add files"
)
'
# Rename a file and confirm that rename is not detected in P4.
# Rename the new file again with detectRenames option enabled and confirm that
# this is detected in P4.
# Rename the new file again adding an extra line, configure a big threshold in
# detectRenames and confirm that rename is not detected in P4.
# Repeat, this time with a smaller threshold and confirm that the rename is
# detected in P4.
test_expect_success 'detect renames' '
git p4 clone --dest="$git" //depot@all &&
test_when_finished cleanup_git &&
(
cd "$git" &&
git config git-p4.skipSubmitEdit true &&
git mv file1 file4 &&
git commit -a -m "Rename file1 to file4" &&
git diff-tree -r -M HEAD &&
git p4 submit &&
p4 filelog //depot/file4 >filelog &&
! grep " from //depot" filelog &&
git mv file4 file5 &&
git commit -a -m "Rename file4 to file5" &&
git diff-tree -r -M HEAD &&
git config git-p4.detectRenames true &&
git p4 submit &&
p4 filelog //depot/file5 >filelog &&
grep " from //depot/file4" filelog &&
git mv file5 file6 &&
echo update >>file6 &&
git add file6 &&
git commit -a -m "Rename file5 to file6 with changes" &&
git diff-tree -r -M HEAD &&
level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
git config git-p4.detectRenames $(($level + 2)) &&
git p4 submit &&
p4 filelog //depot/file6 >filelog &&
! grep " from //depot" filelog &&
git mv file6 file7 &&
echo update >>file7 &&
git add file7 &&
git commit -a -m "Rename file6 to file7 with changes" &&
git diff-tree -r -M HEAD &&
level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") &&
test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
git config git-p4.detectRenames $(($level - 2)) &&
git p4 submit &&
p4 filelog //depot/file7 >filelog &&
grep " from //depot/file6" filelog
)
'
# Copy a file and confirm that copy is not detected in P4.
# Copy a file with detectCopies option enabled and confirm that copy is not
# detected in P4.
# Modify and copy a file with detectCopies option enabled and confirm that copy
# is detected in P4.
# Copy a file with detectCopies and detectCopiesHarder options enabled and
# confirm that copy is detected in P4.
# Modify and copy a file, configure a bigger threshold in detectCopies and
# confirm that copy is not detected in P4.
# Modify and copy a file, configure a smaller threshold in detectCopies and
# confirm that copy is detected in P4.
test_expect_success 'detect copies' '
git p4 clone --dest="$git" //depot@all &&
test_when_finished cleanup_git &&
(
cd "$git" &&
git config git-p4.skipSubmitEdit true &&
cp file2 file8 &&
git add file8 &&
git commit -a -m "Copy file2 to file8" &&
git diff-tree -r -C HEAD &&
git p4 submit &&
p4 filelog //depot/file8 &&
p4 filelog //depot/file8 | test_must_fail grep -q "branch from" &&
cp file2 file9 &&
git add file9 &&
git commit -a -m "Copy file2 to file9" &&
git diff-tree -r -C HEAD &&
git config git-p4.detectCopies true &&
git p4 submit &&
p4 filelog //depot/file9 &&
p4 filelog //depot/file9 | test_must_fail grep -q "branch from" &&
echo "file2" >>file2 &&
cp file2 file10 &&
git add file2 file10 &&
git commit -a -m "Modify and copy file2 to file10" &&
git diff-tree -r -C HEAD &&
git p4 submit &&
p4 filelog //depot/file10 &&
p4 filelog //depot/file10 | grep -q "branch from //depot/file" &&
cp file2 file11 &&
git add file11 &&
git commit -a -m "Copy file2 to file11" &&
git diff-tree -r -C --find-copies-harder HEAD &&
src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
test "$src" = file10 &&
git config git-p4.detectCopiesHarder true &&
git p4 submit &&
p4 filelog //depot/file11 &&
p4 filelog //depot/file11 | grep -q "branch from //depot/file" &&
cp file2 file12 &&
echo "some text" >>file12 &&
git add file12 &&
git commit -a -m "Copy file2 to file12 with changes" &&
git diff-tree -r -C --find-copies-harder HEAD &&
level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 &&
src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
test "$src" = file10 -o "$src" = file11 &&
git config git-p4.detectCopies $(($level + 2)) &&
git p4 submit &&
p4 filelog //depot/file12 &&
p4 filelog //depot/file12 | test_must_fail grep -q "branch from" &&
cp file2 file13 &&
echo "different text" >>file13 &&
git add file13 &&
git commit -a -m "Copy file2 to file13 with changes" &&
git diff-tree -r -C --find-copies-harder HEAD &&
level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") &&
test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 &&
src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) &&
test "$src" = file10 -o "$src" = file11 -o "$src" = file12 &&
git config git-p4.detectCopies $(($level - 2)) &&
git p4 submit &&
p4 filelog //depot/file13 &&
p4 filelog //depot/file13 | grep -q "branch from //depot/file"
)
'
# See if configurables can be set, and in particular if the run.move.allow
# variable exists, which allows admins to disable the "p4 move" command.
test_expect_success 'p4 configure command and run.move.allow are available' '
p4 configure show run.move.allow >out ; retval=$? &&
test $retval = 0 &&
{
egrep ^run.move.allow: out &&
test_set_prereq P4D_HAVE_CONFIGURABLE_RUN_MOVE_ALLOW ||
true
} || true
'
# If move can be disabled, turn it off and test p4 move handling
test_expect_success P4D_HAVE_CONFIGURABLE_RUN_MOVE_ALLOW \
'do not use p4 move when administratively disabled' '
test_when_finished "p4 configure set run.move.allow=1" &&
p4 configure set run.move.allow=0 &&
(
cd "$cli" &&
echo move-disallow-file >move-disallow-file &&
p4 add move-disallow-file &&
p4 submit -d "add move-disallow-file"
) &&
test_when_finished cleanup_git &&
git p4 clone --dest="$git" //depot &&
(
cd "$git" &&
git config git-p4.skipSubmitEdit true &&
git config git-p4.detectRenames true &&
git mv move-disallow-file move-disallow-file-moved &&
git commit -m "move move-disallow-file" &&
git p4 submit
)
'
test_expect_success 'kill p4d' '
kill_p4d
'
test_done
|