Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='basic tests for fast-export --anonymize' |
Johannes Schindelin | a881baa | 2020-11-18 23:44:42 +0000 | [diff] [blame] | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 6 | |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 7 | . ./test-lib.sh |
| 8 | |
| 9 | test_expect_success 'setup simple repo' ' |
| 10 | test_commit base && |
| 11 | test_commit foo && |
Jeff King | 65b5d9f | 2020-06-25 15:48:32 -0400 | [diff] [blame] | 12 | test_commit retain-me && |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 13 | git checkout -b other HEAD^ && |
| 14 | mkdir subdir && |
| 15 | test_commit subdir/bar && |
| 16 | test_commit subdir/xyzzy && |
Jeff King | b897bf5 | 2020-06-23 11:24:49 -0400 | [diff] [blame] | 17 | fake_commit=$(echo $ZERO_OID | sed s/0/a/) && |
| 18 | git update-index --add --cacheinfo 160000,$fake_commit,link1 && |
| 19 | git update-index --add --cacheinfo 160000,$fake_commit,link2 && |
| 20 | git commit -m "add gitlink" && |
Tal Kelrich | 2f040a9 | 2021-08-31 15:55:54 +0000 | [diff] [blame] | 21 | git tag -m "annotated tag" mytag && |
| 22 | git tag -m "annotated tag with long message" longtag |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 23 | ' |
| 24 | |
| 25 | test_expect_success 'export anonymized stream' ' |
Jeff King | 65b5d9f | 2020-06-25 15:48:32 -0400 | [diff] [blame] | 26 | git fast-export --anonymize --all \ |
| 27 | --anonymize-map=retain-me \ |
| 28 | --anonymize-map=xyzzy:custom-name \ |
Jeff King | 8a49495 | 2020-06-25 15:48:35 -0400 | [diff] [blame] | 29 | --anonymize-map=other \ |
Jeff King | 65b5d9f | 2020-06-25 15:48:32 -0400 | [diff] [blame] | 30 | >stream |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 31 | ' |
| 32 | |
| 33 | # this also covers commit messages |
| 34 | test_expect_success 'stream omits path names' ' |
| 35 | ! grep base stream && |
| 36 | ! grep foo stream && |
| 37 | ! grep subdir stream && |
| 38 | ! grep bar stream && |
| 39 | ! grep xyzzy stream |
| 40 | ' |
| 41 | |
Jeff King | 65b5d9f | 2020-06-25 15:48:32 -0400 | [diff] [blame] | 42 | test_expect_success 'stream contains user-specified names' ' |
| 43 | grep retain-me stream && |
| 44 | grep custom-name stream |
| 45 | ' |
| 46 | |
Jeff King | b897bf5 | 2020-06-23 11:24:49 -0400 | [diff] [blame] | 47 | test_expect_success 'stream omits gitlink oids' ' |
| 48 | # avoid relying on the whole oid to remain hash-agnostic; this is |
| 49 | # plenty to be unique within our test case |
| 50 | ! grep a000000000000000000 stream |
| 51 | ' |
| 52 | |
Jeff King | 8a49495 | 2020-06-25 15:48:35 -0400 | [diff] [blame] | 53 | test_expect_success 'stream retains other as refname' ' |
| 54 | grep other stream |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 55 | ' |
| 56 | |
| 57 | test_expect_success 'stream omits other refnames' ' |
Johannes Schindelin | a881baa | 2020-11-18 23:44:42 +0000 | [diff] [blame] | 58 | ! grep main stream && |
Tal Kelrich | 2f040a9 | 2021-08-31 15:55:54 +0000 | [diff] [blame] | 59 | ! grep mytag stream && |
| 60 | ! grep longtag stream |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 61 | ' |
| 62 | |
| 63 | test_expect_success 'stream omits identities' ' |
| 64 | ! grep "$GIT_COMMITTER_NAME" stream && |
| 65 | ! grep "$GIT_COMMITTER_EMAIL" stream && |
| 66 | ! grep "$GIT_AUTHOR_NAME" stream && |
| 67 | ! grep "$GIT_AUTHOR_EMAIL" stream |
| 68 | ' |
| 69 | |
| 70 | test_expect_success 'stream omits tag message' ' |
| 71 | ! grep "annotated tag" stream |
| 72 | ' |
| 73 | |
| 74 | # NOTE: we chdir to the new, anonymized repository |
| 75 | # after this. All further tests should assume this. |
| 76 | test_expect_success 'import stream to new repository' ' |
| 77 | git init new && |
| 78 | cd new && |
| 79 | git fast-import <../stream |
| 80 | ' |
| 81 | |
| 82 | test_expect_success 'result has two branches' ' |
| 83 | git for-each-ref --format="%(refname)" refs/heads >branches && |
| 84 | test_line_count = 2 branches && |
Jeff King | 8a49495 | 2020-06-25 15:48:35 -0400 | [diff] [blame] | 85 | other_branch=refs/heads/other && |
| 86 | main_branch=$(grep -v $other_branch branches) |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 87 | ' |
| 88 | |
| 89 | test_expect_success 'repo has original shape and timestamps' ' |
| 90 | shape () { |
| 91 | git log --format="%m %ct" --left-right --boundary "$@" |
| 92 | } && |
Johannes Schindelin | a881baa | 2020-11-18 23:44:42 +0000 | [diff] [blame] | 93 | (cd .. && shape main...other) >expect && |
Jeff King | 8a49495 | 2020-06-25 15:48:35 -0400 | [diff] [blame] | 94 | shape $main_branch...$other_branch >actual && |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 95 | test_cmp expect actual |
| 96 | ' |
| 97 | |
| 98 | test_expect_success 'root tree has original shape' ' |
| 99 | # the output entries are not necessarily in the same |
Jeff King | b8c0689 | 2020-06-23 11:24:47 -0400 | [diff] [blame] | 100 | # order, but we should at least have the same set of |
| 101 | # object types. |
| 102 | git -C .. ls-tree HEAD >orig-root && |
| 103 | cut -d" " -f2 <orig-root | sort >expect && |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 104 | git ls-tree $other_branch >root && |
| 105 | cut -d" " -f2 <root | sort >actual && |
| 106 | test_cmp expect actual |
| 107 | ' |
| 108 | |
| 109 | test_expect_success 'paths in subdir ended up in one tree' ' |
Jeff King | b8c0689 | 2020-06-23 11:24:47 -0400 | [diff] [blame] | 110 | git -C .. ls-tree other:subdir >orig-subdir && |
| 111 | cut -d" " -f2 <orig-subdir | sort >expect && |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 112 | tree=$(grep tree root | cut -f2) && |
| 113 | git ls-tree $other_branch:$tree >tree && |
| 114 | cut -d" " -f2 <tree >actual && |
| 115 | test_cmp expect actual |
| 116 | ' |
| 117 | |
Jeff King | b897bf5 | 2020-06-23 11:24:49 -0400 | [diff] [blame] | 118 | test_expect_success 'identical gitlinks got identical oid' ' |
| 119 | awk "/commit/ { print \$3 }" <root | sort -u >commits && |
| 120 | test_line_count = 1 commits |
| 121 | ' |
| 122 | |
Tal Kelrich | 2f040a9 | 2021-08-31 15:55:54 +0000 | [diff] [blame] | 123 | test_expect_success 'all tags point to branch tip' ' |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 124 | git rev-parse $other_branch >expect && |
Tal Kelrich | 2f040a9 | 2021-08-31 15:55:54 +0000 | [diff] [blame] | 125 | git for-each-ref --format="%(*objectname)" | grep . | uniq >actual && |
Jeff King | a872275 | 2014-08-27 13:01:28 -0400 | [diff] [blame] | 126 | test_cmp expect actual |
| 127 | ' |
| 128 | |
| 129 | test_expect_success 'idents are shared' ' |
| 130 | git log --all --format="%an <%ae>" >authors && |
| 131 | sort -u authors >unique && |
| 132 | test_line_count = 1 unique && |
| 133 | git log --all --format="%cn <%ce>" >committers && |
| 134 | sort -u committers >unique && |
| 135 | test_line_count = 1 unique && |
| 136 | ! test_cmp authors committers |
| 137 | ' |
| 138 | |
| 139 | test_done |