Skip to content

Commit

Permalink
Check git remote exists (#126)
Browse files Browse the repository at this point in the history
* bugfix for get_studio_token_and_repo_url

* check git remote exists
  • Loading branch information
Dave Berenbaum authored Dec 11, 2023
1 parent 3c898a5 commit 39e7abf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/dvc_studio_client/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def _get_remote_url() -> str:
except IndexError:
# IndexError happens when the head is detached
_remote, url = get_remote_repo(repo, b"origin")
return url
# Dulwich returns (None, "origin") if no remote set
if (_remote, url) == (None, "origin"):
logger.warning("No Git remote. Can't infer Studio repo URL.")
else:
return url


@lru_cache(maxsize=1)
Expand Down
9 changes: 8 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@
)


def test_get_url(monkeypatch, tmp_path_factory):
def test_get_remote_url(monkeypatch, tmp_path_factory):
source = os.fspath(tmp_path_factory.mktemp("source"))
target = os.fspath(tmp_path_factory.mktemp("target"))
with init(source), clone(source, target):
monkeypatch.chdir(target)
assert _get_remote_url() == source


def test_get_remote_url_no_remote(monkeypatch, tmp_path_factory):
target = os.fspath(tmp_path_factory.mktemp("target"))
with init(target):
monkeypatch.chdir(target)
assert _get_remote_url() is None


@pytest.mark.parametrize(
"token,repo_url",
[(DVC_STUDIO_TOKEN, DVC_STUDIO_REPO_URL), (STUDIO_TOKEN, STUDIO_REPO_URL)],
Expand Down

0 comments on commit 39e7abf

Please sign in to comment.