mirror of
https://github.com/newren/git-filter-repo.git
synced 2024-11-07 09:20:29 +00:00
filter-repo: throw an error if user specifies any path starting with a slash
All paths are intended to be relative paths, relative to the project root, not to the filesystem root. There have been a few people who didn't understand this, and then ended up with fast-import crashes that are not very clear. Check for it early and throw a simple error message instead. Signed-off-by: Elijah Newren <newren@gmail.com>
This commit is contained in:
parent
764e0e00dd
commit
2833ef275f
@ -1632,11 +1632,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."))
|
||||
if any(v.startswith(b'/') for v in values):
|
||||
raise SystemExit(_("Error: Pathnames cannot begin with a '/'"))
|
||||
components = values[0].split(b'/') + values[1].split(b'/')
|
||||
else:
|
||||
mod_type = 'filter'
|
||||
match_type = suffix
|
||||
components = values.split(b'/')
|
||||
if values.startswith(b'/'):
|
||||
raise SystemExit(_("Error: Pathnames cannot begin with a '/'"))
|
||||
for illegal_path in [b'.', b'..', b'.git']:
|
||||
if illegal_path in components:
|
||||
raise SystemExit(_("Error: Invalid path component '%s' found in '%s'")
|
||||
|
@ -1108,8 +1108,22 @@ test_expect_success 'other startup error cases and requests for help' '
|
||||
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
|
||||
test_i18ngrep "Invalid path component .\.. found in .foo/bar:\." err &&
|
||||
|
||||
test_must_fail git filter-repo --path /foo/bar 2>err &&
|
||||
test_i18ngrep "Pathnames cannot begin with a ./" err &&
|
||||
|
||||
test_must_fail git filter-repo --path-rename foo:/bar 2>err &&
|
||||
test_i18ngrep "Pathnames cannot begin with a ./" err &&
|
||||
|
||||
test_must_fail git filter-repo --path-rename /foo:bar 2>err &&
|
||||
test_i18ngrep "Pathnames cannot begin with a ./" err &&
|
||||
|
||||
test_must_fail git filter-repo --subdirectory-filter /foo 2>err &&
|
||||
test_i18ngrep "Pathnames cannot begin with a ./" err &&
|
||||
|
||||
test_must_fail git filter-repo --subdirectory-filter /foo 2>err &&
|
||||
test_i18ngrep "Pathnames cannot begin with a ./" err
|
||||
)
|
||||
'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user