1463476b2159e6610dcc6bc19e3f6afe3a8a74a6
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Shawn Pearce
   4#
   5
   6test_description='test git-fast-import utility'
   7. ./test-lib.sh
   8. ../diff-lib.sh ;# test-lib chdir's into trash
   9
  10###
  11### series A
  12###
  13
  14test_tick
  15cat >input <<INPUT_END
  16blob
  17mark :2
  18data <<EOF
  19file2
  20second line of EOF
  21EOF
  22
  23blob
  24mark :3
  25data <<END
  26EOF
  27in 3rd file
  28 END
  29END
  30
  31blob
  32mark :4
  33data 4
  34abcd
  35commit refs/heads/master
  36mark :5
  37committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  38data <<COMMIT
  39initial
  40COMMIT
  41
  42M 644 :2 file2
  43M 644 :3 file3
  44M 755 :4 file4
  45
  46INPUT_END
  47test_expect_success \
  48    'A: create pack from stdin' \
  49    'git-fast-import --export-marks=marks.out <input &&
  50         git-whatchanged master'
  51test_expect_success \
  52        'A: verify pack' \
  53        'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
  54
  55cat >expect <<EOF
  56author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  57committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  58
  59initial
  60EOF
  61test_expect_success \
  62        'A: verify commit' \
  63        'git-cat-file commit master | sed 1d >actual &&
  64        diff -u expect actual'
  65
  66cat >expect <<EOF
  67100644 blob file2
  68100644 blob file3
  69100755 blob file4
  70EOF
  71test_expect_success \
  72        'A: verify tree' \
  73        'git-cat-file -p master^{tree} | sed "s/ [0-9a-f]*      / /" >actual &&
  74         diff -u expect actual'
  75
  76cat >expect <<EOF
  77file2
  78second line of EOF
  79EOF
  80test_expect_success \
  81        'A: verify file2' \
  82        'git-cat-file blob master:file2 >actual && diff -u expect actual'
  83
  84cat >expect <<END
  85EOF
  86in 3rd file
  87 END
  88END
  89test_expect_success \
  90        'A: verify file3' \
  91        'git-cat-file blob master:file3 >actual && diff -u expect actual'
  92
  93printf abcd >expect
  94test_expect_success \
  95        'A: verify file4' \
  96        'git-cat-file blob master:file4 >actual && diff -u expect actual'
  97
  98cat >expect <<EOF
  99:2 `git-rev-parse --verify master:file2`
 100:3 `git-rev-parse --verify master:file3`
 101:4 `git-rev-parse --verify master:file4`
 102:5 `git-rev-parse --verify master^0`
 103EOF
 104test_expect_success \
 105        'A: verify marks output' \
 106        'diff -u expect marks.out'
 107
 108###
 109### series B
 110###
 111
 112test_tick
 113cat >input <<INPUT_END
 114commit refs/heads/branch
 115mark :1
 116committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 117data <<COMMIT
 118corrupt
 119COMMIT
 120
 121from refs/heads/master
 122M 755 0000000000000000000000000000000000000001 zero1
 123
 124INPUT_END
 125test_expect_failure \
 126    'B: fail on invalid blob sha1' \
 127    'git-fast-import <input'
 128rm -f .git/objects/pack_* .git/objects/index_*
 129
 130###
 131### series C
 132###
 133
 134newf=`echo hi newf | git-hash-object -w --stdin`
 135oldf=`git-rev-parse --verify master:file2`
 136test_tick
 137cat >input <<INPUT_END
 138commit refs/heads/branch
 139committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 140data <<COMMIT
 141second
 142COMMIT
 143
 144from refs/heads/master
 145M 644 $oldf file2/oldf
 146M 755 $newf file2/newf
 147D file3
 148
 149INPUT_END
 150test_expect_success \
 151    'C: incremental import create pack from stdin' \
 152    'git-fast-import <input &&
 153         git-whatchanged branch'
 154test_expect_success \
 155        'C: verify pack' \
 156        'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
 157test_expect_success \
 158        'C: validate reuse existing blob' \
 159        'test $newf = `git-rev-parse --verify branch:file2/newf`
 160         test $oldf = `git-rev-parse --verify branch:file2/oldf`'
 161
 162cat >expect <<EOF
 163parent `git-rev-parse --verify master^0`
 164author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 165committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
 166
 167second
 168EOF
 169test_expect_success \
 170        'C: verify commit' \
 171        'git-cat-file commit branch | sed 1d >actual &&
 172         diff -u expect actual'
 173
 174cat >expect <<EOF
 175:000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A      file2/newf
 176:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100   file2   file2/oldf
 177:100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D      file3
 178EOF
 179git-diff-tree -M -r master branch >actual
 180test_expect_success \
 181        'C: validate rename result' \
 182        'compare_diff_raw expect actual'
 183
 184test_done