def resolve_repo_dir(template): """ Determine path to local repository based on template name. This can be either a local path, a remote URL or a remote alias such as for Github. Sundry bits from Cookiecutter do the heavy lifting here. Arguments template [path|url|alias] """ cc_home = DEFAULT_CONFIG['cookiecutters_dir'] if template_type(template) in ['remote alias', 'url']: raw_url = expand_abbreviations(template, BUILTIN_ABBREVIATIONS) repo_type, repo_url = identify_repo(raw_url) repo_url = repo_url.rstrip('/') tail = os.path.split(repo_url)[1] if repo_type == 'git': repo_dir = os.path.normpath( os.path.join(cc_home, tail.rsplit('.git')[0])) elif repo_type == 'hg': repo_dir = os.path.normpath(os.path.join(cc_home, tail)) repo_dir = template else: repo_dir = os.path.abspath(template) return repo_dir
def test_identify_known_repo(repo_url, exp_repo_type, exp_repo_url): """Verify different correct repositories url syntax is correctly transformed.""" assert vcs.identify_repo(repo_url) == (exp_repo_type, exp_repo_url)
def test_identify_hg_mercurial(self): repo_url = "https://[email protected]/audreyr/cookiecutter-bitbucket" self.assertEqual(vcs.identify_repo(repo_url), "hg")
def test_identify_git_gitorious(self): repo_url = "[email protected]:cookiecutter-gitorious/cookiecutter-gitorious.git" self.assertEqual(vcs.identify_repo(repo_url), "git")
def test_identify_git_github_no_extension(self): repo_url = "https://github.com/audreyr/cookiecutter-pypackage" self.assertEqual(vcs.identify_repo(repo_url), "git")
def test_identify_git_github_no_extension(): repo_url = 'https://github.com/audreyr/cookiecutter-pypackage' assert vcs.identify_repo(repo_url)[0] == 'git'
def test_identify_known_repo(repo_url, exp_repo_type, exp_repo_url): assert vcs.identify_repo(repo_url) == (exp_repo_type, exp_repo_url)
def test_identify_git_gitorious(): repo_url = ( '[email protected]:cookiecutter-gitorious/cookiecutter-gitorious.git' ) assert vcs.identify_repo(repo_url)[0] == 'git'
def test_identify_git_github(): repo_url = "https://github.com/audreyr/cookiecutter-pypackage.git" assert vcs.identify_repo(repo_url)[0] == "git"
def test_unknown_repo_type(): repo_url = 'http://norepotypespecified.com' with pytest.raises(exceptions.UnknownRepoType): vcs.identify_repo(repo_url)[0]
def test_identify_hg_mercurial(): repo_url = 'https://[email protected]/audreyr/cookiecutter-bitbucket' assert vcs.identify_repo(repo_url)[0] == 'hg'
def test_identify_git_gitorious(): repo_url = ( '[email protected]:cookiecutter-gitorious/cookiecutter-gitorious.git') assert vcs.identify_repo(repo_url)[0] == 'git'
def test_identify_raise_on_unknown_repo(unknown_repo_type_url): """Verify different incorrect repositories url syntax trigger error raising.""" with pytest.raises(exceptions.UnknownRepoType): vcs.identify_repo(unknown_repo_type_url)
def test_identify_raise_on_unknown_repo(unknown_repo_type_url): with pytest.raises(exceptions.UnknownRepoType): vcs.identify_repo(unknown_repo_type_url)
def test_identify_git_github(self): repo_url = "git+https://github.com/audreyr/cookiecutter-pypackage.git" self.assertEqual(vcs.identify_repo(repo_url), "git")