Skip to content

Commit

Permalink
fix: Handle no remote gracefully
Browse files Browse the repository at this point in the history
Issue-24: #24
PR-75: #75
  • Loading branch information
chme committed Mar 17, 2024
1 parent 305f159 commit 92f6f94
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/git_changelog/build.py
Expand Up @@ -309,7 +309,7 @@ def get_remote_url(self) -> str:
The origin remote URL.
"""
remote = "remote." + os.environ.get("GIT_CHANGELOG_REMOTE", "origin") + ".url"
git_url = self.run_git("config", "--get", remote).rstrip("\n")
git_url = self.run_git("config", "--default", "", "--get", remote).rstrip("\n")
if git_url.startswith("git@"):
git_url = git_url.replace(":", "/", 1).replace("git@", "https://", 1)
if git_url.endswith(".git"):
Expand Down
21 changes: 21 additions & 0 deletions tests/test_build.py
Expand Up @@ -197,3 +197,24 @@ def _assert_version(
assert version.previous_version is None
hashes = [commit.hash for commit in version.commits]
assert hashes == expected_commits


def test_no_remote_url(repo: GitRepo) -> None:
"""Test parsing and grouping commits to versions without a git remote.
Parameters:
repo: GitRepo to a temporary repository.
"""
repo.git("remote", "remove", "origin")
commit_a = repo.first_hash
repo.tag("1.0.0")

changelog = Changelog(repo.path, convention=AngularConvention)

assert len(changelog.versions_list) == 1
_assert_version(
changelog.versions_list[0],
expected_tag="1.0.0",
expected_prev_tag=None,
expected_commits=[commit_a],
)

0 comments on commit 92f6f94

Please sign in to comment.