Skip to content

Commit 57ec29d

Browse files
authored
chore: skip commit if only changs were in the function run (#692)
1 parent 0e3e8df commit 57ec29d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/codegen/git/repo_operator/repo_operator.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,12 @@ def checkout_branch(self, branch_name: str | None, *, remote: bool = False, remo
446446
logger.exception(f"Error with Git operations: {e}")
447447
raise
448448

449+
def get_modified_files(self, ref: str | GitCommit) -> list[str]:
450+
"""Returns a list of modified files in the repo"""
451+
self.git_cli.git.add(A=True)
452+
diff = self.git_cli.git.diff(ref, "--name-only")
453+
return diff.splitlines()
454+
449455
def get_diffs(self, ref: str | GitCommit, reverse: bool = True) -> list[Diff]:
450456
"""Gets all staged diffs"""
451457
self.git_cli.git.add(A=True)

src/codegen/runner/servers/local_daemon.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import os
23
from contextlib import asynccontextmanager
34

45
from fastapi import FastAPI
@@ -78,6 +79,10 @@ async def run(request: RunFunctionRequest) -> CodemodRunResult:
7879
diff_req = GetDiffRequest(codemod=Codemod(user_code=request.codemod_source))
7980
diff_response = await runner.get_diff(request=diff_req)
8081
if request.commit:
81-
if commit_sha := runner.codebase.git_commit(f"[Codegen] {request.function_name}"):
82+
changed_files = runner.op.get_modified_files(runner.commit)
83+
# if the only changed file is the function that was requested, do not commit
84+
if len(changed_files) == 1 and os.path.splitext(os.path.basename(changed_files[0])) == request.function_name:
85+
logger.info(f"Skipping commit because only changes to {request.function_name} were made")
86+
elif commit_sha := runner.codebase.git_commit(f"[Codegen] {request.function_name}"):
8287
logger.info(f"Committed changes to {commit_sha.hexsha}")
8388
return diff_response.result

0 commit comments

Comments
 (0)