Skip to content

Commit

Permalink
Fixed handling of broken symlinks.
Browse files Browse the repository at this point in the history
Skipping broken symlinks, but not all symlinks.

Reported in #20
  • Loading branch information
Robpol86 committed Aug 22, 2016
1 parent 3800876 commit 8dbff4e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Changed

Fixed
* https://github.com/Robpol86/sphinxcontrib-versioning/issues/13
* https://github.com/Robpol86/sphinxcontrib-versioning/pull/20

Removed
* Jinja2 context variables: ``scv_root_ref_is_branch`` ``scv_root_ref_is_tag``
Expand Down
8 changes: 7 additions & 1 deletion sphinxcontrib/versioning/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def export(local_root, commit, target):
:param str commit: Git commit SHA to export.
:param str target: Directory to export to.
"""
log = logging.getLogger(__name__)
git_command = ['git', 'archive', '--format=tar', commit]

with TempDir() as temp_dir:
Expand All @@ -289,7 +290,12 @@ def export(local_root, commit, target):
if not os.path.exists(t_dirpath):
os.makedirs(t_dirpath)
for args in ((os.path.join(s_dirpath, f), os.path.join(t_dirpath, f)) for f in s_filenames):
shutil.copy(*args)
try:
shutil.copy(*args)
except IOError:
if not os.path.islink(args[0]):
raise
log.debug('Skipping broken symlink: %s', args[0])


def clone(local_root, new_root, branch, rel_dest, exclude):
Expand Down
24 changes: 24 additions & 0 deletions tests/test_git/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,27 @@ def test_new_branch_tags(tmpdir, local_light, fail):
files = [f.relto(target) for f in target.listdir()]
assert files == ['README']
assert target.join('README').read() == 'new'


def test_symlink(tmpdir, local, run):
"""Test repos with broken symlinks.
:param tmpdir: pytest fixture.
:param local: conftest fixture.
:param run: conftest fixture.
"""
orphan = tmpdir.ensure('to_be_removed')
local.join('good_symlink').mksymlinkto('README')
local.join('broken_symlink').mksymlinkto('to_be_removed')
run(local, ['git', 'add', 'good_symlink', 'broken_symlink'])
run(local, ['git', 'commit', '-m', 'Added symlinks.'])
run(local, ['git', 'push', 'origin', 'master'])
orphan.remove()

target = tmpdir.ensure_dir('target')
sha = run(local, ['git', 'rev-parse', 'HEAD']).strip()

export(str(local), sha, str(target))
run(local, ['git', 'diff-index', '--quiet', 'HEAD', '--']) # Exit 0 if nothing changed.
files = sorted(f.relto(target) for f in target.listdir())
assert files == ['README', 'good_symlink']

0 comments on commit 8dbff4e

Please sign in to comment.