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