@@ -94,27 +94,59 @@ def checkout_repo(name, url, ref, path):
9494 print (f" Detected commit hash. Cloning and then checking out." )
9595
9696 # Clone the repository
97- subprocess .run (["git" , "clone" , auth_url , path ], check = True , capture_output = True )
97+ result = subprocess .run (
98+ ["git" , "clone" , auth_url , path ],
99+ capture_output = True ,
100+ text = True
101+ )
102+ if result .returncode != 0 :
103+ print (f" Git error: { result .stderr } " , file = sys .stderr )
104+ raise subprocess .CalledProcessError (result .returncode , result .args , result .stdout , result .stderr )
98105
99106 # Checkout specific commit
100- subprocess .run (["git" , "-C" , path , "checkout" , ref ], check = True , capture_output = True )
107+ result = subprocess .run (
108+ ["git" , "-C" , path , "checkout" , ref ],
109+ capture_output = True ,
110+ text = True
111+ )
112+ if result .returncode != 0 :
113+ print (f" Git error: { result .stderr } " , file = sys .stderr )
114+ raise subprocess .CalledProcessError (result .returncode , result .args , result .stdout , result .stderr )
101115 else :
102116 print (f"Checking out { name } ({ ref } ) to { path } " )
103117 print (f" Detected branch/tag. Cloning with --branch." )
104118
105119 # Clone with shallow copy and specific branch/tag
106- # Add 'v' prefix if not already present (common convention)
107- branch_ref = ref if ref .startswith ("v" ) else f"v{ ref } "
108- subprocess .run (
109- ["git" , "clone" , "--depth" , "1" , "--branch" , branch_ref , auth_url , path ],
110- check = True ,
120+ # Try the ref as-is first
121+ result = subprocess .run (
122+ ["git" , "clone" , "--depth" , "1" , "--branch" , ref , auth_url , path ],
111123 capture_output = True ,
124+ text = True ,
112125 )
113126
127+ if result .returncode != 0 :
128+ # If failed, try with 'v' prefix (common for version tags)
129+ if not ref .startswith ("v" ) and re .match (r"^\d+\.\d+" , ref ):
130+ print (f" First attempt failed, retrying with 'v' prefix for version tag..." )
131+ branch_ref = f"v{ ref } "
132+ result = subprocess .run (
133+ ["git" , "clone" , "--depth" , "1" , "--branch" , branch_ref , auth_url , path ],
134+ capture_output = True ,
135+ text = True ,
136+ )
137+ if result .returncode != 0 :
138+ print (f" Git error: { result .stderr } " , file = sys .stderr )
139+ raise subprocess .CalledProcessError (result .returncode , result .args , result .stdout , result .stderr )
140+ else :
141+ print (f" Git error: { result .stderr } " , file = sys .stderr )
142+ raise subprocess .CalledProcessError (result .returncode , result .args , result .stdout , result .stderr )
143+
114144 return True
115145
116146 except subprocess .CalledProcessError as e :
117147 print (f"Error: Failed to checkout { name } : { e } " , file = sys .stderr )
148+ if hasattr (e , 'stderr' ) and e .stderr :
149+ print (f" Details: { e .stderr } " , file = sys .stderr )
118150 return False
119151
120152
0 commit comments