Skip to content

Commit 5c8fbf6

Browse files
committed
bug fix when pushing branch
1 parent 5675ef0 commit 5c8fbf6

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

codeflash/code_utils/git_utils.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
from git import Repo
2323

2424

25-
def get_git_diff(repo_directory: Path = Path.cwd(), uncommitted_changes: bool = False) -> dict[str, list[int]]: # noqa: B008, FBT001, FBT002
25+
def get_git_diff(repo_directory: Path | None = None, *, uncommitted_changes: bool = False) -> dict[str, list[int]]:
26+
if repo_directory is None:
27+
repo_directory = Path.cwd()
2628
repository = git.Repo(repo_directory, search_parent_directories=True)
2729
commit = repository.head.commit
2830
if uncommitted_changes:
@@ -117,30 +119,31 @@ def confirm_proceeding_with_no_git_repo() -> str | bool:
117119
return True
118120

119121

120-
def check_and_push_branch(repo: git.Repo, git_remote: str | None = "origin", wait_for_push: bool = False) -> bool: # noqa: FBT001, FBT002
121-
current_branch = repo.active_branch.name
122+
def check_and_push_branch(repo: git.Repo, git_remote: str | None = "origin", *, wait_for_push: bool = False) -> bool:
123+
current_branch = repo.active_branch
124+
current_branch_name = current_branch.name
122125
remote = repo.remote(name=git_remote)
123126

124127
# Check if the branch is pushed
125-
if f"{git_remote}/{current_branch}" not in repo.refs:
126-
logger.warning(f"⚠️ The branch '{current_branch}' is not pushed to the remote repository.")
128+
if f"{git_remote}/{current_branch_name}" not in repo.refs:
129+
logger.warning(f"⚠️ The branch '{current_branch_name}' is not pushed to the remote repository.")
127130
if not sys.__stdin__.isatty():
128131
logger.warning("Non-interactive shell detected. Branch will not be pushed.")
129132
return False
130133
if sys.__stdin__.isatty() and Confirm.ask(
131134
f"⚡️ In order for me to create PRs, your current branch needs to be pushed. Do you want to push "
132-
f"the branch '{current_branch}' to the remote repository?",
135+
f"the branch '{current_branch_name}' to the remote repository?",
133136
default=False,
134137
):
135138
remote.push(current_branch)
136-
logger.info(f"⬆️ Branch '{current_branch}' has been pushed to {git_remote}.")
139+
logger.info(f"⬆️ Branch '{current_branch_name}' has been pushed to {git_remote}.")
137140
if wait_for_push:
138141
time.sleep(3) # adding this to give time for the push to register with GitHub,
139142
# so that our modifications to it are not rejected
140143
return True
141-
logger.info(f"🔘 Branch '{current_branch}' has not been pushed to {git_remote}.")
144+
logger.info(f"🔘 Branch '{current_branch_name}' has not been pushed to {git_remote}.")
142145
return False
143-
logger.debug(f"The branch '{current_branch}' is present in the remote repository.")
146+
logger.debug(f"The branch '{current_branch_name}' is present in the remote repository.")
144147
return True
145148

146149

0 commit comments

Comments
 (0)