Skip to content

Commit 88b79ea

Browse files
Merge pull request #542 from codeflash-ai/fix/git-remote
[Fix] multiple git remotes (CF-677)
2 parents c288419 + fad810d commit 88b79ea

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

codeflash/cli_cmds/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def handle_optimize_all_arg_parsing(args: Namespace) -> Namespace:
234234
"I need a git repository to run --all and open PRs for optimizations. Exiting..."
235235
)
236236
apologize_and_exit()
237-
if not args.no_pr and not check_and_push_branch(git_repo):
237+
if not args.no_pr and not check_and_push_branch(git_repo, git_remote=args.git_remote):
238238
exit_with_message("Branch is not pushed...", error_on_exit=True)
239239
owner, repo = get_repo_owner_and_name(git_repo)
240240
if not args.no_pr:

codeflash/code_utils/git_utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ def confirm_proceeding_with_no_git_repo() -> str | bool:
117117
return True
118118

119119

120-
def check_and_push_branch(repo: git.Repo, wait_for_push: bool = False) -> bool: # noqa: FBT001, FBT002
120+
def check_and_push_branch(repo: git.Repo, git_remote: str | None = "origin", wait_for_push: bool = False) -> bool: # noqa: FBT001, FBT002
121121
current_branch = repo.active_branch.name
122-
origin = repo.remote(name="origin")
122+
remote = repo.remote(name=git_remote)
123123

124124
# Check if the branch is pushed
125-
if f"origin/{current_branch}" not in repo.refs:
125+
if f"{git_remote}/{current_branch}" not in repo.refs:
126126
logger.warning(f"⚠️ The branch '{current_branch}' is not pushed to the remote repository.")
127127
if not sys.__stdin__.isatty():
128128
logger.warning("Non-interactive shell detected. Branch will not be pushed.")
@@ -132,13 +132,13 @@ def check_and_push_branch(repo: git.Repo, wait_for_push: bool = False) -> bool:
132132
f"the branch '{current_branch}' to the remote repository?",
133133
default=False,
134134
):
135-
origin.push(current_branch)
136-
logger.info(f"⬆️ Branch '{current_branch}' has been pushed to origin.")
135+
remote.push(current_branch)
136+
logger.info(f"⬆️ Branch '{current_branch}' has been pushed to {git_remote}.")
137137
if wait_for_push:
138138
time.sleep(3) # adding this to give time for the push to register with GitHub,
139139
# so that our modifications to it are not rejected
140140
return True
141-
logger.info(f"🔘 Branch '{current_branch}' has not been pushed to origin.")
141+
logger.info(f"🔘 Branch '{current_branch}' has not been pushed to {git_remote}.")
142142
return False
143143
logger.debug(f"The branch '{current_branch}' is present in the remote repository.")
144144
return True

codeflash/result/create_pr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def check_create_pr(
185185
owner, repo = get_repo_owner_and_name(git_repo, git_remote)
186186
logger.info(f"Pushing to {git_remote} - Owner: {owner}, Repo: {repo}")
187187
console.rule()
188-
if not check_and_push_branch(git_repo, wait_for_push=True):
188+
if not check_and_push_branch(git_repo, git_remote, wait_for_push=True):
189189
logger.warning("⏭️ Branch is not pushed, skipping PR creation...")
190190
return
191191
relative_path = explanation.file_path.relative_to(git_root_dir()).as_posix()

0 commit comments

Comments
 (0)