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