1414
1515import yaml
1616
17+ REPO_LINK = 'https://github.com/ros-infrastructure/vcs2l.git'
18+
1719
1820def to_file_url (path ):
1921 return urljoin ('file:' , pathname2url (path ))
@@ -30,7 +32,29 @@ def setup_git_repository(temp_dir):
3032 repo_root = os .path .dirname (os .path .dirname (__file__ ))
3133 gitrepo_path = os .path .join (temp_dir .name , 'gitrepo' )
3234
33- subprocess .check_call (['git' , 'clone' , '--branch' , 'main' , repo_root , gitrepo_path ])
35+ commits_count = int (
36+ subprocess .check_output (
37+ ['git' , 'rev-list' , '--count' , 'HEAD' ], cwd = repo_root
38+ ).strip ()
39+ )
40+
41+ if commits_count == 1 :
42+ repo_root = REPO_LINK # codecov sparsely clones the repo
43+
44+ subprocess .check_call (['git' , 'clone' , repo_root , gitrepo_path ])
45+ try :
46+ subprocess .check_call (['git' , 'checkout' , 'main' ], cwd = gitrepo_path )
47+ except subprocess .CalledProcessError :
48+ branch_names = subprocess .check_output (
49+ ['git' , 'branch' , '-a' ], cwd = gitrepo_path
50+ ).decode ('utf-8' )
51+
52+ print ('Available branches:\n ' , branch_names )
53+
54+ # Create branch named 'main' if CI cannot checkout main directly
55+ subprocess .check_call (
56+ ['git' , 'checkout' , '-b' , 'main' ], cwd = gitrepo_path
57+ )
3458
3559 return gitrepo_path
3660
0 commit comments