Skip to content

Commit

Permalink
Raise exception if using improper github private tracker urls
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Mar 25, 2015
1 parent eb8ef2a commit b7108bd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ CURRENT
- [cli]: ``-r`` / ``--repomatch`` for matching directories, accepts
`fnmatch`_ \'s.
- [cli]: ``-c`` / ``--config`` YAML / JSON file of repositories
- [config/vcs]: Exception for private / ssh GitHub repository URLs and
message to change to correct format.

0.0.8.4
-------
Expand Down
20 changes: 15 additions & 5 deletions vcspull/repo/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __init__(self, arguments, *args, **kwargs):

BaseRepo.__init__(self, arguments, *args, **kwargs)

self['remotes']= arguments['remotes'] if 'remotes' in arguments else []
self['remotes'] = arguments['remotes'] if 'remotes' in arguments else []

def get_revision(self):
current_rev = run(
Expand All @@ -130,11 +130,19 @@ def get_url_rev(self):
work with a ssh:// scheme (e.g. Github). But we need a scheme for
parsing. Hence we remove it again afterwards and return it as a stub.
"""
if not '://' in self['url']:
assert not 'file:' in self['url']
if '://' not in self['url']:
assert 'file:' not in self['url']
self.url = self.url.replace('git+', 'git+ssh://')
self.info(self.url)
url, rev = super(GitRepo, self).get_url_rev()
url = url.replace('ssh://', '')
elif 'github.com:' in self['url']:
raise exc.PullvException(
"Repo %s is malformatted, please use the convention %s for"
"ssh / private GitHub repositories." % (
self['url'], "git+https://github.com/username/repo.git"
)
)
else:
url, rev = super(GitRepo, self).get_url_rev()

Expand All @@ -157,8 +165,10 @@ def get_revision(self, location=None):

def get_refs(self, location):
"""Return map of named refs (branches or tags) to commit hashes."""
output = run(['git', 'show-ref'],
show_stdout=False, cwd=location)
output = run(
['git', 'show-ref'],
show_stdout=False, cwd=location
)
rv = {}
for line in output:
commit, ref = line.split(' ', 1)
Expand Down
19 changes: 19 additions & 0 deletions vcspull/testsuite/repo_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import unittest

from .helpers import ConfigTest, RepoTest
from .. import exc
from ..repo import Repo
from ..util import run

Expand Down Expand Up @@ -86,6 +87,23 @@ def test_remotes(self):
self.assertIn('myrepo', git_repo.remotes_get())


class GitRepoSSHUrl(RepoTest):

def test_private_ssh_format(self):
repo_dir, git_repo = self.create_git_repo()

git_checkout_dest = os.path.join(self.TMP_DIR, 'private_ssh_repo')

git_repo = Repo({
'url': 'git+ssh://github.com:' + git_checkout_dest,
'parent_path': os.path.dirname(repo_dir),
'name': os.path.basename(os.path.normpath(repo_dir)),
})

with self.assertRaisesRegexp(exc.PullvException, "is malformatted"):
git_repo.obtain(quiet=True)


class TestRemoteGit(RepoTest):

def test_ls_remotes(self):
Expand Down Expand Up @@ -133,6 +151,7 @@ def test_set_remote(self):
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(GitRepoRemotes))
suite.addTest(unittest.makeSuite(GitRepoSSHUrl))
suite.addTest(unittest.makeSuite(RepoGit))
suite.addTest(unittest.makeSuite(TestRemoteGit))
return suite

0 comments on commit b7108bd

Please sign in to comment.