3 test_description
='basic tests for fast-export --anonymize'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_PASSES_SANITIZE_LEAK
=true
10 test_expect_success
'setup simple repo' '
13 test_commit retain-me &&
14 git checkout -b other HEAD^ &&
16 test_commit subdir/bar &&
17 test_commit subdir/xyzzy &&
18 fake_commit=$(echo $ZERO_OID | sed s/0/a/) &&
19 git update-index --add --cacheinfo 160000,$fake_commit,link1 &&
20 git update-index --add --cacheinfo 160000,$fake_commit,link2 &&
21 git commit -m "add gitlink" &&
22 git tag -m "annotated tag" mytag &&
23 git tag -m "annotated tag with long message" longtag
26 test_expect_success
'export anonymized stream' '
27 git fast-export --anonymize --all \
28 --anonymize-map=retain-me \
29 --anonymize-map=xyzzy:should-not-appear \
30 --anonymize-map=xyzzy:custom-name \
31 --anonymize-map=other \
35 # this also covers commit messages
36 test_expect_success
'stream omits path names' '
39 ! grep subdir stream &&
44 test_expect_success
'stream contains user-specified names' '
45 grep retain-me stream &&
46 ! grep should-not-appear stream &&
47 grep custom-name stream
50 test_expect_success
'stream omits gitlink oids' '
51 # avoid relying on the whole oid to remain hash-agnostic; this is
52 # plenty to be unique within our test case
53 ! grep a000000000000000000 stream
56 test_expect_success
'stream retains other as refname' '
60 test_expect_success
'stream omits other refnames' '
62 ! grep mytag stream &&
66 test_expect_success
'stream omits identities' '
67 ! grep "$GIT_COMMITTER_NAME" stream &&
68 ! grep "$GIT_COMMITTER_EMAIL" stream &&
69 ! grep "$GIT_AUTHOR_NAME" stream &&
70 ! grep "$GIT_AUTHOR_EMAIL" stream
73 test_expect_success
'stream omits tag message' '
74 ! grep "annotated tag" stream
77 # NOTE: we chdir to the new, anonymized repository
78 # after this. All further tests should assume this.
79 test_expect_success
'import stream to new repository' '
82 git fast-import <../stream
85 test_expect_success
'result has two branches' '
86 git for-each-ref --format="%(refname)" refs/heads >branches &&
87 test_line_count = 2 branches &&
88 other_branch=refs/heads/other &&
89 main_branch=$(grep -v $other_branch branches)
92 test_expect_success
'repo has original shape and timestamps' '
94 git log --format="%m %ct" --left-right --boundary "$@"
96 (cd .. && shape main...other) >expect &&
97 shape $main_branch...$other_branch >actual &&
98 test_cmp expect actual
101 test_expect_success
'root tree has original shape' '
102 # the output entries are not necessarily in the same
103 # order, but we should at least have the same set of
105 git -C .. ls-tree HEAD >orig-root &&
106 cut -d" " -f2 <orig-root | sort >expect &&
107 git ls-tree $other_branch >root &&
108 cut -d" " -f2 <root | sort >actual &&
109 test_cmp expect actual
112 test_expect_success
'paths in subdir ended up in one tree' '
113 git -C .. ls-tree other:subdir >orig-subdir &&
114 cut -d" " -f2 <orig-subdir | sort >expect &&
115 tree=$(grep tree root | cut -f2) &&
116 git ls-tree $other_branch:$tree >tree &&
117 cut -d" " -f2 <tree >actual &&
118 test_cmp expect actual
121 test_expect_success
'identical gitlinks got identical oid' '
122 awk "/commit/ { print \$3 }" <root | sort -u >commits &&
123 test_line_count = 1 commits
126 test_expect_success
'all tags point to branch tip' '
127 git rev-parse $other_branch >expect &&
128 git for-each-ref --format="%(*objectname)" | grep . | uniq >actual &&
129 test_cmp expect actual
132 test_expect_success
'idents are shared' '
133 git log --all --format="%an <%ae>" >authors &&
134 sort -u authors >unique &&
135 test_line_count = 1 unique &&
136 git log --all --format="%cn <%ce>" >committers &&
137 sort -u committers >unique &&
138 test_line_count = 1 unique &&
139 ! test_cmp authors committers