Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle repo with invalid HEAD state #645

Merged
merged 1 commit into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/orion/core/io/resolve_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,13 @@ def infer_versioning_metadata(user_script):
git_repo = fetch_user_repo(user_script)
if not git_repo:
return {}
if not git_repo.head.is_valid():
logging.warning(
f"Repository at {git_repo.git.rev_parse('--show-toplevel')} has an invalid HEAD. "
"No commits maybe?"
)
return {}

vcs = {}
vcs["type"] = "git"
vcs["is_dirty"] = git_repo.is_dirty()
Expand Down
25 changes: 25 additions & 0 deletions tests/unittests/core/io/test_resolve_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,31 @@ def repo():
os.chdir("orion")


@pytest.fixture
def invalid_repo():
"""Create a dummy invalid repo for the tests."""
os.chdir("../")
os.makedirs("dummy_orion")
os.chdir("dummy_orion")
repo = git.Repo.init(".")
with open("README.md", "w+") as f:
f.write("dummy content")
# No commit, no branch, blank...
yield repo
os.chdir("../")
shutil.rmtree("dummy_orion")
os.chdir("orion")


def test_infer_version_on_invalid_head(invalid_repo, caplog):
"""Test that repo is ignored if repo has an invalid HEAD state."""

with caplog.at_level(logging.WARNING):
assert resolve_config.infer_versioning_metadata(".git") == {}

assert "dummy_orion has an invalid HEAD." in caplog.text


def test_infer_versioning_metadata_on_clean_repo(repo):
"""
Test how `infer_versioning_metadata` fills its different fields
Expand Down