@@ -1806,6 +1806,19 @@ def _verify_branch_exists(self, branch_name: str, repo_path: Path) -> bool:
18061806 try :
18071807 import subprocess
18081808
1809+ # Use git show-ref for more reliable branch checking
1810+ result = subprocess .run (
1811+ ["git" , "show-ref" , "--verify" , "--quiet" , f"refs/heads/{ branch_name } " ],
1812+ cwd = repo_path ,
1813+ capture_output = True ,
1814+ text = True ,
1815+ timeout = 5 ,
1816+ check = False ,
1817+ )
1818+ if result .returncode == 0 :
1819+ return True
1820+
1821+ # Fallback: check using git branch --list (for compatibility)
18091822 result = subprocess .run (
18101823 ["git" , "branch" , "--list" , branch_name ],
18111824 cwd = repo_path ,
@@ -1815,8 +1828,17 @@ def _verify_branch_exists(self, branch_name: str, repo_path: Path) -> bool:
18151828 check = False ,
18161829 )
18171830 # Check if branch exists locally
1818- if result .returncode == 0 :
1819- branches = [line .strip ().replace ("*" , "" ).strip () for line in result .stdout .split ("\n " ) if line .strip ()]
1831+ if result .returncode == 0 and result .stdout .strip ():
1832+ # Parse branch names from output (handles both "* branch" and " branch" formats)
1833+ branches = []
1834+ for line in result .stdout .split ("\n " ):
1835+ line = line .strip ()
1836+ if line :
1837+ # Remove asterisk and any leading/trailing whitespace
1838+ branch = line .replace ("*" , "" ).strip ()
1839+ if branch :
1840+ branches .append (branch )
1841+ # Check if exact branch name matches (after normalization)
18201842 if branch_name in branches :
18211843 return True
18221844
@@ -1829,7 +1851,7 @@ def _verify_branch_exists(self, branch_name: str, repo_path: Path) -> bool:
18291851 timeout = 5 ,
18301852 check = False ,
18311853 )
1832- if result .returncode == 0 :
1854+ if result .returncode == 0 and result . stdout . strip () :
18331855 # Extract branch name from remote branch format
18341856 remote_branches = []
18351857 for line in result .stdout .split ("\n " ):
0 commit comments