@@ -334,9 +334,21 @@ def get_git_show_ref_shasum(branch_name, the_path):
334334 `head -n 1` is to get the first element in the list
335335 """
336336
337+ # Try the branch name as-is first (works for local branches and remote branches)
337338 proc_git_show_ref = subprocess .run (
338- ['git' , 'show-ref' , branch_name ], cwd = the_path , stdout = subprocess .PIPE
339+ ['git' , 'show-ref' , branch_name ],
340+ cwd = the_path ,
341+ capture_output = True ,
339342 )
343+
344+ # If that fails, try with 'origin/' prefix (for remote branches in cloned repos)
345+ if proc_git_show_ref .returncode != 0 and not branch_name .startswith ('origin/' ):
346+ proc_git_show_ref = subprocess .run (
347+ ['git' , 'show-ref' , 'origin/' + branch_name ],
348+ cwd = the_path ,
349+ capture_output = True ,
350+ )
351+
340352 proc_git_show_ref .check_returncode ()
341353 msg = proc_git_show_ref .stdout .decode ('utf-8' )
342354 # `msg.split()`: # split by space and '\n'
@@ -362,6 +374,7 @@ def get_results_branches(ria_directory):
362374 path to the git (or datalad) repository
363375
364376 """
377+ # Try local branches first
365378 branch_output = subprocess .run (
366379 ['git' , 'branch' , '--list' ],
367380 cwd = ria_directory ,
@@ -370,13 +383,50 @@ def get_results_branches(ria_directory):
370383 )
371384
372385 # Filter to just branches starting with 'job-'
386+ # Handle empty output: if stdout is empty, split('\n') returns [''] which we filter out
387+ branch_lines = branch_output .stdout .strip ().split ('\n ' ) if branch_output .stdout .strip () else []
373388 branches = [
374389 # Remove leading and trailing asterisks and spaces
375390 b .strip ().replace ('* ' , '' )
376- for b in branch_output . stdout . strip (). split ( ' \n ' )
391+ for b in branch_lines
377392 if b .strip ().replace ('* ' , '' ).startswith ('job-' )
378393 ]
379394
395+ # If no local branches found, check if this is a cloned repository
396+ # (has 'origin' remote) and try remote branches
397+ if not branches :
398+ # Check if 'origin' remote exists (indicates a cloned repository)
399+ check_remote = subprocess .run (
400+ ['git' , 'remote' , 'show' , 'origin' ],
401+ cwd = ria_directory ,
402+ capture_output = True ,
403+ text = True ,
404+ )
405+ # Only check remote branches if 'origin' remote exists
406+ # (this indicates it's a cloned repo like merge_ds, not the original RIA)
407+ if check_remote .returncode == 0 :
408+ branch_output_remote = subprocess .run (
409+ ['git' , 'branch' , '-r' , '--list' ],
410+ cwd = ria_directory ,
411+ capture_output = True ,
412+ text = True ,
413+ )
414+
415+ # Filter to just branches starting with 'origin/job-' and strip 'origin/' prefix
416+ # Handle empty output: if stdout is empty, split('\n') returns [''] which we filter out
417+ remote_branch_lines = (
418+ branch_output_remote .stdout .strip ().split ('\n ' )
419+ if branch_output_remote .stdout .strip ()
420+ else []
421+ )
422+ remote_branches = [
423+ # Remove leading and trailing asterisks and spaces, then strip 'origin/' prefix
424+ b .strip ().replace ('* ' , '' ).replace ('origin/' , '' )
425+ for b in remote_branch_lines
426+ if b .strip ().replace ('* ' , '' ).startswith ('origin/job-' )
427+ ]
428+ branches = remote_branches
429+
380430 return branches
381431
382432
0 commit comments