Skip to content

Commit

Permalink
set git refresh before importing errors/repo
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloitu committed May 20, 2023
1 parent d2a14bf commit 609a294
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions floatcsep/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from urllib.parse import urlencode
from csep.utils.time_utils import datetime_to_utc_epoch, utc_now_datetime
from csep.core.catalogs import CSEPCatalog
from git import Repo, InvalidGitRepositoryError, NoSuchPathError
import git
import requests
import hashlib
import os
Expand Down Expand Up @@ -97,10 +97,12 @@ def from_git(url, path, branch=None, depth=1, **kwargs):
"""

kwargs.update({'depth': depth})
git.refresh()

try:
repo = Repo(path)
except (NoSuchPathError, InvalidGitRepositoryError):
repo = Repo.clone_from(url, path, branch=branch, **kwargs)
repo = git.Repo(path)
except (git.NoSuchPathError, git.InvalidGitRepositoryError):
repo = git.Repo.clone_from(url, path, branch=branch, **kwargs)
git_dir = os.path.join(path, '.git')
if os.path.isdir(git_dir):
shutil.rmtree(git_dir)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def tearDownClass(cls) -> None:


class TestGitter(unittest.TestCase):
@mock.patch('floatcsep.accessors.Repo')
@mock.patch('floatcsep.accessors.git.Repo')
@mock.patch('git.Git')
def runTest(self, mock_git, mock_repo):
p = mock.PropertyMock(return_value=False)
Expand Down

0 comments on commit 609a294

Please sign in to comment.