@@ -87,42 +87,54 @@ def branch_exists(self, branch):
8787 This checks to make sure the branch we are told to access
8888 exists in the repo
8989 """
90- p_heads = subprocess .run (
91- ["git" , "ls-remote" , "--heads" , self .git_url ],
92- capture_output = True ,
93- text = True ,
94- )
95- p_tags = subprocess .run (
96- ["git" , "ls-remote" , "--tags" , self .git_url ],
97- capture_output = True ,
98- text = True ,
99- )
100- lines = p_heads .stdout .splitlines () + p_tags .stdout .splitlines ()
101- branches = []
102- for line in lines :
103- _ , ref = line .split ()
104- refs , heads , branch_name = ref .split ("/" , 2 )
105- branches .append (branch_name )
106- return branch in branches
90+ try :
91+ heads = subprocess .run (
92+ ["git" , "ls-remote" , "--heads" , self .git_url ],
93+ capture_output = True ,
94+ text = True ,
95+ check = True
96+ )
97+ tags = subprocess .run (
98+ ["git" , "ls-remote" , "--tags" , self .git_url ],
99+ capture_output = True ,
100+ text = True ,
101+ check = True
102+ )
103+ lines = heads .stdout .splitlines () + tags .stdout .splitlines ()
104+ branches = []
105+ for line in lines :
106+ _ , ref = line .split ()
107+ refs , heads , branch_name = ref .split ("/" , 2 )
108+ branches .append (branch_name )
109+ return branch in branches
110+ except subprocess .CalledProcessError :
111+ m = f"Problem accessing list of branches and/or tags: { self .git_url } "
112+ logging .exception (m )
113+ raise ValueError (m )
107114
108115 def resolve_default_branch (self ):
109116 """
110117 This will resolve the default branch of the repo in
111118 the case where the branch given does not exist
112119 """
113- p = subprocess .run (
114- ["git" , "ls-remote" , "--symref" , self .git_url , "HEAD" ],
115- capture_output = True ,
116- text = True ,
117- )
118-
119- for line in p .stdout .splitlines ():
120- if line .startswith ("ref:" ):
121- # line resembles --> ref: refs/heads/main HEAD
122- _ , ref , head = line .split ()
123- refs , heads , branch_name = ref .split ("/" , 2 )
124- return branch_name
125- raise ValueError (f"default branch not found in { self .git_url } " )
120+ try :
121+ head_branch = subprocess .run (
122+ ["git" , "ls-remote" , "--symref" , self .git_url , "HEAD" ],
123+ capture_output = True ,
124+ text = True ,
125+ check = True
126+ )
127+ for line in head_branch .stdout .splitlines ():
128+ if line .startswith ("ref:" ):
129+ # line resembles --> ref: refs/heads/main HEAD
130+ _ , ref , head = line .split ()
131+ refs , heads , branch_name = ref .split ("/" , 2 )
132+ return branch_name
133+ raise ValueError (f"default branch not found in { self .git_url } " )
134+ except subprocess .CalledProcessError :
135+ m = f"Problem accessing HEAD branch: { self .git_url } "
136+ logging .exception (m )
137+ raise ValueError (m )
126138
127139 def pull (self ):
128140 """
0 commit comments