Skip to content
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
10 changes: 8 additions & 2 deletions src/codegen/git/repo_operator/repo_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,14 @@ def git_cli(self) -> GitCLI:
return git_cli

@property
def head_commit(self) -> GitCommit:
return self.git_cli.head.commit
def head_commit(self) -> GitCommit | None:
try:
return self.git_cli.head.commit
except ValueError as e:
if (f"Reference at {self.git_cli.head.ref.path!r} does not exist") in str(e):
logger.info(f"Ref: {self.git_cli.head.ref.name} has no commits")
return None
raise

@property
def git_diff(self) -> str:
Expand Down
5 changes: 5 additions & 0 deletions src/codegen/sdk/core/codebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,10 @@ def checkout(
result = self._op.checkout_commit(commit_hash=commit)
if result == CheckoutResult.SUCCESS:
logger.info(f"Checked out {branch or commit}")
if self._op.head_commit is None:
logger.info(f"Ref: {self._op.git_cli.head.ref.name} has no commits")
return CheckoutResult.SUCCESS

self.sync_to_commit(self._op.head_commit)
elif result == CheckoutResult.NOT_FOUND:
logger.info(f"Could not find branch {branch or commit}")
Expand Down Expand Up @@ -1435,6 +1439,7 @@ def from_string(

with tempfile.TemporaryDirectory(prefix="codegen_") as tmp_dir:
logger.info(f"Using directory: {tmp_dir}")

codebase = CodebaseFactory.get_codebase_from_files(repo_path=tmp_dir, files=files, programming_language=prog_lang)
logger.info("Codebase initialization complete")
return codebase
Expand Down
Loading