|
22 | 22 | from git import Repo |
23 | 23 |
|
24 | 24 |
|
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() |
26 | 28 | repository = git.Repo(repo_directory, search_parent_directories=True) |
27 | 29 | commit = repository.head.commit |
28 | 30 | if uncommitted_changes: |
@@ -117,30 +119,31 @@ def confirm_proceeding_with_no_git_repo() -> str | bool: |
117 | 119 | return True |
118 | 120 |
|
119 | 121 |
|
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 |
122 | 125 | remote = repo.remote(name=git_remote) |
123 | 126 |
|
124 | 127 | # 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.") |
127 | 130 | if not sys.__stdin__.isatty(): |
128 | 131 | logger.warning("Non-interactive shell detected. Branch will not be pushed.") |
129 | 132 | return False |
130 | 133 | if sys.__stdin__.isatty() and Confirm.ask( |
131 | 134 | 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?", |
133 | 136 | default=False, |
134 | 137 | ): |
135 | 138 | 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}.") |
137 | 140 | if wait_for_push: |
138 | 141 | time.sleep(3) # adding this to give time for the push to register with GitHub, |
139 | 142 | # so that our modifications to it are not rejected |
140 | 143 | 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}.") |
142 | 145 | 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.") |
144 | 147 | return True |
145 | 148 |
|
146 | 149 |
|
|
0 commit comments