mirror of
https://github.com/newren/git-filter-repo.git
synced 2024-07-06 18:32:14 +02:00
filter-repo: start revamping the --help page
Signed-off-by: Elijah Newren <newren@gmail.com>
This commit is contained in:
parent
5f55960dfe
commit
f813469ff8
166
git-filter-repo
166
git-filter-repo
@ -1515,83 +1515,117 @@ class AppendFilter(argparse.Action):
|
|||||||
setattr(namespace, self.dest, items)
|
setattr(namespace, self.dest, items)
|
||||||
|
|
||||||
def get_args():
|
def get_args():
|
||||||
parser = argparse.ArgumentParser(description='Rewrite repository history')
|
# Include usage in the summary, so we can put the description first
|
||||||
|
summary = '''Rewrite (or analyze) repository history
|
||||||
|
|
||||||
|
git-filter-repo destructively rewrites history (unless --analyze or --dry-run
|
||||||
|
are specified) according to specified rules. It refuses to do any rewriting
|
||||||
|
unless either run from a clean fresh clone, or --force was specified.
|
||||||
|
|
||||||
|
Basic Usage:
|
||||||
|
git-filter-repo --analyze
|
||||||
|
git-filter-repo [FILTER/RENAME/CONTROL OPTIONS]
|
||||||
|
|
||||||
|
See EXAMPLES section for details.
|
||||||
|
'''.rstrip()
|
||||||
|
|
||||||
|
# Provide a long helpful examples section
|
||||||
|
example_text = '''EXAMPLES
|
||||||
|
|
||||||
|
To get help:
|
||||||
|
git-filter-repo --help
|
||||||
|
'''
|
||||||
|
|
||||||
|
# Create the basic parser
|
||||||
|
parser = argparse.ArgumentParser(description=summary,
|
||||||
|
usage = argparse.SUPPRESS,
|
||||||
|
add_help = False,
|
||||||
|
epilog = example_text,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||||
# FIXME: Need to special case all --* args that rev-list takes, or call
|
# FIXME: Need to special case all --* args that rev-list takes, or call
|
||||||
# git rev-parse ...
|
# git rev-parse ...
|
||||||
parser.add_argument('--analyze', action='store_true',
|
analyze = parser.add_argument_group(title='Analysis')
|
||||||
help='''Analyze repository history and create a report
|
analyze.add_argument('--analyze', action='store_true',
|
||||||
that may be useful in determining what to
|
help='''Analyze repository history and create a
|
||||||
filter in a subsequent run.''')
|
report that may be useful in determining
|
||||||
parser.add_argument('--force', '-f', action='store_true',
|
what to filter in a subsequent run. Will
|
||||||
help='''Rewrite history even if the current repo does not
|
not modify your repo.''')
|
||||||
look like a fresh clone.''')
|
|
||||||
|
|
||||||
path_group = parser.add_argument_group(title='Filtering based on paths')
|
refs = parser.add_argument_group(title='Git References (positional args)')
|
||||||
path_group.add_argument('--invert-paths', action='store_false',
|
refs.add_argument('refs', nargs='*',
|
||||||
dest='inclusive',
|
help='''git refs (branches, tags, etc.) to rewrite,
|
||||||
help='''Invert the selection of files from the
|
e.g. 'master v2.1.0 v0.5.0'. Special rev-list
|
||||||
specified --path-{match,glob,regex} options
|
options, such as --branches, --tags, --all, --glob,
|
||||||
below, i.e. only select files matching none
|
or --exclude are allowed. [default: --all]. To
|
||||||
of those options.''')
|
avoid mixing new history with old, any references
|
||||||
|
not specified will be deleted.''')
|
||||||
|
|
||||||
path_group.add_argument('--path-match', '--path', metavar='DIR_OR_FILE',
|
path = parser.add_argument_group(title='Filtering based on paths')
|
||||||
action=AppendFilter, dest='path_changes',
|
path.add_argument('--invert-paths', action='store_false',
|
||||||
help='''Exact paths (files or directories) to include
|
dest='inclusive',
|
||||||
in filtered history. Multiple --path
|
help='''Invert the selection of files from the specified
|
||||||
options can be specified to get a union of
|
--path-{match,glob,regex} options below, i.e. only
|
||||||
paths.''')
|
select files matching none of those options.''')
|
||||||
path_group.add_argument('--path-glob', metavar='GLOB',
|
|
||||||
action=AppendFilter, dest='path_changes',
|
|
||||||
help='''Glob of paths to include in filtered
|
|
||||||
history. Multiple --path-glob options can
|
|
||||||
be specified to get a union of paths.''')
|
|
||||||
path_group.add_argument('--path-regex', metavar='REGEX',
|
|
||||||
action=AppendFilter, dest='path_changes',
|
|
||||||
help='''Regex of paths to include in filtered
|
|
||||||
history. Multiple --path-regex options can
|
|
||||||
be specified to get a union of paths''')
|
|
||||||
|
|
||||||
rename_group = parser.add_argument_group(title='Renaming based on paths')
|
path.add_argument('--path-match', '--path', metavar='DIR_OR_FILE',
|
||||||
rename_group.add_argument('--path-rename', '--path-rename-prefix',
|
action=AppendFilter, dest='path_changes',
|
||||||
metavar='OLD_NAME:NEW_NAME',
|
help='''Exact paths (files or directories) to include in
|
||||||
action=AppendFilter, dest='path_changes',
|
filtered history. Multiple --path options can be
|
||||||
help='''Prefix to rename; if filename starts with
|
specified to get a union of paths.''')
|
||||||
OLD_NAME, replace that with NEW_NAME.
|
path.add_argument('--path-glob', metavar='GLOB',
|
||||||
Multiple --path-rename options can be
|
action=AppendFilter, dest='path_changes',
|
||||||
specified.''')
|
help='''Glob of paths to include in filtered history.
|
||||||
|
Multiple --path-glob options can be specified to
|
||||||
|
get a union of paths.''')
|
||||||
|
path.add_argument('--path-regex', metavar='REGEX',
|
||||||
|
action=AppendFilter, dest='path_changes',
|
||||||
|
help='''Regex of paths to include in filtered history.
|
||||||
|
Multiple --path-regex options can be specified to
|
||||||
|
get a union of paths''')
|
||||||
|
|
||||||
parser.add_argument('--dry-run', action='store_true',
|
rename = parser.add_argument_group(title='Renaming based on paths')
|
||||||
help='''Do not change the repository. Run `git
|
rename.add_argument('--path-rename', '--path-rename-prefix',
|
||||||
fast-export` and filter its output, and save
|
metavar='OLD_NAME:NEW_NAME',
|
||||||
both the original and the filtered version for
|
action=AppendFilter, dest='path_changes',
|
||||||
comparison. Some filtering of empty commits
|
help='''Prefix to rename; if filename starts with
|
||||||
may not occur due to inability to query the
|
OLD_NAME, replace that with NEW_NAME. Multiple
|
||||||
fast-import backend.''')
|
--path-rename options can be specified.''')
|
||||||
parser.add_argument('--debug', action='store_true',
|
|
||||||
help='''Print additional information about operations
|
|
||||||
being performed and commands being run. When
|
|
||||||
used together with --dry-run, also show extra
|
|
||||||
information about what would be run.''')
|
|
||||||
parser.add_argument('--stdin', action='store_true',
|
|
||||||
help='''Instead of running `git fast-export` and filtering
|
|
||||||
its output, filter the fast-export stream from
|
|
||||||
stdin.''')
|
|
||||||
|
|
||||||
|
misc = parser.add_argument_group(title='Miscellaneous options')
|
||||||
|
misc.add_argument('--help', '-h', action='store_true',
|
||||||
|
help='''Show this help message and exit.''')
|
||||||
|
misc.add_argument('--force', '-f', action='store_true',
|
||||||
|
help='''Rewrite history even if the current repo does not
|
||||||
|
look like a fresh clone.''')
|
||||||
|
|
||||||
parser.add_argument('--quiet', action='store_true',
|
misc.add_argument('--dry-run', action='store_true',
|
||||||
help='''Pass --quiet to other git commands called''')
|
help='''Do not change the repository. Run `git
|
||||||
|
fast-export` and filter its output, and save both
|
||||||
|
the original and the filtered version for
|
||||||
|
comparison. Some filtering of empty commits may
|
||||||
|
not occur due to inability to query the fast-import
|
||||||
|
backend.''')
|
||||||
|
misc.add_argument('--debug', action='store_true',
|
||||||
|
help='''Print additional information about operations being
|
||||||
|
performed and commands being run. When used
|
||||||
|
together with --dry-run, also show extra
|
||||||
|
information about what would be run.''')
|
||||||
|
misc.add_argument('--stdin', action='store_true',
|
||||||
|
help='''Instead of running `git fast-export` and filtering
|
||||||
|
its output, filter the fast-export stream from
|
||||||
|
stdin.''')
|
||||||
|
misc.add_argument('--quiet', action='store_true',
|
||||||
|
help='''Pass --quiet to other git commands called''')
|
||||||
|
|
||||||
parser.add_argument('revisions', nargs='*',
|
|
||||||
help='''Branches/tags/refs to rewrite. Special rev-list
|
|
||||||
options, such as --branches, --tags, --all,
|
|
||||||
--glob, or --exclude are allowed. [default:
|
|
||||||
--all]''')
|
|
||||||
if len(sys.argv) == 1:
|
if len(sys.argv) == 1:
|
||||||
parser.print_usage()
|
parser.print_usage()
|
||||||
raise SystemExit("No arguments specified.")
|
raise SystemExit("No arguments specified.")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if not args.revisions:
|
if args.help:
|
||||||
args.revisions = ['--all']
|
parser.print_help()
|
||||||
|
raise SystemExit()
|
||||||
|
if not args.refs:
|
||||||
|
args.refs = ['--all']
|
||||||
if args.analyze and args.path_changes:
|
if args.analyze and args.path_changes:
|
||||||
raise SystemExit("Error: --analyze is incompatible with --path* flags; "
|
raise SystemExit("Error: --analyze is incompatible with --path* flags; "
|
||||||
"it's a read-only operation.")
|
"it's a read-only operation.")
|
||||||
@ -1763,7 +1797,7 @@ def gather_data(args):
|
|||||||
'--always-show-modify-after-rename',
|
'--always-show-modify-after-rename',
|
||||||
'--signed-tags=strip',
|
'--signed-tags=strip',
|
||||||
'--tag-of-filtered-object=rewrite',
|
'--tag-of-filtered-object=rewrite',
|
||||||
'--use-done-feature'] + args.revisions
|
'--use-done-feature'] + args.refs
|
||||||
fep = subprocess.Popen(fep_cmd, stdout=subprocess.PIPE)
|
fep = subprocess.Popen(fep_cmd, stdout=subprocess.PIPE)
|
||||||
input = fep.stdout
|
input = fep.stdout
|
||||||
output = open(os.devnull, 'w')
|
output = open(os.devnull, 'w')
|
||||||
@ -2134,7 +2168,7 @@ def run_fast_filter():
|
|||||||
'--signed-tags=strip',
|
'--signed-tags=strip',
|
||||||
'--tag-of-filtered-object=rewrite',
|
'--tag-of-filtered-object=rewrite',
|
||||||
'--no-data',
|
'--no-data',
|
||||||
'--use-done-feature'] + args.revisions
|
'--use-done-feature'] + args.refs
|
||||||
fep = subprocess.Popen(fep_cmd, stdout=subprocess.PIPE)
|
fep = subprocess.Popen(fep_cmd, stdout=subprocess.PIPE)
|
||||||
input = fep.stdout
|
input = fep.stdout
|
||||||
if args.dry_run or args.debug:
|
if args.dry_run or args.debug:
|
||||||
|
Loading…
Reference in New Issue
Block a user