Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --ignore-gitattr to ignore .gitattributes #82

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions git_archive_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class GitArchiver(object):

LOG = logging.getLogger('GitArchiver')

def __init__(self, prefix='', exclude=True, force_sub=False, extra=None, main_repo_abspath=None, git_version=None):
def __init__(self, prefix='', exclude=True, ignore_gitattributes=False, force_sub=False, extra=None, main_repo_abspath=None, git_version=None):
"""
@param prefix: Prefix used to prepend all paths in the resulting archive.
Extra file paths are only prefixed if they are not relative.
Expand All @@ -152,6 +152,8 @@ def __init__(self, prefix='', exclude=True, force_sub=False, extra=None, main_re

@param exclude: Determines whether archiver should follow rules specified in .gitattributes files.

@param exclude: Ignore .gitattributes files.

@param force_sub: Determines whether submodules are initialized and updated before archiving.

@param extra: List of extra paths to include in the resulting archive.
Expand Down Expand Up @@ -184,6 +186,7 @@ def __init__(self, prefix='', exclude=True, force_sub=False, extra=None, main_re

self.prefix = fspath(prefix)
self.exclude = exclude
self.ignore_gitattributes = ignore_gitattributes
self.extra = [fspath(e) for e in extra] if extra is not None else []
self.force_sub = force_sub

Expand Down Expand Up @@ -286,10 +289,11 @@ def is_file_excluded(self, repo_abspath, repo_file_path):
else:
repo_file_dir_path = path.dirname(repo_file_path)

if repo_file_dir_path:
cache[repo_file_path] = self.is_file_excluded(repo_abspath, repo_file_dir_path)
else:
cache[repo_file_path] = False
if not self.ignore_gitattributes:
if repo_file_dir_path:
cache[repo_file_path] = self.is_file_excluded(repo_abspath, repo_file_dir_path)
else:
cache[repo_file_path] = False

return cache[repo_file_path]

Expand Down Expand Up @@ -333,8 +337,9 @@ def walk_git_files(self, repo_path=fspath('')):
if not path.islink(repo_file_abspath) and path.isdir(repo_file_abspath):
continue

if self.is_file_excluded(repo_abspath, repo_file_path):
continue
if not self.ignore_gitattributes:
if self.is_file_excluded(repo_abspath, repo_file_path):
continue

yield main_repo_file_path

Expand All @@ -355,13 +360,15 @@ def walk_git_files(self, repo_path=fspath('')):
repo_submodule_path = fspath(m.group(1)) # relative to repo_path
main_repo_submodule_path = path.join(repo_path, repo_submodule_path) # relative to main_repo_abspath

if self.is_file_excluded(repo_abspath, repo_submodule_path):
continue
if not self.ignore_gitattributes:
if self.is_file_excluded(repo_abspath, repo_submodule_path):
continue

for main_repo_submodule_file_path in self.walk_git_files(main_repo_submodule_path):
repo_submodule_file_path = path.relpath(main_repo_submodule_file_path, repo_path) # relative to repo_path
if self.is_file_excluded(repo_abspath, repo_submodule_file_path):
continue
if not self.ignore_gitattributes:
if self.is_file_excluded(repo_abspath, repo_submodule_file_path):
continue

yield main_repo_submodule_file_path
except IOError:
Expand Down Expand Up @@ -556,7 +563,7 @@ def main(argv=None):
from optparse import OptionParser, SUPPRESS_HELP

parser = OptionParser(
usage="usage: %prog [-v] [-C BASE_REPO] [--prefix PREFIX] [--no-exclude]"
usage="usage: %prog [-v] [-C BASE_REPO] [--prefix PREFIX] [--no-exclude] [--ignore-gitattr]"
" [--force-submodules] [--extra EXTRA1 ...] [--dry-run] [-0 | ... | -9] OUTPUT_FILE",
version="%prog {0}".format(__version__)
)
Expand Down Expand Up @@ -586,6 +593,12 @@ def main(argv=None):
default=True,
help="ignore the [-]export-ignore attribute in .gitattributes")

parser.add_option('--ignore-gitattr',
action='store_true',
dest='ignore_gitattributes',
default=False,
help="ignore .gitattributes files")

parser.add_option('--force-submodules',
action='store_true',
dest='force_sub',
Expand Down Expand Up @@ -638,6 +651,7 @@ def main(argv=None):
GitArchiver.LOG.setLevel(logging.DEBUG if options.verbose else logging.INFO)
archiver = GitArchiver(options.prefix,
options.exclude,
options.ignore_gitattributes,
options.force_sub,
options.extra,
path.abspath(options.base_repo) if options.base_repo is not None else None
Expand Down