Switch to exceptions instead of exit() and add a new test
MODIFY
repo2docker/app.py
repo2docker/app.py
@@ -104,7 +104,7 @@ class Repo2Docker(Application):
except subprocess.CalledProcessError:
self.log.error('Failed to clone repository!',
extra=dict(phase='failed'))
- sys.exit(1)
+ raise RuntimeError("Failed to clone %s." % url)
def _unshallow():
try:
@@ -115,7 +115,8 @@ class Repo2Docker(Application):
except subprocess.CalledProcessError:
self.log.error('Failed to unshallow repository!',
extra=dict(phase='failed'))
- sys.exit(1)
+ raise RuntimeError("Failed to create a full clone of"
+ " %s." % url)
def _contains(ref):
try:
@@ -137,11 +138,12 @@ class Repo2Docker(Application):
except subprocess.CalledProcessError:
self.log.error('Failed to check out ref %s', ref,
extra=dict(phase='failed'))
- sys.exit(1)
+ raise RuntimeError("Failed to checkout reference %s for"
+ " %s." % (ref, url))
# create a shallow clone first
_clone(depth=50)
- if ref:
+
if not _contains(ref):
# have to create a full clone
_unshallow()

DELETE
tests/external/datasci-shallow-clone.repos.yaml
-# Check that we correctly detect that this ref is more than 50 commits ago
-# and trigger a full clone of the repository
-- name: Jake's Data Science Book
- url: https://github.com/betatim/repo2docker-ci-clone-depth
- ref: f702ae5c612ca0dcaf77954f9f5dd4ede7cb9b5f
- verify: python -c "commit = open('COMMIT').read(); assert int(commit) == 1, 'this is not the first commit'"

ADD
tests/external/shallow-clone.repos.yaml
+# Check that we correctly detect that this ref is more than 50 commits ago
+# and trigger a full clone of the repository
+- name: A dummy repo with 100 commits - unshallow to reach ref
+ url: https://github.com/betatim/repo2docker-ci-clone-depth
+ ref: f702ae5c612ca0dcaf77954f9f5dd4ede7cb9b5f
+ verify: python -c "commit = open('COMMIT').read(); assert int(commit) == 1, 'this is not the first commit'"
+
+- name: A dummy repo with 100 commits - shallow clone is enough
+ url: https://github.com/betatim/repo2docker-ci-clone-depth
+ ref: 28674ab4da34585525d9c5451f6d6a872522d017
+ # we checkout the second to last commit, hence the log has 49 entries at a
+ # max clone depth of 50
+ verify: /bin/bash -c '[ $(git log --oneline | wc -l) == "49" ]'

Switch to exceptions instead of exit() and add a new test