@@ -156,7 +156,7 @@ def process_depth(splitted_merge, branchname, main_branch, main_branch_name, rep
156156 stdout = PIPE ,
157157 stderr = PIPE ,
158158 )
159- .stdout .decode ("utf-8" )
159+ .stderr .decode ("utf-8" )
160160 .replace ("\n " , "" )
161161 )
162162 if not lastrev :
@@ -183,6 +183,27 @@ def process_depth(splitted_merge, branchname, main_branch, main_branch_name, rep
183183 # Should log/print some error here.
184184 return 1024
185185
186+ def has_connection (remote , repo_path ):
187+ os .chdir (repo_path )
188+ import pudb
189+ pudb .set_trace ()
190+ exit_code = (
191+ run (
192+ [
193+ "git" ,
194+ "ls-remote" ,
195+ "--heads" ,
196+ "--exit-code" ,
197+ "" .join ([remote ]) ,
198+ ],
199+ stdout = PIPE ,
200+ stderr = PIPE ,
201+ )
202+ )
203+ std_error = exit_code .stderr .decode ("utf-8" ).replace ("\n " , "" )
204+ if std_error != '' :
205+ return False
206+ return True
186207def branch_exists (remote , splitted_merge , branchname , repo_path ):
187208 os .chdir (repo_path )
188209 # make sure we have the latest available.
@@ -247,8 +268,14 @@ def main():
247268 if branchname :
248269 # if branchname does not exist , comment out and do next merge
249270 remote = doc [repo ]['remotes' ][splitted_merge [0 ]]
250- exists = branch_exists (remote , splitted_merge , branchname , repo_path )
251- if not exists :
271+ # before checking if branch exists , we check if
272+ # connection is accessible. This will avoid commenting out all
273+ # merges if there is no connection or server down.
274+ connected = has_connection (remote , repo_path )
275+ exists = branch_exists (
276+ remote , splitted_merge , branchname , repo_path )
277+ if not exists and connected :
278+ # before commenting out we check connection again.
252279 # merge does not exist, comment it out and continue
253280 index = doc [repo ]['merges' ].index (merge )
254281 print ("# Removing and dumping in comment section non-existing merge %s from repo %s \n " % (doc [repo ]['merges' ][index ] , doc [repo ]))
@@ -268,7 +295,7 @@ def main():
268295
269296 # compute depth only for merges with branchname
270297 min_depth = process_depth (
271- splitted_merge ,
298+ splitted_merge ,
272299 branchname ,
273300 main_branch ,
274301 main_branch_name ,
0 commit comments