File: t9391-filter-repo-lib-usage.sh

package info (click to toggle)
git-filter-repo 2.47.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,280 kB
  • sloc: sh: 4,887; python: 4,856; makefile: 114
file content (259 lines) | stat: -rwxr-xr-x 6,517 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/bin/bash

test_description='Usage of git-filter-repo as a library'
. ./test-lib.sh

# for git_filter_repo.py import
case "$(uname -s)" in
MINGW*|MSYS)
	export PYTHONPATH=$(cygpath -am $TEST_DIRECTORY/..)\;$PYTHONPATH
	;;
*)
	export PYTHONPATH=$(dirname $TEST_DIRECTORY):$PYTHONPATH
	;;
esac
# Avoid writing git_filter_repo.pyc file
export PYTHONDONTWRITEBYTECODE=1
export CONTRIB_DIR=$TEST_DIRECTORY/../contrib/filter-repo-demos

DATA="$TEST_DIRECTORY/t9391"

setup()
{
	git init $1 &&
	(
		cd $1 &&
		echo hello > world &&
		git add world &&
		test_tick &&
		git commit -m initial &&
		printf "The launch code is 1-2-3-4." > secret &&
		git add secret &&
		test_tick &&
		git commit -m "Sssh.  Dont tell no one" &&
		echo A file that you cant trust > file.doc &&
		echo there >> world &&
		git add file.doc world &&
		test_tick &&
		printf "Random useless changes\n\nLet us be like the marketing group.  Marketing is staffed with pansies" | git commit -F - &&
		echo Do not use a preposition to end a setence with > advice &&
		git add advice &&
		test_tick &&
		GIT_AUTHOR_NAME="Copy N. Paste" git commit -m "hypocrisy is fun" &&
		echo Avoid cliches like the plague >> advice &&
		test_tick &&
		GIT_AUTHOR_EMAIL="foo@my.crp" git commit -m "it is still fun" advice &&
		echo "  \$Id: A bunch of junk$" > foobar.c &&
		git add foobar.c &&
		test_tick &&
		git commit -m "Brain damage"
	)
}

test_expect_success 'commit_info.py' '
	setup commit_info &&
	(
		cd commit_info &&
		$TEST_DIRECTORY/t9391/commit_info.py &&
		test 0e5a1029 = $(git rev-parse --short=8 --verify refs/heads/master)
	)
'

test_expect_success 'file_filter.py' '
	setup file_filter &&
	(
		cd file_filter &&
		$TEST_DIRECTORY/t9391/file_filter.py &&
		test ee59e2b4 = $(git rev-parse --short=8 --verify refs/heads/master)
	)
'

test_expect_success 'print_progress.py' '
	setup print_progress &&
	(
		cd print_progress &&
		MASTER=$(git rev-parse --verify master) &&
		$TEST_DIRECTORY/t9391/print_progress.py . new &&
		test $MASTER = $(git rev-parse --verify refs/heads/master)
	)
'

test_expect_success 'rename-master-to-develop.py' '
	setup rename_master_to_develop &&
	(
		cd rename_master_to_develop &&
		MASTER=$(git rev-parse --verify master) &&
		$TEST_DIRECTORY/t9391/rename-master-to-develop.py &&
		test $MASTER = $(git rev-parse --verify refs/heads/develop)
	)
'

test_expect_success 'strip-cvs-keywords.py' '
	setup strip_cvs_keywords &&
	(
		cd strip_cvs_keywords &&
		$TEST_DIRECTORY/t9391/strip-cvs-keywords.py
		test 2306fc7c = $(git rev-parse --short=8 --verify refs/heads/master)
	)
'

test_expect_success 'setup two extra repositories' '
	mkdir repo1 &&
	cd repo1 &&
	git init &&
	echo hello > world &&
	git add world &&
	test_tick &&
	git commit -m "Commit A" &&
	echo goodbye > world &&
	git add world &&
	test_tick &&
	git commit -m "Commit C" &&
	cd .. &&
	mkdir repo2 &&
	cd repo2 &&
	git init &&
	echo foo > bar &&
	git add bar &&
	test_tick &&
	git commit -m "Commit B" &&
	echo fooey > bar &&
	git add bar &&
	test_tick &&
	git commit -m "Commit D" &&
	cd ..
'

