From ca40ba71ed6aa6e29464f882af1e9653e7091247 Mon Sep 17 00:00:00 2001 From: Laurent Bonnans Date: Thu, 17 Oct 2019 12:22:45 +0200 Subject: [PATCH] Optionally specify the main git repository Follows git's convention for option naming --- README.rst | 1 + git_archive_all.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 16dbbfb..3dd7f6c 100644 --- a/README.rst +++ b/README.rst @@ -33,6 +33,7 @@ Archive repository with all its submodules. --prefix=PREFIX Prepend PREFIX to each filename in the archive. OUTPUT_FILE name is used by default to avoid tarbomb. You can set it to '' in order to explicitly request tarbomb. + -C BASE_REPO Use BASE_REPO as the main repository git working directory to archive. Defaults to current directory when empty --no-exclude Don't read .gitattributes files for patterns containing export-ignore attributes. --force-submodules Force a `git submodule init && git submodule update` at each level before iterating submodules diff --git a/git_archive_all.py b/git_archive_all.py index 8d454ec..5034f91 100755 --- a/git_archive_all.py +++ b/git_archive_all.py @@ -484,8 +484,8 @@ def main(): from optparse import OptionParser, SUPPRESS_HELP parser = OptionParser( - usage="usage: %prog [-v] [--prefix PREFIX] [--no-exclude] [--force-submodules]" - " [--extra EXTRA1 ...] [--dry-run] [-0 | ... | -9] OUTPUT_FILE", + usage="usage: %prog [-v] [-C BASE_REPO] [--prefix PREFIX] [--no-exclude]" + " [--force-submodules] [--extra EXTRA1 ...] [--dry-run] [-0 | ... | -9] OUTPUT_FILE", version="%prog {0}".format(__version__) ) @@ -497,6 +497,13 @@ def main(): OUTPUT_FILE name is used by default to avoid tarbomb. You can set it to '' in order to explicitly request tarbomb""") + parser.add_option('-C', + type='string', + dest='base_repo', + default=None, + help="""use BASE_REPO as the main repository git working directory to archive. + Defaults to current directory when empty""") + parser.add_option('-v', '--verbose', action='store_true', dest='verbose', @@ -561,7 +568,9 @@ def main(): archiver = GitArchiver(options.prefix, options.exclude, options.force_sub, - options.extra) + options.extra, + path.abspath(options.base_repo) if options.base_repo is not None else None + ) archiver.create(output_file_path, options.dry_run, compresslevel=options.compresslevel) except Exception as e: parser.exit(2, "{0}\n".format(e))