@@ -249,25 +249,29 @@ def project_root_from_module_root(module_root: Path, pyproject_file_path: Path)
249249
250250
251251def handle_optimize_all_arg_parsing (args : Namespace ) -> Namespace :
252- if hasattr (args , "all" ):
253- import git
254-
255- from codeflash .code_utils .git_utils import check_and_push_branch , get_repo_owner_and_name
256- from codeflash .code_utils .github_utils import require_github_app_or_exit
257-
258- # Ensure that the user can actually open PRs on the repo.
259- try :
260- git_repo = git .Repo (search_parent_directories = True )
261- except git .exc .InvalidGitRepositoryError :
262- logger .exception (
263- "I couldn't find a git repository in the current directory. "
264- "I need a git repository to run --all and open PRs for optimizations. Exiting..."
265- )
266- apologize_and_exit ()
267- if not args .no_pr and not check_and_push_branch (git_repo , git_remote = args .git_remote ):
268- exit_with_message ("Branch is not pushed..." , error_on_exit = True )
269- owner , repo = get_repo_owner_and_name (git_repo )
270- if not args .no_pr :
252+ if hasattr (args , "all" ) or (hasattr (args , "file" ) and args .file ):
253+ no_pr = getattr (args , "no_pr" , False )
254+
255+ if not no_pr :
256+ import git
257+
258+ from codeflash .code_utils .git_utils import check_and_push_branch , get_repo_owner_and_name
259+ from codeflash .code_utils .github_utils import require_github_app_or_exit
260+
261+ # Ensure that the user can actually open PRs on the repo.
262+ try :
263+ git_repo = git .Repo (search_parent_directories = True )
264+ except git .exc .InvalidGitRepositoryError :
265+ mode = "--all" if hasattr (args , "all" ) else "--file"
266+ logger .exception (
267+ f"I couldn't find a git repository in the current directory. "
268+ f"I need a git repository to run { mode } and open PRs for optimizations. Exiting..."
269+ )
270+ apologize_and_exit ()
271+ git_remote = getattr (args , "git_remote" , None )
272+ if not check_and_push_branch (git_repo , git_remote = git_remote ):
273+ exit_with_message ("Branch is not pushed..." , error_on_exit = True )
274+ owner , repo = get_repo_owner_and_name (git_repo )
271275 require_github_app_or_exit (owner , repo )
272276 if not hasattr (args , "all" ):
273277 args .all = None
0 commit comments