mirror of
https://github.com/newren/git-filter-repo.git
synced 2024-07-06 02:12:17 +02:00
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
385b0586ca
("filter-repo (python3): bytestr splicing and iterating is
different", 2019-04-27).
Signed-off-by: Elijah Newren <newren@gmail.com>
This commit is contained in:
parent
a1d20f8e77
commit
1dae85ee9a
@ -1632,7 +1632,7 @@ class FilteringOptions(object):
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
af = FilteringOptions.AppendFilter(dest='path_changes',
|
||||
option_strings=None)
|
||||
dirname = values if values[-1] == b'/' else values+b'/'
|
||||
dirname = values if values[-1:] == b'/' else values+b'/'
|
||||
if option_string == '--subdirectory-filter':
|
||||
af(parser, namespace, dirname, '--path-match')
|
||||
af(parser, namespace, dirname+b':', '--path-rename')
|
||||
|
@ -246,12 +246,30 @@ test_expect_success '--subdirectory-filter' '
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success '--subdirectory-filter with trailing slash' '
|
||||
(
|
||||
git clone file://"$(pwd)"/metasyntactic subdir_filter_2 &&
|
||||
cd subdir_filter_2 &&
|
||||
git filter-repo \
|
||||
--subdirectory-filter words/ &&
|
||||
git cat-file --batch-check --batch-all-objects >all-objs &&
|
||||
test_line_count = 10 all-objs &&
|
||||
git log --format=%n --name-only | sort | uniq >filenames &&
|
||||
test_line_count = 6 filenames &&
|
||||
grep ^important$ filenames &&
|
||||
test_must_fail git cat-file -t v1.0 &&
|
||||
test_must_fail git cat-file -t v1.1 &&
|
||||
test $(git cat-file -t v2.0) = commit &&
|
||||
test $(git cat-file -t v3.0) = tag
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success '--to-subdirectory-filter' '
|
||||
(
|
||||
git clone file://"$(pwd)"/metasyntactic to_subdir_filter &&
|
||||
cd to_subdir_filter &&
|
||||
git filter-repo \
|
||||
--to-subdirectory-filter mysubdir &&
|
||||
--to-subdirectory-filter mysubdir/ &&
|
||||
git cat-file --batch-check --batch-all-objects >all-objs &&
|
||||
test_line_count = 22 all-objs &&
|
||||
git log --format=%n --name-only | sort | uniq >filenames &&
|
||||
|
Loading…
Reference in New Issue
Block a user