Merge branch 'es/maintenance-of-bare-repositories'
[git/debian.git] / t / t9351-fast-export-anonymize.sh
blob1c6e6fcdaf3c5a258dd9a98647b38a2cd82631b6
1 #!/bin/sh
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-lib.sh
9 test_expect_success 'setup simple repo' '
10 test_commit base &&
11 test_commit foo &&
12 test_commit retain-me &&
13 git checkout -b other HEAD^ &&
14 mkdir subdir &&
15 test_commit subdir/bar &&
16 test_commit subdir/xyzzy &&
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" &&
21 git tag -m "annotated tag" mytag
24 test_expect_success 'export anonymized stream' '
25 git fast-export --anonymize --all \
26 --anonymize-map=retain-me \
27 --anonymize-map=xyzzy:custom-name \
28 --anonymize-map=other \
29 >stream
32 # this also covers commit messages
33 test_expect_success 'stream omits path names' '
34 ! grep base stream &&
35 ! grep foo stream &&
36 ! grep subdir stream &&
37 ! grep bar stream &&
38 ! grep xyzzy stream
41 test_expect_success 'stream contains user-specified names' '
42 grep retain-me stream &&
43 grep custom-name stream
46 test_expect_success 'stream omits gitlink oids' '
47 # avoid relying on the whole oid to remain hash-agnostic; this is
48 # plenty to be unique within our test case
49 ! grep a000000000000000000 stream
52 test_expect_success 'stream retains other as refname' '
53 grep other stream
56 test_expect_success 'stream omits other refnames' '
57 ! grep main stream &&
58 ! grep mytag stream
61 test_expect_success 'stream omits identities' '
62 ! grep "$GIT_COMMITTER_NAME" stream &&
63 ! grep "$GIT_COMMITTER_EMAIL" stream &&
64 ! grep "$GIT_AUTHOR_NAME" stream &&
65 ! grep "$GIT_AUTHOR_EMAIL" stream
68 test_expect_success 'stream omits tag message' '
69 ! grep "annotated tag" stream
72 # NOTE: we chdir to the new, anonymized repository
73 # after this. All further tests should assume this.
74 test_expect_success 'import stream to new repository' '
75 git init new &&
76 cd new &&
77 git fast-import <../stream
80 test_expect_success 'result has two branches' '
81 git for-each-ref --format="%(refname)" refs/heads >branches &&
82 test_line_count = 2 branches &&
83 other_branch=refs/heads/other &&
84 main_branch=$(grep -v $other_branch branches)
87 test_expect_success 'repo has original shape and timestamps' '
88 shape () {
89 git log --format="%m %ct" --left-right --boundary "$@"
90 } &&
91 (cd .. && shape main...other) >expect &&
92 shape $main_branch...$other_branch >actual &&
93 test_cmp expect actual
96 test_expect_success 'root tree has original shape' '
97 # the output entries are not necessarily in the same
98 # order, but we should at least have the same set of
99 # object types.
100 git -C .. ls-tree HEAD >orig-root &&
101 cut -d" " -f2 <orig-root | sort >expect &&
102 git ls-tree $other_branch >root &&
103 cut -d" " -f2 <root | sort >actual &&
104 test_cmp expect actual
107 test_expect_success 'paths in subdir ended up in one tree' '
108 git -C .. ls-tree other:subdir >orig-subdir &&
109 cut -d" " -f2 <orig-subdir | sort >expect &&
110 tree=$(grep tree root | cut -f2) &&
111 git ls-tree $other_branch:$tree >tree &&
112 cut -d" " -f2 <tree >actual &&
113 test_cmp expect actual
116 test_expect_success 'identical gitlinks got identical oid' '
117 awk "/commit/ { print \$3 }" <root | sort -u >commits &&
118 test_line_count = 1 commits
121 test_expect_success 'tag points to branch tip' '
122 git rev-parse $other_branch >expect &&
123 git for-each-ref --format="%(*objectname)" | grep . >actual &&
124 test_cmp expect actual
127 test_expect_success 'idents are shared' '
128 git log --all --format="%an <%ae>" >authors &&
129 sort -u authors >unique &&
130 test_line_count = 1 unique &&
131 git log --all --format="%cn <%ce>" >committers &&
132 sort -u committers >unique &&
133 test_line_count = 1 unique &&
134 ! test_cmp authors committers
137 test_done