t / t9119-git-svn-info.shon commit git svn info: tests: do not use set -e (e9a805a)
   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
  37test_expect_success 'setup repository and import' '
  38        mkdir info &&
  39        cd info &&
  40                echo FIRST > A &&
  41                echo one > file &&
  42                ln -s file symlink-file &&
  43                mkdir directory &&
  44                touch directory/.placeholder &&
  45                ln -s directory symlink-directory &&
  46                svn import -m "initial" . "$svnrepo" &&
  47        cd .. &&
  48        mkdir gitwc &&
  49        cd gitwc &&
  50                git-svn init "$svnrepo" &&
  51                git-svn fetch &&
  52        cd .. &&
  53        svn co "$svnrepo" svnwc &&
  54        ptouch svnwc/file gitwc/file &&
  55        ptouch svnwc/directory gitwc/directory &&
  56        ptouch svnwc/symlink-file gitwc/symlink-file &&
  57        ptouch svnwc/symlink-directory gitwc/symlink-directory
  58        '
  59
  60test_expect_success 'info' "
  61        (cd svnwc; svn info) > expected.info &&
  62        (cd gitwc; git-svn info) > actual.info &&
  63        git-diff expected.info actual.info
  64        "
  65
  66test_expect_success 'info --url' '
  67        test "$(cd gitwc; git-svn info --url)" = "$svnrepo"
  68        '
  69
  70test_expect_success 'info .' "
  71        (cd svnwc; svn info .) > expected.info-dot &&
  72        (cd gitwc; git-svn info .) > actual.info-dot &&
  73        git-diff expected.info-dot actual.info-dot
  74        "
  75
  76test_expect_success 'info --url .' '
  77        test "$(cd gitwc; git-svn info --url .)" = "$svnrepo"
  78        '
  79
  80test_expect_success 'info file' "
  81        (cd svnwc; svn info file) > expected.info-file &&
  82        (cd gitwc; git-svn info file) > actual.info-file &&
  83        git-diff expected.info-file actual.info-file
  84        "
  85
  86test_expect_success 'info --url file' '
  87        test "$(cd gitwc; git-svn info --url file)" = "$svnrepo/file"
  88        '
  89
  90test_expect_success 'info directory' "
  91        (cd svnwc; svn info directory) > expected.info-directory &&
  92        (cd gitwc; git-svn info directory) > actual.info-directory &&
  93        git-diff expected.info-directory actual.info-directory
  94        "
  95
  96test_expect_success 'info --url directory' '
  97        test "$(cd gitwc; git-svn info --url directory)" = "$svnrepo/directory"
  98        '
  99
 100test_expect_success 'info symlink-file' "
 101        (cd svnwc; svn info symlink-file) > expected.info-symlink-file &&
 102        (cd gitwc; git-svn info symlink-file) > actual.info-symlink-file &&
 103        git-diff expected.info-symlink-file actual.info-symlink-file
 104        "
 105
 106test_expect_success 'info --url symlink-file' '
 107        test "$(cd gitwc; git-svn info --url symlink-file)" \
 108             = "$svnrepo/symlink-file"
 109        '
 110
 111test_expect_success 'info symlink-directory' "
 112        (cd svnwc; svn info symlink-directory) \
 113                > expected.info-symlink-directory &&
 114        (cd gitwc; git-svn info symlink-directory) \
 115                > actual.info-symlink-directory &&
 116        git-diff expected.info-symlink-directory actual.info-symlink-directory
 117        "
 118
 119test_expect_success 'info --url symlink-directory' '
 120        test "$(cd gitwc; git-svn info --url symlink-directory)" \
 121             = "$svnrepo/symlink-directory"
 122        '
 123
 124test_expect_success 'info added-file' "
 125        echo two > gitwc/added-file &&
 126        cd gitwc &&
 127                git add added-file &&
 128        cd .. &&
 129        cp gitwc/added-file svnwc/added-file &&
 130        ptouch gitwc/added-file svnwc/added-file &&
 131        cd svnwc &&
 132                svn add added-file > /dev/null &&
 133        cd .. &&
 134        (cd svnwc; svn info added-file) > expected.info-added-file &&
 135        (cd gitwc; git-svn info added-file) > actual.info-added-file &&
 136        git-diff expected.info-added-file actual.info-added-file
 137        "
 138
 139test_expect_success 'info --url added-file' '
 140        test "$(cd gitwc; git-svn info --url added-file)" \
 141             = "$svnrepo/added-file"
 142        '
 143
 144test_expect_success 'info added-directory' "
 145        mkdir gitwc/added-directory svnwc/added-directory &&
 146        ptouch gitwc/added-directory svnwc/added-directory &&
 147        touch gitwc/added-directory/.placeholder &&
 148        cd svnwc &&
 149                svn add added-directory > /dev/null &&
 150        cd .. &&
 151        cd gitwc &&
 152                git add added-directory &&
 153        cd .. &&
 154        (cd svnwc; svn info added-directory) \
 155                > expected.info-added-directory &&
 156        (cd gitwc; git-svn info added-directory) \
 157                > actual.info-added-directory &&
 158        git-diff expected.info-added-directory actual.info-added-directory
 159        "
 160
 161test_expect_success 'info --url added-directory' '
 162        test "$(cd gitwc; git-svn info --url added-directory)" \
 163             = "$svnrepo/added-directory"
 164        '
 165
 166test_expect_success 'info added-symlink-file' "
 167        cd gitwc &&
 168                ln -s added-file added-symlink-file &&
 169                git add added-symlink-file &&
 170        cd .. &&
 171        cd svnwc &&
 172                ln -s added-file added-symlink-file &&
 173                svn add added-symlink-file > /dev/null &&
 174        cd .. &&
 175        ptouch gitwc/added-symlink-file svnwc/added-symlink-file &&
 176        (cd svnwc; svn info added-symlink-file) \
 177                > expected.info-added-symlink-file &&
 178        (cd gitwc; git-svn info added-symlink-file) \
 179                > actual.info-added-symlink-file &&
 180        git-diff expected.info-added-symlink-file \
 181                 actual.info-added-symlink-file
 182        "
 183
 184test_expect_success 'info --url added-symlink-file' '
 185        test "$(cd gitwc; git-svn info --url added-symlink-file)" \
 186             = "$svnrepo/added-symlink-file"
 187        '
 188
 189test_expect_success 'info added-symlink-directory' "
 190        cd gitwc &&
 191                ln -s added-directory added-symlink-directory &&
 192                git add added-symlink-directory &&
 193        cd .. &&
 194        cd svnwc &&
 195                ln -s added-directory added-symlink-directory &&
 196                svn add added-symlink-directory > /dev/null &&
 197        cd .. &&
 198        ptouch gitwc/added-symlink-directory svnwc/added-symlink-directory &&
 199        (cd svnwc; svn info added-symlink-directory) \
 200                > expected.info-added-symlink-directory &&
 201        (cd gitwc; git-svn info added-symlink-directory) \
 202                > actual.info-added-symlink-directory &&
 203        git-diff expected.info-added-symlink-directory \
 204                 actual.info-added-symlink-directory
 205        "
 206
 207test_expect_success 'info --url added-symlink-directory' '
 208        test "$(cd gitwc; git-svn info --url added-symlink-directory)" \
 209             = "$svnrepo/added-symlink-directory"
 210        '
 211
 212# The next few tests replace the "Text Last Updated" value with a
 213# placeholder since git doesn't have a way to know the date that a
 214# now-deleted file was last checked out locally.  Internally it
 215# simply reuses the Last Changed Date.
 216
 217test_expect_success 'info deleted-file' "
 218        cd gitwc &&
 219                git rm -f file > /dev/null &&
 220        cd .. &&
 221        cd svnwc &&
 222                svn rm --force file > /dev/null &&
 223        cd .. &&
 224        (cd svnwc; svn info file) |
 225        sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
 226                > expected.info-deleted-file &&
 227        (cd gitwc; git-svn info file) |
 228        sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
 229                > actual.info-deleted-file &&
 230        git-diff expected.info-deleted-file actual.info-deleted-file
 231        "
 232
 233test_expect_success 'info --url file (deleted)' '
 234        test "$(cd gitwc; git-svn info --url file)" \
 235             = "$svnrepo/file"
 236        '
 237
 238test_expect_success 'info deleted-directory' "
 239        cd gitwc &&
 240                git rm -r -f directory > /dev/null &&
 241        cd .. &&
 242        cd svnwc &&
 243                svn rm --force directory > /dev/null &&
 244        cd .. &&
 245        (cd svnwc; svn info directory) |
 246        sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
 247                > expected.info-deleted-directory &&
 248        (cd gitwc; git-svn info directory) |
 249        sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
 250                > actual.info-deleted-directory &&
 251        git-diff expected.info-deleted-directory actual.info-deleted-directory
 252        "
 253
 254test_expect_success 'info --url directory (deleted)' '
 255        test "$(cd gitwc; git-svn info --url directory)" \
 256             = "$svnrepo/directory"
 257        '
 258
 259test_expect_success 'info deleted-symlink-file' "
 260        cd gitwc &&
 261                git rm -f symlink-file > /dev/null &&
 262        cd .. &&
 263        cd svnwc &&
 264                svn rm --force symlink-file > /dev/null &&
 265        cd .. &&
 266        (cd svnwc; svn info symlink-file) |
 267        sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
 268                > expected.info-deleted-symlink-file &&
 269        (cd gitwc; git-svn info symlink-file) |
 270        sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
 271                > actual.info-deleted-symlink-file &&
 272        git-diff expected.info-deleted-symlink-file \
 273                 actual.info-deleted-symlink-file
 274        "
 275
 276test_expect_success 'info --url symlink-file (deleted)' '
 277        test "$(cd gitwc; git-svn info --url symlink-file)" \
 278             = "$svnrepo/symlink-file"
 279        '
 280
 281test_expect_success 'info deleted-symlink-directory' "
 282        cd gitwc &&
 283                git rm -f symlink-directory > /dev/null &&
 284        cd .. &&
 285        cd svnwc &&
 286                svn rm --force symlink-directory > /dev/null &&
 287        cd .. &&
 288        (cd svnwc; svn info symlink-directory) |
 289        sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
 290                 > expected.info-deleted-symlink-directory &&
 291        (cd gitwc; git-svn info symlink-directory) |
 292        sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \
 293                 > actual.info-deleted-symlink-directory &&
 294        git-diff expected.info-deleted-symlink-directory \
 295                 actual.info-deleted-symlink-directory
 296        "
 297
 298test_expect_success 'info --url symlink-directory (deleted)' '
 299        test "$(cd gitwc; git-svn info --url symlink-directory)" \
 300             = "$svnrepo/symlink-directory"
 301        '
 302
 303# NOTE: git does not have the concept of replaced objects,
 304# so we can't test for files in that state.
 305
 306test_expect_success 'info unknown-file' "
 307        echo two > gitwc/unknown-file &&
 308        cp gitwc/unknown-file svnwc/unknown-file &&
 309        ptouch gitwc/unknown-file svnwc/unknown-file &&
 310        (cd svnwc; svn info unknown-file) 2> expected.info-unknown-file &&
 311        (cd gitwc; git-svn info unknown-file) 2> actual.info-unknown-file &&
 312        git-diff expected.info-unknown-file actual.info-unknown-file
 313        "
 314
 315test_expect_success 'info --url unknown-file' '
 316        test -z "$(cd gitwc; git-svn info --url unknown-file \
 317                        2> ../actual.info--url-unknown-file)" &&
 318        git-diff expected.info-unknown-file actual.info--url-unknown-file
 319        '
 320
 321test_expect_success 'info unknown-directory' "
 322        mkdir gitwc/unknown-directory svnwc/unknown-directory &&
 323        ptouch gitwc/unknown-directory svnwc/unknown-directory &&
 324        touch gitwc/unknown-directory/.placeholder &&
 325        (cd svnwc; svn info unknown-directory) \
 326                2> expected.info-unknown-directory &&
 327        (cd gitwc; git-svn info unknown-directory) \
 328                2> actual.info-unknown-directory &&
 329        git-diff expected.info-unknown-directory actual.info-unknown-directory
 330        "
 331
 332test_expect_success 'info --url unknown-directory' '
 333        test -z "$(cd gitwc; git-svn info --url unknown-directory \
 334                        2> ../actual.info--url-unknown-directory)" &&
 335        git-diff expected.info-unknown-directory \
 336                 actual.info--url-unknown-directory
 337        '
 338
 339test_expect_success 'info unknown-symlink-file' "
 340        cd gitwc &&
 341                ln -s unknown-file unknown-symlink-file &&
 342        cd .. &&
 343        cd svnwc &&
 344                ln -s unknown-file unknown-symlink-file &&
 345        cd .. &&
 346        ptouch gitwc/unknown-symlink-file svnwc/unknown-symlink-file &&
 347        (cd svnwc; svn info unknown-symlink-file) \
 348                2> expected.info-unknown-symlink-file &&
 349        (cd gitwc; git-svn info unknown-symlink-file) \
 350                2> actual.info-unknown-symlink-file &&
 351        git-diff expected.info-unknown-symlink-file \
 352                 actual.info-unknown-symlink-file
 353        "
 354
 355test_expect_success 'info --url unknown-symlink-file' '
 356        test -z "$(cd gitwc; git-svn info --url unknown-symlink-file \
 357                        2> ../actual.info--url-unknown-symlink-file)" &&
 358        git-diff expected.info-unknown-symlink-file \
 359                 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 svnwc &&
 367                ln -s unknown-directory unknown-symlink-directory &&
 368        cd .. &&
 369        ptouch gitwc/unknown-symlink-directory \
 370               svnwc/unknown-symlink-directory &&
 371        (cd svnwc; svn info unknown-symlink-directory) \
 372                2> expected.info-unknown-symlink-directory &&
 373        (cd gitwc; git-svn info unknown-symlink-directory) \
 374                2> actual.info-unknown-symlink-directory &&
 375        git-diff expected.info-unknown-symlink-directory \
 376                 actual.info-unknown-symlink-directory
 377        "
 378
 379test_expect_success 'info --url unknown-symlink-directory' '
 380        test -z "$(cd gitwc; git-svn info --url unknown-symlink-directory \
 381                        2> ../actual.info--url-unknown-symlink-directory)" &&
 382        git-diff expected.info-unknown-symlink-directory \
 383                 actual.info--url-unknown-symlink-directory
 384        '
 385
 386test_done