2018-11-05 15:31:06 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2019-03-05 20:00:11 +01:00
|
|
|
"""
|
|
|
|
Please see the
|
|
|
|
***** API BACKWARD COMPATIBILITY CAVEAT *****
|
|
|
|
near the top of git-filter-repo.
|
|
|
|
|
|
|
|
Also, note that splicing repos may need some special care as fast-export
|
|
|
|
only shows the files that changed relative to the first parent, so there
|
|
|
|
may be gotchas if you are to splice near merge commits; this example does
|
|
|
|
not try to handle any such special cases.
|
|
|
|
"""
|
|
|
|
|
2018-11-05 15:31:06 +01:00
|
|
|
import sys
|
2019-02-10 03:24:37 +01:00
|
|
|
import git_filter_repo as fr
|
2018-11-05 15:31:06 +01:00
|
|
|
|
|
|
|
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')
|
2019-02-10 03:24:37 +01:00
|
|
|
args = fr.FilteringOptions.parse_args(sys.argv[1:])
|
2018-11-05 15:31:06 +01:00
|
|
|
|
2019-02-10 03:24:37 +01:00
|
|
|
filter = fr.RepoFilter(args,
|
|
|
|
blob_callback = drop_file_by_contents,
|
|
|
|
commit_callback = drop_files_by_name)
|
2018-11-05 15:31:06 +01:00
|
|
|
filter.run()
|