mirror of
https://github.com/newren/git-filter-repo.git
synced 2024-11-19 03:25:33 +00:00
filter-repo: warn users who try to use invalid path components
It's hard to be exhaustive, but if users try something like: --path-rename foo/bar/baz:. or --path ../other-dir then bad things happen. In the first case, filter-repo will try to ask fast-import to create a directory named '.' and move everything from foo/bar/baz/ into it but of course '.' is a reserved directory name so we can't create it. In the second case, they are probably running from a subdirectory, but filter-repo doesn't work from a subdirectory. I hard-coded the assumption that everything was in the toplevel directory and all paths were relative from there pretty early on. So, if the user tries to use any of these components anywhere, just throw an early error. Signed-off-by: Elijah Newren <newren@gmail.com>
This commit is contained in:
parent
3bdfa91768
commit
7cfef09e9b
@ -1602,6 +1602,7 @@ class GitUtils(object):
|
||||
class FilteringOptions(object):
|
||||
class AppendFilter(argparse.Action):
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
user_path = values
|
||||
suffix = option_string[len('--path-'):] or 'match'
|
||||
if suffix.startswith('rename'):
|
||||
mod_type = 'rename'
|
||||
@ -1612,9 +1613,15 @@ class FilteringOptions(object):
|
||||
raise SystemExit(_("Error: With --path-rename, if OLD_NAME and "
|
||||
"NEW_NAME are both non-empty and either ends "
|
||||
"with a slash then both must."))
|
||||
components = values[0].split(b'/') + values[1].split(b'/')
|
||||
else:
|
||||
mod_type = 'filter'
|
||||
match_type = suffix
|
||||
components = values.split(b'/')
|
||||
for illegal_path in [b'.', b'..', b'.git']:
|
||||
if illegal_path in components:
|
||||
raise SystemExit(_("Error: Invalid path component '%s' found in '%s'")
|
||||
% (decode(illegal_path), decode(user_path)))
|
||||
if match_type == 'regex':
|
||||
values = re.compile(values)
|
||||
items = getattr(namespace, self.dest, []) or []
|
||||
|
@ -1028,7 +1028,10 @@ test_expect_success 'other startup error cases and requests for help' '
|
||||
test_i18ngrep "renaming globs makes no sense" err &&
|
||||
|
||||
test_must_fail git filter-repo --strip-blobs-bigger-than 3GiB 2>err &&
|
||||
test_i18ngrep "could not parse.*3GiB" err
|
||||
test_i18ngrep "could not parse.*3GiB" err &&
|
||||
|
||||
test_must_fail git filter-repo --path-rename foo/bar:. 2>err &&
|
||||
test_i18ngrep "Invalid path component .\.. found in .foo/bar:\." err
|
||||
|
||||
)
|
||||
'
|
||||
|
Loading…
Reference in New Issue
Block a user