Skip to content

Commit

Permalink
filter-repo: also allow --path-rename arguments before --path arguments
Browse files Browse the repository at this point in the history
The manual says
  Also, `--path-rename` brings up ordering issues; all path arguments are
  applied in order
which suggests that you can have --path-rename arguments both before and
after --path arguments, but having --path-rename arguments before --path
arguments was broken.  It did work once upon a time, but was broken by
  5c4637f (Documentation: add guides for people converting from
                filter-branch or BFG, 2020-05-16)
because it stored the filename in both `pathname` and `full_pathname`,
and would have renames affect only `full_pathname`, while filtering
would operate only on `pathname`.  The existence of allowing filtering
based on basename really does require us to have both variables, but
since we have both, ensure that path_rename updates both.

Signed-off-by: Elijah Newren <[email protected]>
  • Loading branch information
newren committed Nov 25, 2024
1 parent 58ab2ca commit 19b1cb6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions git-filter-repo
Original file line number Diff line number Diff line change
Expand Up @@ -3867,8 +3867,10 @@ 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)
pathname = full_pathname # rename incompatible with use_base_name
if match_type == 'regex':
full_pathname = match.sub(repl, full_pathname)
pathname = full_pathname # rename incompatible with use_base_name
return full_pathname if (wanted == filtering_is_inclusive) else None

args = self._args
Expand Down
21 changes: 21 additions & 0 deletions t/t9390-filter-repo-basics.sh
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,27 @@ test_expect_success 'Mixing filtering and renaming paths, enough filters' '
)
'

test_expect_success 'Path rename also allowed before path filtering' '
create_path_filtering_and_renaming &&
git clone --no-local path_filtering_and_renaming \
path_renaming_and_filtering &&
(
cd path_renaming_and_filtering &&
git filter-repo --invert-paths \
--path-rename src/main/java/com/org/foo/uptoten:src/main/java/org/foo/asbigasten \
--path src/main/java/com/ \
cat <<-EOF >expect &&
.gitignore
src/main/java/org/foo/asbigasten
src/main/resources/uptofive
EOF
git ls-files >actual &&
test_cmp expect actual
)
'

test_expect_success 'Mixing filtering and to-subdirectory-filter' '
create_path_filtering_and_renaming &&
git clone --no-local path_filtering_and_renaming \
Expand Down

0 comments on commit 19b1cb6

Please sign in to comment.