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