blob: 156a6474847cf6e5bc86df2212ce98211986e6d6 [file] [log] [blame]
Jeff Kinga8722752014-08-27 13:01:28 -04001#!/bin/sh
2
3test_description='basic tests for fast-export --anonymize'
Johannes Schindelina881baa2020-11-18 23:44:42 +00004GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00005export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
Jeff Kinga8722752014-08-27 13:01:28 -04007. ./test-lib.sh
8
9test_expect_success 'setup simple repo' '
10 test_commit base &&
11 test_commit foo &&
Jeff King65b5d9f2020-06-25 15:48:32 -040012 test_commit retain-me &&
Jeff Kinga8722752014-08-27 13:01:28 -040013 git checkout -b other HEAD^ &&
14 mkdir subdir &&
15 test_commit subdir/bar &&
16 test_commit subdir/xyzzy &&
Jeff Kingb897bf52020-06-23 11:24:49 -040017 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 Kelrich2f040a92021-08-31 15:55:54 +000021 git tag -m "annotated tag" mytag &&
22 git tag -m "annotated tag with long message" longtag
Jeff Kinga8722752014-08-27 13:01:28 -040023'
24
25test_expect_success 'export anonymized stream' '
Jeff King65b5d9f2020-06-25 15:48:32 -040026 git fast-export --anonymize --all \
27 --anonymize-map=retain-me \
Jeff Kingaa548452023-03-22 13:42:13 -040028 --anonymize-map=xyzzy:should-not-appear \
Jeff King65b5d9f2020-06-25 15:48:32 -040029 --anonymize-map=xyzzy:custom-name \
Jeff King8a494952020-06-25 15:48:35 -040030 --anonymize-map=other \
Jeff King65b5d9f2020-06-25 15:48:32 -040031 >stream
Jeff Kinga8722752014-08-27 13:01:28 -040032'
33
34# this also covers commit messages
35test_expect_success 'stream omits path names' '
36 ! grep base stream &&
37 ! grep foo stream &&
38 ! grep subdir stream &&
39 ! grep bar stream &&
40 ! grep xyzzy stream
41'
42
Jeff King65b5d9f2020-06-25 15:48:32 -040043test_expect_success 'stream contains user-specified names' '
44 grep retain-me stream &&
Jeff Kingaa548452023-03-22 13:42:13 -040045 ! grep should-not-appear stream &&
Jeff King65b5d9f2020-06-25 15:48:32 -040046 grep custom-name stream
47'
48
Jeff Kingb897bf52020-06-23 11:24:49 -040049test_expect_success 'stream omits gitlink oids' '
50 # avoid relying on the whole oid to remain hash-agnostic; this is
51 # plenty to be unique within our test case
52 ! grep a000000000000000000 stream
53'
54
Jeff King8a494952020-06-25 15:48:35 -040055test_expect_success 'stream retains other as refname' '
56 grep other stream
Jeff Kinga8722752014-08-27 13:01:28 -040057'
58
59test_expect_success 'stream omits other refnames' '
Johannes Schindelina881baa2020-11-18 23:44:42 +000060 ! grep main stream &&
Tal Kelrich2f040a92021-08-31 15:55:54 +000061 ! grep mytag stream &&
62 ! grep longtag stream
Jeff Kinga8722752014-08-27 13:01:28 -040063'
64
65test_expect_success 'stream omits identities' '
66 ! grep "$GIT_COMMITTER_NAME" stream &&
67 ! grep "$GIT_COMMITTER_EMAIL" stream &&
68 ! grep "$GIT_AUTHOR_NAME" stream &&
69 ! grep "$GIT_AUTHOR_EMAIL" stream
70'
71
72test_expect_success 'stream omits tag message' '
73 ! grep "annotated tag" stream
74'
75
76# NOTE: we chdir to the new, anonymized repository
77# after this. All further tests should assume this.
78test_expect_success 'import stream to new repository' '
79 git init new &&
80 cd new &&
81 git fast-import <../stream
82'
83
84test_expect_success 'result has two branches' '
85 git for-each-ref --format="%(refname)" refs/heads >branches &&
86 test_line_count = 2 branches &&
Jeff King8a494952020-06-25 15:48:35 -040087 other_branch=refs/heads/other &&
88 main_branch=$(grep -v $other_branch branches)
Jeff Kinga8722752014-08-27 13:01:28 -040089'
90
91test_expect_success 'repo has original shape and timestamps' '
92 shape () {
93 git log --format="%m %ct" --left-right --boundary "$@"
94 } &&
Johannes Schindelina881baa2020-11-18 23:44:42 +000095 (cd .. && shape main...other) >expect &&
Jeff King8a494952020-06-25 15:48:35 -040096 shape $main_branch...$other_branch >actual &&
Jeff Kinga8722752014-08-27 13:01:28 -040097 test_cmp expect actual
98'
99
100test_expect_success 'root tree has original shape' '
101 # the output entries are not necessarily in the same
Jeff Kingb8c06892020-06-23 11:24:47 -0400102 # order, but we should at least have the same set of
103 # object types.
104 git -C .. ls-tree HEAD >orig-root &&
105 cut -d" " -f2 <orig-root | sort >expect &&
Jeff Kinga8722752014-08-27 13:01:28 -0400106 git ls-tree $other_branch >root &&
107 cut -d" " -f2 <root | sort >actual &&
108 test_cmp expect actual
109'
110
111test_expect_success 'paths in subdir ended up in one tree' '
Jeff Kingb8c06892020-06-23 11:24:47 -0400112 git -C .. ls-tree other:subdir >orig-subdir &&
113 cut -d" " -f2 <orig-subdir | sort >expect &&
Jeff Kinga8722752014-08-27 13:01:28 -0400114 tree=$(grep tree root | cut -f2) &&
115 git ls-tree $other_branch:$tree >tree &&
116 cut -d" " -f2 <tree >actual &&
117 test_cmp expect actual
118'
119
Jeff Kingb897bf52020-06-23 11:24:49 -0400120test_expect_success 'identical gitlinks got identical oid' '
121 awk "/commit/ { print \$3 }" <root | sort -u >commits &&
122 test_line_count = 1 commits
123'
124
Tal Kelrich2f040a92021-08-31 15:55:54 +0000125test_expect_success 'all tags point to branch tip' '
Jeff Kinga8722752014-08-27 13:01:28 -0400126 git rev-parse $other_branch >expect &&
Tal Kelrich2f040a92021-08-31 15:55:54 +0000127 git for-each-ref --format="%(*objectname)" | grep . | uniq >actual &&
Jeff Kinga8722752014-08-27 13:01:28 -0400128 test_cmp expect actual
129'
130
131test_expect_success 'idents are shared' '
132 git log --all --format="%an <%ae>" >authors &&
133 sort -u authors >unique &&
134 test_line_count = 1 unique &&
135 git log --all --format="%cn <%ce>" >committers &&
136 sort -u committers >unique &&
137 test_line_count = 1 unique &&
138 ! test_cmp authors committers
139'
140
141test_done