Skip to content

Commit 1dae85e

Browse files
committed
filter-repo: permit trailing slash for --[to-]subdirectory-filter argument
There was code to allow the argument of --to-subdirectory-filter and --subdirectory-filter to have a trailing slash, but it was broken due to a bug in python3's bytestring design: b'somestring/'[-1] != b'/', despite that being the obvious expectation. One either has to compare b'somestring/'[-1:] to b'/' or else compare b'somestring/'[-1] to b'/'[0]. So lame. Note that this is essentially a follow-up to commit 385b058 ("filter-repo (python3): bytestr splicing and iterating is different", 2019-04-27). Signed-off-by: Elijah Newren <[email protected]>
1 parent a1d20f8 commit 1dae85e

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

git-filter-repo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,7 @@ class FilteringOptions(object):
16321632
def __call__(self, parser, namespace, values, option_string=None):
16331633
af = FilteringOptions.AppendFilter(dest='path_changes',
16341634
option_strings=None)
1635-
dirname = values if values[-1] == b'/' else values+b'/'
1635+
dirname = values if values[-1:] == b'/' else values+b'/'
16361636
if option_string == '--subdirectory-filter':
16371637
af(parser, namespace, dirname, '--path-match')
16381638
af(parser, namespace, dirname+b':', '--path-rename')

t/t9390-filter-repo.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,30 @@ test_expect_success '--subdirectory-filter' '
246246
)
247247
'
248248

249+
test_expect_success '--subdirectory-filter with trailing slash' '
250+
(
251+
git clone file://"$(pwd)"/metasyntactic subdir_filter_2 &&
252+
cd subdir_filter_2 &&
253+
git filter-repo \
254+
--subdirectory-filter words/ &&
255+
git cat-file --batch-check --batch-all-objects >all-objs &&
256+
test_line_count = 10 all-objs &&
257+
git log --format=%n --name-only | sort | uniq >filenames &&
258+
test_line_count = 6 filenames &&
259+
grep ^important$ filenames &&
260+
test_must_fail git cat-file -t v1.0 &&
261+
test_must_fail git cat-file -t v1.1 &&
262+
test $(git cat-file -t v2.0) = commit &&
263+
test $(git cat-file -t v3.0) = tag
264+
)
265+
'
266+
249267
test_expect_success '--to-subdirectory-filter' '
250268
(
251269
git clone file://"$(pwd)"/metasyntactic to_subdir_filter &&
252270
cd to_subdir_filter &&
253271
git filter-repo \
254-
--to-subdirectory-filter mysubdir &&
272+
--to-subdirectory-filter mysubdir/ &&
255273
git cat-file --batch-check --batch-all-objects >all-objs &&
256274
test_line_count = 22 all-objs &&
257275
git log --format=%n --name-only | sort | uniq >filenames &&

0 commit comments

Comments
 (0)