t / t9119-git-svn-info.shon commit checkout -m path: fix recreating conflicts (6d6f9ac)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 David D. Kilzer
   4
   5test_description='git svn info'
   6
   7. ./lib-git-svn.sh
   8
   9# Tested with: svn, version 1.4.4 (r25188)
  10v=`svn --version | sed -n -e 's/^svn, version \(1\.[0-9]*\.[0-9]*\).*$/\1/p'`
  11case $v in
  121.[45].*)
  13        ;;
  14*)
  15        say "skipping svn-info test (SVN version: $v not supported)"
  16        test_done
  17        ;;
  18esac
  19
  20ptouch() {
  21        perl -w -e '
  22                use strict;
  23                use POSIX qw(mktime);
  24                die "ptouch requires exactly 2 arguments" if @ARGV != 2;
  25                my $text_last_updated = shift @ARGV;
  26                my $git_file = shift @ARGV;
  27                die "\"$git_file\" does not exist" if ! -e $git_file;
  28                if ($text_last_updated
  29                    =~ /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/) {
  30                        my $mtime = mktime($6, $5, $4, $3, $2 - 1, $1 - 1900);
  31                        my $atime = $mtime;
  32                        utime $atime, $mtime, $git_file;
  33                }
  34        ' "`svn info $2 | grep '^Text Last Updated:'`" "$1"
  35}
  36
  37quoted_svnrepo="$(echo $svnrepo | sed 's/ /%20/')"
  38
  39test_expect_success 'setup repository and import' '
  40        mkdir info &&
  41        cd info &&
  42                echo FIRST > A &&
  43                echo one > file &&
  44                ln -s file symlink-file &&
  45                mkdir directory &&
  46                touch directory/.placeholder &&
  47                ln -s directory symlink-directory &&
  48                svn import -m "initial" . "$svnrepo" &&
  49        cd .. &&
  50        svn co "$svnrepo" svnwc &&
  51        cd svnwc &&
  52                echo foo > foo &&
  53                svn add foo &&
  54                svn commit -m "change outside directory" &&
  55                svn update &&
  56        cd .. &&
  57        mkdir gitwc &&
  58        cd gitwc &&
  59                git svn init "$svnrepo" &&
  60                git svn fetch &&
  61        cd .. &&
  62        ptouch gitwc/file svnwc/file &&
  63        ptouch gitwc/directory svnwc/directory &&
  64        ptouch gitwc/symlink-file svnwc/symlink-file &&
  65        ptouch gitwc/symlink-directory svnwc/symlink-directory
  66        '
  67
  68test_expect_success 'info' "
  69        (cd svnwc; svn info) > expected.info &&
  70        (cd gitwc; git svn info) > actual.info &&
  71        test_cmp expected.info actual.info
  72        "
  73
  74test_expect_success 'info --url' '
  75        test "$(cd gitwc; git svn info --url)" = "$quoted_svnrepo"
  76        '
  77
  78test_expect_success 'info .' "
  79        (cd svnwc; svn info .) > expected.info-dot &&
  80        (cd gitwc; git svn info .) > actual.info-dot &&
  81        test_cmp expected.info-dot actual.info-dot
  82        "
  83
  84test_expect_success 'info --url .' '
  85        test "$(cd gitwc; git svn info --url .)" = "$quoted_svnrepo"
  86        '
  87
  88test_expect_success 'info file' "
  89        (cd svnwc; svn info file) > expected.info-file &&
  90        (cd gitwc; git svn info file) > actual.info-file &&
  91        test_cmp expected.info-file actual.info-file
  92        "
  93
  94test_expect_success 'info --url file' '
  95        test "$(cd gitwc; git svn info --url file)" = "$quoted_svnrepo/file"
  96        '
  97
  98test_expect_success 'info directory' "
  99        (cd svnwc; svn info directory) > expected.info-directory &&
 100        (cd gitwc; git svn info directory) > actual.info-directory &&
 101        test_cmp expected.info-directory actual.info-directory
 102        "
 103
 104test_expect_success 'info inside directory' "
 105        (cd svnwc/directory; svn info) > expected.info-inside-directory &&
 106        (cd gitwc/directory; git svn info) > actual.info-inside-directory &&
 107        test_cmp expected.info-inside-directory actual.info-inside-directory
 108        "
 109
 110test_expect_success 'info --url directory' '
 111        test "$(cd gitwc; git svn info --url directory)" = "$quoted_svnrepo/directory"
 112        '
 113
 114test_expect_success 'info symlink-file' "
 115        (cd svnwc; svn info symlink-file) > expected.info-symlink-file &&
 116        (cd gitwc; git svn info symlink-file) > actual.info-symlink-file &&
 117        test_cmp expected.info-symlink-file actual.info-symlink-file
 118        "
 119
 120test_expect_success 'info --url symlink-file' '
 121        test "$(cd gitwc; git svn info --url symlink-file)" \
 122             = "$quoted_svnrepo/symlink-file"
 123        '
 124
 125test_expect_success 'info symlink-directory' "
 126        (cd svnwc; svn info symlink-directory) \
 127                > expected.info-symlink-directory &&
 128        (cd gitwc; git svn info symlink-directory) \
 129                > actual.info-symlink-directory &&
 130        test_cmp expected.info-symlink-directory actual.info-symlink-directory
 131        "
 132
 133test_expect_success 'info --url symlink-directory' '
 134        test "$(cd gitwc; git svn info --url symlink-directory)" \
 135             = "$quoted_svnrepo/symlink-directory"
 136        '
 137
 138test_expect_success 'info added-file' "
 139        echo two > gitwc/added-file &&
 140        cd gitwc &&
 141                git add added-file &&
 142        cd .. &&
 143        cp gitwc/added-file svnwc/added-file &&
 144        ptouch gitwc/added-file svnwc/added-file &&
 145        cd svnwc &&
 146                svn add added-file > /dev/null &&
 147        cd .. &&
 148        (cd svnwc; svn info added-file) > expected.info-added-file &&
 149        (cd gitwc; git svn info added-file) > actual.info-added-file &&
 150        test_cmp expected.info-added-file actual.info-added-file
 151        "
 152
 153test_expect_success 'info --url added-file' '
 154        test "$(cd gitwc; git svn info --url added-file)" \
 155             = "$quoted_svnrepo/added-file"
 156        '
 157
 158test_expect_success 'info added-directory' "
 159        mkdir gitwc/added-directory svnwc/added-directory &&
 160        ptouch gitwc/added-directory svnwc/added-directory &&
 161        touch gitwc/added-directory/.placeholder &&
 162        cd svnwc &&
 163                svn add added-directory > /dev/null &&
 164        cd .. &&
 165        cd gitwc &&
 166                git add added-directory &&
 167        cd .. &&
 168        (cd svnwc; svn info added-directory) \
 169                > expected.info-added-directory &&
 170        (cd gitwc; git svn info added-directory) \
 171                > actual.info-added-directory &&
 172        test_cmp expected.info-added-directory actual.info-added-directory
 173        "
 174
 175test_expect_success 'info --url added-directory' '
 176        test "$(cd gitwc; git svn info --url added-directory)" \
 177             = "$quoted_svnrepo/added-directory"
 178        '
 179
 180test_expect_success 'info added-symlink-file' "
 181        cd gitwc &&
 182                ln -s added-file added-symlink-file &&
 183                git add added-symlink-file &&
 184        cd .. &&
 185        cd svnwc &&
 186                ln -s added-file added-symlink-file &&
 187                svn add added-symlink-file > /dev/null &&
 188        cd .. &&
 189        ptouch gitwc/added-symlink-file svnwc/added-symlink-file &&
 190        (cd svnwc; svn info added-symlink-file) \
 191                > expected.info-added-symlink-file &&
 192        (cd gitwc; git svn info added-symlink-file) \
 193                > actual.info-added-symlink-file &&
 194        test_cmp expected.info-added-symlink-file \
 195                 actual.info-added-symlink-file
 196        "
 197
 198test_expect_success 'info --url added-symlink-file' '
 199        test "$(cd gitwc; git svn info --url added-symlink-file)" \
 200             = "$quoted_svnrepo/added-symlink-file"
 201        '
 202
 203test_expect_success 'info added-symlink-directory' "
 204        cd gitwc &&
 205                ln -s added-directory added-symlink-directory &&
 206                git add added-symlink-directory &&
 207        cd .. &&
 208        cd svnwc &&
 209                ln -s added-directory added-symlink-directory &&
 210                svn add added-symlink-directory > /dev/null &&
 211        cd .. &&
 212        ptouch gitwc/added-symlink-directory svnwc/added-symlink-directory &&
 213        (cd svnwc; svn info added-symlink-directory) \
 214                > expected.info-added-symlink-directory &&
 215        (cd gitwc; git svn info added-symlink-directory) \
 216                > actual.info-added-symlink-directory &&
 217        test_cmp expected.info-added-symlink-directory \
 218                 actual.info-added-symlink-directory
 219        "
 220
 221test_expect_success 'info --url added-symlink-directory' '
 222        test "$(cd gitwc; git svn info --url added-symlink-directory)" \
 223             = "$quoted_svnrepo/added-symlink-directory"
 224        '
 225
 226# The next few tests replace the "Text Last Updated" value with a
 227# placeholder since git doesn't have a way to know the date that a
 228# now-deleted file was last checked out locally.  Internally it
 229# simply reuses the Last Changed Date.
 230
 231test_expect_success 'info deleted-file' "
 232        cd gitwc &&
 233                git rm -f file > /dev/null &&
 234        cd .. &&
 235        cd svnwc &&
 236                svn rm --force file > /dev/null &&
 237        cd .. &&
 238        (cd svnwc; svn info file) |
 239        sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
 240                > expected.info-deleted-file &&
 241        (cd gitwc; git svn info file) |
 242        sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
 243                > actual.info-deleted-file &&
 244        test_cmp expected.info-deleted-file actual.info-deleted-file
 245        "
 246
 247test_expect_success 'info --url file (deleted)' '
 248        test "$(cd gitwc; git svn info --url file)" \
 249             = "$quoted_svnrepo/file"
 250        '
 251
 252test_expect_success 'info deleted-directory' "
 253        cd gitwc &&
 254                git rm -r -f directory > /dev/null &&
 255        cd .. &&
 256        cd svnwc &&
 257                svn rm --force directory > /dev/null &&
 258        cd .. &&
 259        (cd svnwc; svn info directory) |
 260        sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
 261                > expected.info-deleted-directory &&
 262        (cd gitwc; git svn info directory) |
 263        sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
 264                > actual.info-deleted-directory &&
 265        test_cmp expected.info-deleted-directory actual.info-deleted-directory
 266        "
 267
 268test_expect_success 'info --url directory (deleted)' '
 269        test "$(cd gitwc; git svn info --url directory)" \
 270             = "$quoted_svnrepo/directory"
 271        '
 272
 273test_expect_success 'info deleted-symlink-file' "
 274        cd gitwc &&
 275                git rm -f symlink-file > /dev/null &&
 276        cd .. &&
 277        cd svnwc &&
 278                svn rm --force symlink-file > /dev/null &&
 279        cd .. &&
 280        (cd svnwc; svn info symlink-file) |
 281        sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
 282                > expected.info-deleted-symlink-file &&
 283        (cd gitwc; git svn info symlink-file) |
 284        sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
 285                > actual.info-deleted-symlink-file &&
 286        test_cmp expected.info-deleted-symlink-file \
 287                 actual.info-deleted-symlink-file
 288        "
 289
 290test_expect_success 'info --url symlink-file (deleted)' '
 291        test "$(cd gitwc; git svn info --url symlink-file)" \
 292             = "$quoted_svnrepo/symlink-file"
 293        '
 294
 295test_expect_success 'info deleted-symlink-directory' "
 296        cd gitwc &&
 297                git rm -f symlink-directory > /dev/null &&
 298        cd .. &&
 299        cd svnwc &&
 300                svn rm --force symlink-directory > /dev/null &&
 301        cd .. &&
 302        (cd svnwc; svn info symlink-directory) |
 303        sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
 304                 > expected.info-deleted-symlink-directory &&
 305        (cd gitwc; git svn info symlink-directory) |
 306        sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
 307                 > actual.info-deleted-symlink-directory &&
 308        test_cmp expected.info-deleted-symlink-directory \
 309                 actual.info-deleted-symlink-directory
 310        "
 311
 312test_expect_success 'info --url symlink-directory (deleted)' '
 313        test "$(cd gitwc; git svn info --url symlink-directory)" \
 314             = "$quoted_svnrepo/symlink-directory"
 315        '
 316
 317# NOTE: git does not have the concept of replaced objects,
 318# so we can't test for files in that state.
 319
 320test_expect_success 'info unknown-file' "
 321        echo two > gitwc/unknown-file &&
 322        (cd gitwc; test_must_fail git svn info unknown-file) \
 323                 2> actual.info-unknown-file &&
 324        grep unknown-file actual.info-unknown-file
 325        "
 326
 327test_expect_success 'info --url unknown-file' '
 328        echo two > gitwc/unknown-file &&
 329        (cd gitwc; test_must_fail git svn info --url unknown-file) \
 330                 2> actual.info-url-unknown-file &&
 331        grep unknown-file actual.info-url-unknown-file
 332        '
 333
 334test_expect_success 'info unknown-directory' "
 335        mkdir gitwc/unknown-directory svnwc/unknown-directory &&
 336        (cd gitwc; test_must_fail git svn info unknown-directory) \
 337                 2> actual.info-unknown-directory &&
 338        grep unknown-directory actual.info-unknown-directory
 339        "
 340
 341test_expect_success 'info --url unknown-directory' '
 342        (cd gitwc; test_must_fail git svn info --url unknown-directory) \
 343                 2> actual.info-url-unknown-directory &&
 344        grep unknown-directory actual.info-url-unknown-directory
 345        '
 346
 347test_expect_success 'info unknown-symlink-file' "
 348        cd gitwc &&
 349                ln -s unknown-file unknown-symlink-file &&
 350        cd .. &&
 351        (cd gitwc; test_must_fail git svn info unknown-symlink-file) \
 352                 2> actual.info-unknown-symlink-file &&
 353        grep unknown-symlink-file actual.info-unknown-symlink-file
 354        "
 355
 356test_expect_success 'info --url unknown-symlink-file' '
 357        (cd gitwc; test_must_fail git svn info --url unknown-symlink-file) \
 358                 2> actual.info-url-unknown-symlink-file &&
 359        grep unknown-symlink-file actual.info-url-unknown-symlink-file
 360        '
 361
 362test_expect_success 'info unknown-symlink-directory' "
 363        cd gitwc &&
 364                ln -s unknown-directory unknown-symlink-directory &&
 365        cd .. &&
 366        (cd gitwc; test_must_fail git svn info unknown-symlink-directory) \
 367                 2> actual.info-unknown-symlink-directory &&
 368        grep unknown-symlink-directory actual.info-unknown-symlink-directory
 369        "
 370
 371test_expect_success 'info --url unknown-symlink-directory' '
 372        (cd gitwc; test_must_fail git svn info --url unknown-symlink-directory) \
 373                 2> actual.info-url-unknown-symlink-directory &&
 374        grep unknown-symlink-directory actual.info-url-unknown-symlink-directory
 375        '
 376
 377test_done