def setUp(self) -> None: self.github_host = github.GithubHost( typedefs.GitConfig('', 'master'), 'albertyw', 'git-browse', ) self.repository_url = 'https://github.com/albertyw/git-browse' self.focus_object = typedefs.FocusObject('/') self.focus_hash = typedefs.FocusHash(test_util.get_tag())
def setUp(self) -> None: self.host = bitbucket.BitbucketHost( typedefs.GitConfig('', 'master'), 'albertyw', 'git-browse', ) self.repository_url = 'https://bitbucket.org/albertyw/git-browse' self.focus_object = typedefs.FocusObject('/') self.focus_hash = typedefs.FocusHash(test_util.get_tag())
def get_git_config_data(git_config_file: pathlib.Path) -> typedefs.GitConfig: # strict is removed here because gitconfig allows for multiple "fetch" keys config = configparser.ConfigParser(strict=False) config.read(git_config_file) try: git_url = config['remote "origin"']['url'] except KeyError: raise RuntimeError("git config file not parseable") branches = [b for b in config.keys() if 'branch "' in b] branches = [b.lstrip('branch "').rstrip('"') for b in branches] default_branch = 'master' if 'master' not in branches: if 'main' in branches: default_branch = 'main' elif branches: default_branch = branches[0] git_config = typedefs.GitConfig(git_url, default_branch) return git_config
def test_create(self) -> None: repo = '[email protected]:a/b' git_config = typedefs.GitConfig(repo, 'master') git_config.try_url_match(phabricator.UBER_SSH_GITOLITE_URL) with patch('git_browse.browse.get_repository_root') as mock_root: mock_root.return_value = self.temp_dir_name host = phabricator.PhabricatorHost.create(git_config) phabricator_host = cast(phabricator.PhabricatorHost, host) self.assertEqual( phabricator_host.phabricator_url, self.phabricator_url, ) self.assertEqual( phabricator_host.repository_callsign, self.repository_callsign, ) self.assertEqual( phabricator_host.default_branch, self.default_branch, )
def test_create_dot_git(self) -> None: repo = '[email protected]:a/b.git' git_config = typedefs.GitConfig(repo, 'master') git_config.try_url_match(phabricator.UBER_SSH_GITOLITE_URL) obj = sourcegraph.SourcegraphHost.create(git_config) self.assertEqual(obj.repository, 'a/b')
def test_init(self) -> None: git_config = typedefs.GitConfig('', 'master') host = github.GithubHost(git_config, 'user', 'repository') self.assertEqual(host.git_config, git_config) self.assertEqual(host.user, 'user') self.assertEqual(host.repository, 'repository')