git-filter-repo/t/t9391/file_filter.py
Elijah Newren cbacb6cd82 filter-repo: simplify import in lib-usage examples
Python wants filenames with underscores instead of hyphens and with a
.py extension.  We really want the main file named git-filter-repo, but
we can add a git_filter_repo.py symlink.  Doing so dramatically
simplifies the steps needed to import it as a library in external python
scripts.

Signed-off-by: Elijah Newren <newren@gmail.com>
2019-04-26 07:56:03 -07:00

25 lines
668 B
Python
Executable File

#!/usr/bin/env python
import sys
import git_filter_repo as fr
def drop_file_by_contents(blob):
bad_file_contents = 'The launch code is 1-2-3-4.'
if blob.data == bad_file_contents:
blob.skip()
def drop_files_by_name(commit):
new_file_changes = []
for change in commit.file_changes:
if not change.filename.endswith('.doc'):
new_file_changes.append(change)
commit.file_changes = new_file_changes
sys.argv.append('--force')
args = fr.FilteringOptions.parse_args(sys.argv[1:])
filter = fr.RepoFilter(args,
blob_callback = drop_file_by_contents,
commit_callback = drop_files_by_name)
filter.run()