t / t9351-fast-export-anonymize.shon commit t6300: refactor %(trailers) tests (624b44d)
   1#!/bin/sh
   2
   3test_description='basic tests for fast-export --anonymize'
   4. ./test-lib.sh
   5
   6test_expect_success 'setup simple repo' '
   7        test_commit base &&
   8        test_commit foo &&
   9        git checkout -b other HEAD^ &&
  10        mkdir subdir &&
  11        test_commit subdir/bar &&
  12        test_commit subdir/xyzzy &&
  13        git tag -m "annotated tag" mytag
  14'
  15
  16test_expect_success 'export anonymized stream' '
  17        git fast-export --anonymize --all >stream
  18'
  19
  20# this also covers commit messages
  21test_expect_success 'stream omits path names' '
  22        ! grep base stream &&
  23        ! grep foo stream &&
  24        ! grep subdir stream &&
  25        ! grep bar stream &&
  26        ! grep xyzzy stream
  27'
  28
  29test_expect_success 'stream allows master as refname' '
  30        grep master stream
  31'
  32
  33test_expect_success 'stream omits other refnames' '
  34        ! grep other stream &&
  35        ! grep mytag stream
  36'
  37
  38test_expect_success 'stream omits identities' '
  39        ! grep "$GIT_COMMITTER_NAME" stream &&
  40        ! grep "$GIT_COMMITTER_EMAIL" stream &&
  41        ! grep "$GIT_AUTHOR_NAME" stream &&
  42        ! grep "$GIT_AUTHOR_EMAIL" stream
  43'
  44
  45test_expect_success 'stream omits tag message' '
  46        ! grep "annotated tag" stream
  47'
  48
  49# NOTE: we chdir to the new, anonymized repository
  50# after this. All further tests should assume this.
  51test_expect_success 'import stream to new repository' '
  52        git init new &&
  53        cd new &&
  54        git fast-import <../stream
  55'
  56
  57test_expect_success 'result has two branches' '
  58        git for-each-ref --format="%(refname)" refs/heads >branches &&
  59        test_line_count = 2 branches &&
  60        other_branch=$(grep -v refs/heads/master branches)
  61'
  62
  63test_expect_success 'repo has original shape and timestamps' '
  64        shape () {
  65                git log --format="%m %ct" --left-right --boundary "$@"
  66        } &&
  67        (cd .. && shape master...other) >expect &&
  68        shape master...$other_branch >actual &&
  69        test_cmp expect actual
  70'
  71
  72test_expect_success 'root tree has original shape' '
  73        # the output entries are not necessarily in the same
  74        # order, but we know at least that we will have one tree
  75        # and one blob, so just check the sorted order
  76        cat >expect <<-\EOF &&
  77        blob
  78        tree
  79        EOF
  80        git ls-tree $other_branch >root &&
  81        cut -d" " -f2 <root | sort >actual &&
  82        test_cmp expect actual
  83'
  84
  85test_expect_success 'paths in subdir ended up in one tree' '
  86        cat >expect <<-\EOF &&
  87        blob
  88        blob
  89        EOF
  90        tree=$(grep tree root | cut -f2) &&
  91        git ls-tree $other_branch:$tree >tree &&
  92        cut -d" " -f2 <tree >actual &&
  93        test_cmp expect actual
  94'
  95
  96test_expect_success 'tag points to branch tip' '
  97        git rev-parse $other_branch >expect &&
  98        git for-each-ref --format="%(*objectname)" | grep . >actual &&
  99        test_cmp expect actual
 100'
 101
 102test_expect_success 'idents are shared' '
 103        git log --all --format="%an <%ae>" >authors &&
 104        sort -u authors >unique &&
 105        test_line_count = 1 unique &&
 106        git log --all --format="%cn <%ce>" >committers &&
 107        sort -u committers >unique &&
 108        test_line_count = 1 unique &&
 109        ! test_cmp authors committers
 110'
 111
 112test_done