Skip to content

Commit

Permalink
Raising PullError when there's an error cloning or pulling
Browse files Browse the repository at this point in the history
  • Loading branch information
mikicz committed Feb 23, 2018
1 parent 665e6d8 commit 27d5b46
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
14 changes: 10 additions & 4 deletions arca/_arca.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import re
from dogpile.cache import make_region, CacheRegion
from git import Repo, InvalidGitRepositoryError
from git import Repo, InvalidGitRepositoryError, GitCommandError

from .exceptions import ArcaMisconfigured, FileOutOfRangeError
from .exceptions import ArcaMisconfigured, FileOutOfRangeError, PullError
from .backend import BaseBackend
from .result import Result
from .task import Task
Expand Down Expand Up @@ -153,7 +153,10 @@ def _pull(self, *, repo_path: Path=None, git_repo: Repo=None, repo: str=None, br
In a separate method so pulls can be counted in testing.
"""
if git_repo is not None:
git_repo.remote().pull()
try:
git_repo.remote().pull()
except GitCommandError:
raise PullError("There was an error pulling the target repository.")
return git_repo
else:
kwargs = {}
Expand All @@ -168,7 +171,10 @@ def _pull(self, *, repo_path: Path=None, git_repo: Repo=None, repo: str=None, br
kwargs["reference-if-able"] = str(reference.absolute())
kwargs["dissociate"] = True

return Repo.clone_from(repo, str(repo_path), branch=branch, **kwargs)
try:
return Repo.clone_from(repo, str(repo_path), branch=branch, **kwargs)
except GitCommandError:
raise PullError("There was an error cloning the target repository.")

def current_git_hash(self, repo: str, branch: str, git_repo: Repo, short: bool=False) -> str:
current_hash = self._current_hash[self.repo_id(repo)].get(branch)
Expand Down
4 changes: 4 additions & 0 deletions arca/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class TaskMisconfigured(ValueError, ArcaException):
pass


class PullError(ArcaException):
pass


class BuildError(ArcaException):

def __init__(self, *args, extra_info=None, **kwargs):
Expand Down
28 changes: 27 additions & 1 deletion tests/test_arca_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from git import Repo

from arca import Arca, VenvBackend, CurrentEnvironmentBackend
from arca.exceptions import ArcaMisconfigured, FileOutOfRangeError
from arca.exceptions import ArcaMisconfigured, FileOutOfRangeError, PullError
from common import BASE_DIR


Expand Down Expand Up @@ -365,3 +365,29 @@ def test_is_dirty():
fl.unlink()

assert not arca.is_dirty()


def test_pull_error():
arca = Arca(base_dir=BASE_DIR)

git_dir = Path("/tmp/arca/") / str(uuid4())
git_url = f"file://{git_dir}"

with pytest.raises(PullError):
arca.get_files(git_url, "master")

filepath = git_dir / "test_file.txt"
repo = Repo.init(git_dir)
filepath.write_text(str(uuid4()))
repo.index.add([str(filepath)])
repo.index.commit("Initial")

arca.get_files(git_url, "master")

with pytest.raises(PullError):
arca.get_files(git_url, "some_branch")

shutil.rmtree(str(git_dir))

with pytest.raises(PullError):
arca.get_files(git_url, "master")

0 comments on commit 27d5b46

Please sign in to comment.