def __stash_pop(git_repo): """Stash pop if automatic stash is in stash list""" try: if 'Automatic stash' in git_repo.git.stash('list'): asd = git_repo.git.stash('pop') if 'error: could not restore untracked files from stash' in asd: raise exc.GitCommandError(asd) except exc.GitCommandError as error: print("Error: %s" % error) raise error
def test_cached_template_offline(create_command, myapp, capsys): """If the user is offline, a cached template won't be updated, but will still work.""" mock_repo = mock.MagicMock() mock_remote = mock.MagicMock() mock_remote_head = mock.MagicMock() # Git returns a Repo, that repo can return a remote, and it has # heads that can be accessed. However, calling fetch on the remote # will cause a git error (error code 128). create_command.git.Repo.return_value = mock_repo mock_repo.remote.return_value = mock_remote mock_remote.refs.__getitem__.return_value = mock_remote_head mock_remote.fetch.side_effect = git_exceptions.GitCommandError("git", 128) # Generate the template. create_command.generate_app_template(myapp) # An attempt to fetch the repo origin was made mock_repo.remote.assert_called_once_with(name="origin") mock_remote.fetch.assert_called_once_with() # A warning was raised to the user about the fetch problem output = capsys.readouterr().out assert "** WARNING: Unable to update template" in output # The remote head was checked out. mock_remote_head.checkout.assert_called_once_with() # App's config template hasn't changed assert (myapp.template == "https://github.com/beeware/briefcase-tester-dummy-template.git") # Cookiecutter was invoked with the path to the *cached* template name create_command.cookiecutter.assert_called_once_with( os.fsdecode(Path.home() / ".cookiecutters" / "briefcase-tester-dummy-template"), no_input=True, checkout=create_command.python_version_tag, output_dir=os.fsdecode(create_command.platform_path), extra_context=full_context({ "template": "https://github.com/beeware/briefcase-tester-dummy-template.git", "template_branch": "3.X", }), )
def test_offline_repo_template(base_command, mock_git): """If the user is offline the first time a repo template is requested, an error is raised.""" base_command.git = mock_git mock_repo = mock.MagicMock() mock_remote = mock.MagicMock() mock_remote_head = mock.MagicMock() # Git returns a Repo, that repo can return a remote, and it has # heads that can be accessed. However, calling fetch on the remote # will cause a git error (error code 128). base_command.git.Repo.return_value = mock_repo mock_repo.remote.return_value = mock_remote mock_remote.refs.__getitem__.return_value = mock_remote_head mock_remote.fetch.side_effect = git_exceptions.GitCommandError("git", 128) cached_path = cookiecutter_cache_path( "https://example.com/magic/special-template.git" ) # Update the cache cached_template = base_command.update_cookiecutter_cache( template="https://example.com/magic/special-template.git", branch="special" ) # The cookiecutter cache location will be interrogated. base_command.git.Repo.assert_called_once_with(cached_path) # The origin of the repo was fetched mock_repo.remote.assert_called_once_with(name="origin") mock_remote.fetch.assert_called_once_with() # The right branch was accessed mock_remote.refs.__getitem__.assert_called_once_with("special") # The remote head was checked out. mock_remote_head.checkout.assert_called_once_with() # The template that will be used is the original URL assert cached_template == cached_path