test_expect_success 'splice_repos.py' '
	git init splice_repos &&
	$TEST_DIRECTORY/t9391/splice_repos.py repo1 repo2 splice_repos &&
	test 4 = $(git -C splice_repos rev-list master | wc -l)
'

test_expect_success 'create_fast_export_output.py' '
	git init create_fast_export_output &&
	(cd create_fast_export_output &&
		$TEST_DIRECTORY/t9391/create_fast_export_output.py &&
		test e5e0569b = $(git rev-parse --short=8 --verify refs/heads/master) &&
		test 122ead00 = $(git rev-parse --short=8 --verify refs/heads/devel) &&
		test f36143f9 = $(git rev-parse --short=8 --verify refs/tags/v1.0))
'

test_expect_success 'unusual.py' '
	setup unusual &&
	(
		cd unusual &&
		cat $TEST_DIRECTORY/t9390/unusual | \
			$TEST_DIRECTORY/t9391/unusual.py >output &&

		grep "Decipher this: .oy ,tropmi eht gnitrats ma I" output &&
		grep "Found 2 blobs/commits and 4 other objects" output
	)
'

test_expect_success 'erroneous.py' '
	setup erroneous &&
	(
		cd erroneous &&
		test_must_fail $TEST_DIRECTORY/t9391/erroneous.py 2>../err &&

		test_i18ngrep "Error: Cannot pass a tag_callback to RepoFilter AND pass --tag-callback" ../err
	)
'

test_expect_success 'other error cases' '
	GIT_CEILING_DIRECTORIES=$(pwd) &&
	export GIT_CEILING_DIRECTORIES &&
	(
		mkdir other &&
		cd other &&

		! python3 -c "import git_filter_repo as fr; fr.GitUtils.get_commit_count(b\".\", [\"HEAD\"])" 2>err &&
		test_i18ngrep "\. does not appear to be a valid git repository" err
	)
'

test_lazy_prereq DOS2UNIX '
	dos2unix -h
	test $? -ne 127
'

test_expect_success 'lint-history' '
	test_create_repo lint-history &&
	(
		cd lint-history &&
		git config core.autocrlf false &&
		echo initial >content &&
		git add content &&
		git commit -m "initial" &&

		printf "CRLF is stupid\r\n" >content &&
		git add content &&
		git commit -m "make a statement" &&

		printf "CRLF is stupid\n" >content &&
		git add content &&
		git commit -m "oops, that was embarassing" &&

		if test_have_prereq DOS2UNIX
		then
			$CONTRIB_DIR/lint-history --filenames-important dos2unix &&
			echo 2 >expect &&
			git rev-list --count HEAD >actual &&
			test_cmp expect actual
		fi
	)
'

test_expect_success !WINDOWS 'lint-history --refs' '
	test_create_repo lint-history-only-some-refs &&
	(
		cd lint-history-only-some-refs &&
		test_commit a somefile bad &&
		test_commit b notherfile baaad &&
		test_commit c whatever baaaaaad &&
		git checkout -b mybranch HEAD~1 &&
		test_commit d somefile baaaaaaaad &&
		test_commit e whatever "baaaaaaaaaad to the bone" &&

		cat <<-EOF >linter.sh &&
		#!/bin/bash
		cat \$1 | tr -d a >tmp
		mv tmp \$1
		EOF
		chmod u+x linter.sh &&

		PATH=$PATH:. $CONTRIB_DIR/lint-history --refs master..mybranch  -- linter.sh &&

		echo bd >expect &&
		echo bd to the bone >long-expect &&

		# Verify master is untouched
		git checkout master &&
		! test_cmp somefile expect &&
		! test_cmp notherfile expect &&
		! test_cmp whatever expect &&

		# Verify that files touched on the branch are tweaked
		git checkout mybranch &&
		test_cmp somefile expect &&
		! test_cmp notherfile expect &&
		test_cmp whatever long-expect

	)
'

test_expect_success 'clean-ignore with emoji in filenames' '
	test_create_repo clean-ignore &&
	(
		cd clean-ignore &&
		git fast-import --quiet <$DATA/emoji-repo &&
		git reset --hard &&
		$CONTRIB_DIR/clean-ignore --force &&
		printf ".gitignore\nfilename\n" >expect &&
		git ls-files >actual &&
		test_cmp expect actual
	)
'

test_done