Revert "filter-repo: fix ugly bug with mixing path filtering and renaming"

This reverts commit df6c8652a2.  The
motivating example was wrong; path renaming should not be involved in
path filtering, it only says how paths should be renamed if they happen
to be selected.  A subsequent commit will improve the documentation.

Signed-off-by: Elijah Newren <newren@gmail.com>
pull/101/head
Elijah Newren 4 years ago
parent a4c12253a8
commit 3e1bff264c

@ -2026,20 +2026,16 @@ EXAMPLES
args.path_changes = []
args.inclusive = False
else:
# Check for incompatible --path-rename (or equivalent specification
# from --paths-from-file) used together with either
# --use-base-name or --invert-paths.
if args.use_base_name or not args.inclusive:
if any(x[0] == 'rename' for x in args.path_changes):
raise SystemExit(_("Error: path renaming is incompatible with "
"both --use-base-name and --invert-paths"))
# If we only have renaming paths (i.e. we have no filtering paths),
# then no path should be filtered out. Based on how newname() works,
# the easiest way to achieve that is setting args.inclusive to False.
# Similarly, if we have no filtering paths, then no path should be
# filtered out. Based on how newname() works, the easiest way to
# achieve that is setting args.inclusive to False.
if not any(x[0] == 'filter' for x in args.path_changes):
args.inclusive = False
# Also check for incompatible --use-base-name and --path-rename flags.
if args.use_base_name:
if any(x[0] == 'rename' for x in args.path_changes):
raise SystemExit(_("Error: --use-base-name and --path-rename are "
"incompatible."))
# Also throw some sanity checks on git version here;
# PERF: remove these checks once new enough git versions are common
p = subproc.Popen('git fast-export -h'.split(),
@ -3279,11 +3275,8 @@ class RepoFilter(object):
assert match_type in ('match','regex') # glob was translated to regex
if match_type == 'match' and filename_matches(match, full_pathname):
full_pathname = full_pathname.replace(match, repl, 1)
wanted = filtering_is_inclusive
if match_type == 'regex':
full_pathname = match.sub(repl, full_pathname)
if full_pathname != pathname:
wanted = filtering_is_inclusive
return full_pathname if (wanted == filtering_is_inclusive) else None
args = self._args

@ -178,33 +178,6 @@ test_expect_success '--paths-from-file' '
)
'
test_expect_success 'Mixing filtering and renaming paths' '
test_create_repo path_filtering_and_renaming &&
(
cd path_filtering_and_renaming &&
>.gitignore &&
mkdir -p src/main/java/com/org/{foo,bar} &&
mkdir -p src/main/resources &&
test_seq 1 10 >src/main/java/com/org/foo/uptoten &&
test_seq 11 20 >src/main/java/com/org/bar/uptotwenty &&
test_seq 1 7 >src/main/java/com/org/uptoseven &&
test_seq 1 5 >src/main/resources/uptofive &&
git add . &&
git commit -m Initial &&
git filter-repo --path .gitignore --path src/main/resources --path-rename src/main/java/com/org/foo/:src/main/java/com/org/ --force &&
cat <<-EOF >expect &&
.gitignore
src/main/java/com/org/uptoten
src/main/resources/uptofive
EOF
git ls-files >actual &&
test_cmp expect actual
)
'
test_expect_success 'setup metasyntactic repo' '
test_create_repo metasyntactic &&
(
@ -1120,7 +1093,7 @@ test_expect_success 'other startup error cases and requests for help' '
test_i18ngrep ": --analyze is incompatible with --stdin" err &&
test_must_fail git filter-repo --path-rename foo:bar --use-base-name 2>err &&
test_i18ngrep ": path renaming is incompatible with both --use-base-name and --invert-paths" err &&
test_i18ngrep ": --use-base-name and --path-rename are incompatible" err &&
test_must_fail git filter-repo --path-rename foo:bar/ 2>err &&
test_i18ngrep "either ends with a slash then both must." err &&

Loading…
Cancel
Save