Skip to content

Commit

Permalink
Better support for complicated file names.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kentzo committed Aug 14, 2018
1 parent 7a84efa commit 43431c4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
6 changes: 4 additions & 2 deletions git_archive_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,10 @@ def walk_git_files(self, repo_path=''):
).splitlines()

for repo_file_path in repo_file_paths:
# Git puts path in quotes if file path has unicode characters.
repo_file_path = repo_file_path.strip('"') # file path relative to current repo
# Git quotes output if it contains non-ASCII or otherwise problematic characters as ".
if repo_file_path.startswith('"') and repo_file_path.endswith('"'):
repo_file_path = repo_file_path[1:-1]

repo_file_abspath = path.join(repo_abspath, repo_file_path) # absolute file path
main_repo_file_path = path.join(repo_path, repo_file_path) # file path relative to the main repo

Expand Down
39 changes: 30 additions & 9 deletions test_git_archive_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ def archive(self, path):
})
}

base_quoted = deepcopy(base)
base_quoted['data'] = DirRecord({
'\"hello world.dat\"': FileRecord('Special cases aren\'t special enough to break the rules.'),
'\'hello world.dat\'': FileRecord('Although practicality beats purity.')
})

ignore_in_root = deepcopy(base)
ignore_in_root['.gitattributes'] = FileRecord('tests/__init__.py export-ignore')
ignore_in_root['tests'] = DirRecord({
Expand All @@ -142,48 +148,63 @@ def archive(self, path):
ignore_in_submodule = deepcopy(base)
ignore_in_submodule['lib']['.gitattributes'] = FileRecord('tests/__init__.py export-ignore')
ignore_in_submodule['lib']['tests'] = DirRecord({
'__init__.py': FileRecord('#Flat is better than nested.', excluded=True)
'__init__.py': FileRecord('#Complex is better than complicated.', excluded=True)
})

ignore_in_nested_submodule = deepcopy(base)
ignore_in_nested_submodule['lib']['extra']['.gitattributes'] = FileRecord('tests/__init__.py export-ignore')
ignore_in_nested_submodule['lib']['extra']['tests'] = DirRecord({
'__init__.py': FileRecord('#Sparse is better than dense.', excluded=True)
'__init__.py': FileRecord('#Complex is better than complicated.', excluded=True)
})

ignore_in_submodule_from_root = deepcopy(base)
ignore_in_submodule_from_root['.gitattributes'] = FileRecord('lib/tests/__init__.py export-ignore')
ignore_in_submodule_from_root['lib']['tests'] = DirRecord({
'__init__.py': FileRecord('#Readability counts.', excluded=True)
'__init__.py': FileRecord('#Complex is better than complicated.', excluded=True)
})

ignore_in_nested_submodule_from_root = deepcopy(base)
ignore_in_nested_submodule_from_root['.gitattributes'] = FileRecord('lib/extra/tests/__init__.py export-ignore')
ignore_in_nested_submodule_from_root['lib']['extra']['tests'] = DirRecord({
'__init__.py': FileRecord('#Special cases aren\'t special enough to break the rules.', excluded=True)
'__init__.py': FileRecord('#Complex is better than complicated.', excluded=True)
})

ignore_in_nested_submodule_from_submodule = deepcopy(base)
ignore_in_nested_submodule_from_submodule['lib']['.gitattributes'] = FileRecord('extra/tests/__init__.py export-ignore')
ignore_in_nested_submodule_from_submodule['lib']['extra']['tests'] = DirRecord({
'__init__.py': FileRecord('#Although practicality beats purity.', excluded=True)
'__init__.py': FileRecord('#Complex is better than complicated.', excluded=True)
})

unset_export_ignore = deepcopy(base)
unset_export_ignore['.gitattributes'] = FileRecord('.* export-ignore\n*.htaccess -export-ignore', excluded=True)
unset_export_ignore['.a'] = FileRecord('Errors should never pass silently.', excluded=True)
unset_export_ignore['.b'] = FileRecord('Unless explicitly silenced.', excluded=True)
unset_export_ignore['.htaccess'] = FileRecord('In the face of ambiguity, refuse the temptation to guess.')
unset_export_ignore['.a'] = FileRecord('Flat is better than nested.', excluded=True)
unset_export_ignore['.b'] = FileRecord('Sparse is better than dense.', excluded=True)
unset_export_ignore['.htaccess'] = FileRecord('Readability counts.')

unicode_base = deepcopy(base)
unicode_base['data'] = DirRecord({
'مرحبا بالعالم.dat': FileRecord('Special cases aren\'t special enough to break the rules.')
})

unicode_quoted = deepcopy(base)
unicode_quoted['data'] = DirRecord({
'\"مرحبا بالعالم.dat\"': FileRecord('Special cases aren\'t special enough to break the rules.'),
'\'привет мир.dat\'': FileRecord('Although practicality beats purity.')
})


@pytest.mark.parametrize('contents', [
pytest.param(base, id='No Ignore'),
pytest.param(base_quoted, id='No Ignore (Quoted)'),
pytest.param(ignore_in_root, id='Ignore in Root'),
pytest.param(ignore_in_submodule, id='Ignore in Submodule'),
pytest.param(ignore_in_nested_submodule, id='Ignore in Nested Submodule'),
pytest.param(ignore_in_submodule_from_root, id='Ignore in Submodule from Root'),
pytest.param(ignore_in_nested_submodule_from_root, id='Ignore in Nested Submodule from Root'),
pytest.param(unset_export_ignore, id='-export-ignore')
pytest.param(ignore_in_nested_submodule_from_submodule, id='Ignore in Nested Submodule from Submodule'),
pytest.param(unset_export_ignore, id='-export-ignore'),
pytest.param(unicode_base, id='No Ignore (Unicode)'),
pytest.param(unicode_quoted, id='No Ignore (Quoted Unicode)')
])
def test_ignore(contents, tmpdir, git_env):
"""
Expand Down

0 comments on commit 43431c4

Please sign in to comment.