Do not push branch if no commits have been made on the branch #26
|
@ -147,6 +147,21 @@ def push_changes(cwd: Path, branch_name: str, issue_number: str, issue_title: st
|
||||||
]
|
]
|
||||||
run_cmd(cmd, cwd)
|
run_cmd(cmd, cwd)
|
||||||
|
|
||||||
|
def has_commits_on_branch(cwd: Path, base_branch: str, current_branch: str) -> bool:
|
||||||
|
"""Check if there are any commits on the current branch that aren't in the base branch."""
|
||||||
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
["git", "log", f"{base_branch}..{current_branch}", "--oneline"],
|
||||||
|
check=True,
|
||||||
|
cwd=cwd,
|
||||||
|
capture_output=True,
|
||||||
|
text=True
|
||||||
|
)
|
||||||
|
return bool(result.stdout.strip())
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
logger.exception(f"Failed to check commits on branch {current_branch}")
|
||||||
|
return False
|
||||||
|
|
||||||
def run_cmd(cmd: list[str], cwd:Path|None=None) -> None:
|
def run_cmd(cmd: list[str], cwd:Path|None=None) -> None:
|
||||||
print(cmd)
|
print(cmd)
|
||||||
subprocess.run(cmd, check=True, cwd=cwd)
|
subprocess.run(cmd, check=True, cwd=cwd)
|
||||||
|
@ -160,7 +175,12 @@ def process_issue(args, tmpdirname: Path, branch_name: str, issue_title: str, is
|
||||||
run_cmd(["git", "checkout", "-b", branch_name], tmpdirname)
|
run_cmd(["git", "checkout", "-b", branch_name], tmpdirname)
|
||||||
run_cmd(create_aider_command(f'# {issue_title}\n{issue_description}'), tmpdirname)
|
run_cmd(create_aider_command(f'# {issue_title}\n{issue_description}'), tmpdirname)
|
||||||
run_cmd(["git", "add", "."], tmpdirname)
|
run_cmd(["git", "add", "."], tmpdirname)
|
||||||
push_changes(tmpdirname, branch_name, issue_number, issue_title, issue_description, args.base_branch)
|
|
||||||
|
# Check if there are any commits on the branch before pushing
|
||||||
|
if has_commits_on_branch(tmpdirname, args.base_branch, branch_name):
|
||||||
|
push_changes(tmpdirname, branch_name, issue_number, issue_title, issue_description, args.base_branch)
|
||||||
|
else:
|
||||||
|
logger.info(f"No commits made on branch {branch_name}, skipping push")
|
||||||
|
|
||||||
def handle_issues(args, client, seen_issues_db):
|
def handle_issues(args, client, seen_issues_db):
|
||||||
"""Process all open issues with the 'aider' label."""
|
"""Process all open issues with the 'aider' label."""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user