@@ -239,43 +239,64 @@ def test_get_upstream_branch_failure(mock_subproc_popen):
239239 process_mock = Mock (returncode = 128 )
240240 process_mock .communicate .side_effect = [
241241 ('' , "fatal: no such branch: 'blah'" .encode ('utf-8' )),
242- ('' , "fatal: no upstream configured for branch" .encode ('utf-8' ))
242+ ('' , "fatal: no upstream configured for branch" .encode ('utf-8' )),
243+ ('' , "fatal: ambiguous argument 'blah@origin': unknown revision or path not in the working tree." .encode ('utf-8' ))
243244 ]
244245 mock_subproc_popen .return_value = process_mock
245246
246- # When
247+ # When: fatal: no such branch: 'blah'
247248 with pytest .raises (Exception ) as error :
248249 Git (root_dir = '/bin' ).get_upstream_branch (
249250 current_path = 'test_curr_path' , branch_name = 'blah' )
250251
252+ # Then
253+ mock_subproc_popen .assert_has_calls ([
254+ call (
255+ ['git' , 'rev-parse' , '--abbrev-ref' ,
256+ 'blah@{upstream}' ],
257+ stdout = PIPE ,
258+ stderr = PIPE ,
259+ cwd = '/bin/test_curr_path'
260+ ),
261+ call ().communicate ()
262+ ], any_order = False )
251263 assert "Error [fatal: no such branch: 'blah'] " \
252264 "occurred while executing [git rev-parse --abbrev-ref blah@{upstream}] command to get upstream branch." == str (
253265 error .value )
254266
267+ # When: fatal: no upstream configured for branch
255268 actual_response = Git (root_dir = '/bin' ).get_upstream_branch (
256269 current_path = 'test_curr_path' , branch_name = 'test' )
257270
258- assert None == actual_response
259-
260271 # Then
261272 mock_subproc_popen .assert_has_calls ([
262273 call (
263274 ['git' , 'rev-parse' , '--abbrev-ref' ,
264- 'blah @{upstream}' ],
275+ 'test @{upstream}' ],
265276 stdout = PIPE ,
266277 stderr = PIPE ,
267278 cwd = '/bin/test_curr_path'
268279 ),
269- call ().communicate (),
280+ call ().communicate ()
281+ ], any_order = False )
282+ assert None == actual_response
283+
284+ # When: "fatal: ambiguous argument 'blah@origin': unknown revision or path not in the working tree.
285+ actual_response = Git (root_dir = '/bin' ).get_upstream_branch (
286+ current_path = 'test_curr_path' , branch_name = 'blah' )
287+
288+ # Then
289+ mock_subproc_popen .assert_has_calls ([
270290 call (
271291 ['git' , 'rev-parse' , '--abbrev-ref' ,
272- 'test @{upstream}' ],
292+ 'blah @{upstream}' ],
273293 stdout = PIPE ,
274294 stderr = PIPE ,
275295 cwd = '/bin/test_curr_path'
276296 ),
277297 call ().communicate ()
278298 ], any_order = False )
299+ assert None == actual_response
279300
280301
281302@patch ('subprocess.Popen' )
0 commit comments