Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
doshitan committed Dec 26, 2024
1 parent 6bd1853 commit 407d6af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
20 changes: 18 additions & 2 deletions nava/platform/util/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,16 @@ def tag(self, tag: str) -> None:
def rename_branch(self, new_branch_name: str) -> None:
self._run_cmd(["git", "branch", "-m", new_branch_name])

def get_commit_hash_for_head(self) -> str:
return self._run_cmd(["git", "rev-parse", "HEAD"]).stdout.strip()
def get_commit_hash_for_head(self) -> str | None:
result = self._run_cmd(["git", "rev-parse", "HEAD"])

# say you run this against an empty repo, you'll get a return code of
# 128 and message "fatal: ambiguous argument 'HEAD': unknown revision or
# path not in the working tree."
if result.returncode != 0:
return None

return result.stdout.strip()

def is_path_ignored(self, path: str) -> bool:
result = self._run_cmd(["git", "check-ignore", "-q", path])
Expand Down Expand Up @@ -135,6 +143,14 @@ def get_commit_description(self, commit_ish: str = "HEAD") -> str | None:

return result.stdout.strip()

def get_commit_count(self, ref: str = "HEAD") -> int | None:
result = self._run_cmd(["git", "rev-list", "--count", ref])

if result.returncode != 0:
return None

return result.stdout.strip()


def is_a_git_worktree(dir: Path) -> bool:
result = run_text(
Expand Down
8 changes: 4 additions & 4 deletions tests/projects/test_migrate_from_legacy_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_migrate_from_legacy_no_commit(
cli_context: CliContext,
):
project = Project(legacy_project_dir_with_git.dir)
commit_count_before = len(project.git.log().stdout.splitlines())
commit_count_before = len(project.git.log("--oneline ").stdout.splitlines())

MigrateFromLegacyTemplate(
ctx=cli_context,
Expand All @@ -73,7 +73,7 @@ def test_migrate_from_legacy_no_commit(
new_version_answers_file_name="foo.yml",
).migrate_from_legacy(commit=False)

commit_count_after = len(project.git.log().stdout.splitlines())
commit_count_after = len(project.git.log("--oneline").stdout.splitlines())

# only new file should exist
assert (project.dir / ".template" / "foo.yml").exists()
Expand All @@ -88,7 +88,7 @@ def test_migrate_from_legacy_commit(
cli_context: CliContext,
):
project = Project(legacy_project_dir_with_git.dir)
commit_count_before = len(project.git.log().stdout.splitlines())
commit_count_before = len(project.git.log("--oneline ").stdout.splitlines())

MigrateFromLegacyTemplate(
ctx=cli_context,
Expand All @@ -97,7 +97,7 @@ def test_migrate_from_legacy_commit(
new_version_answers_file_name="foo.yml",
).migrate_from_legacy(commit=True)

commit_count_after = len(project.git.log().stdout.splitlines())
commit_count_after = len(project.git.log("--oneline").stdout.splitlines())

# only new file should exist
assert (project.dir / ".template" / "foo.yml").exists()
Expand Down

0 comments on commit 407d6af

Please sign in to comment.