@@ -80,6 +80,11 @@ def get_current_branch(repo: Repo | None = None) -> str:
8080
8181def get_remote_url (repo : Repo | None = None , git_remote : str | None = "origin" ) -> str :
8282 repository : Repo = repo if repo else git .Repo (search_parent_directories = True )
83+ available_remotes = get_git_remotes (repository )
84+ if not available_remotes :
85+ raise ValueError (f"No git remotes configured in this repository" )
86+ if git_remote not in available_remotes :
87+ raise ValueError (f"Git remote '{ git_remote } ' does not exist. Available remotes: { ', ' .join (available_remotes )} " )
8388 return repository .remote (name = git_remote ).url
8489
8590
@@ -128,6 +133,30 @@ def confirm_proceeding_with_no_git_repo() -> str | bool:
128133def check_and_push_branch (repo : git .Repo , git_remote : str | None = "origin" , * , wait_for_push : bool = False ) -> bool :
129134 current_branch = repo .active_branch
130135 current_branch_name = current_branch .name
136+ available_remotes = get_git_remotes (repo )
137+ if not available_remotes :
138+ logger .error (
139+ f"❌ No git remotes configured in this repository.\n "
140+ f"This appears to be a local-only git repository. To use codeflash with PR features, you need to:\n "
141+ f" 1. Create a repository on GitHub (or another git hosting service)\n "
142+ f" 2. Add it as a remote: git remote add origin <repository-url>\n "
143+ f" 3. Push your branch: git push -u origin { current_branch_name } \n \n "
144+ f"Alternatively, you can run codeflash with the '--no-pr' flag to optimize locally without creating PRs."
145+ )
146+ return False
147+
148+ # Check if the specified remote exists
149+ if git_remote not in available_remotes :
150+ logger .error (
151+ f"❌ Git remote '{ git_remote } ' does not exist in this repository.\n "
152+ f"Available remotes: { ', ' .join (available_remotes )} \n \n "
153+ f"You can either:\n "
154+ f" 1. Use one of the existing remotes by setting 'git-remote' in pyproject.toml\n "
155+ f" 2. Add the '{ git_remote } ' remote: git remote add { git_remote } <repository-url>\n "
156+ f" 3. Run codeflash with '--no-pr' to optimize locally without creating PRs."
157+ )
158+ return False
159+
131160 remote = repo .remote (name = git_remote )
132161
133162 # Check if the branch is pushed
0 commit comments