Skip to content

Commit

Permalink
Correctly trim git+ from remotes with git+https
Browse files Browse the repository at this point in the history
Adds tests

Fixes #14
  • Loading branch information
tony committed Jan 27, 2016
1 parent 4ae1e30 commit d189652
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
6 changes: 6 additions & 0 deletions vcspull/repo/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,18 @@ def remote_set(self, cwd=None, name='origin', url=None, user=None):
Run git as a user other than what the minion runs as
"""

# See #14, only use http/https prefix on remotes
# However, git+ssh:// is works fine as remote url
if url.startswith('git+http'):
url = url.replace('git+', '')
if not cwd:
cwd = self['path']
if self.remote_get(cwd, name):
cmd = 'git remote rm {0}'.format(name)
_git_run(cmd, cwd=cwd, runas=user)
cmd = 'git remote add {0} {1}'.format(name, url)

_git_run(cmd, cwd=cwd, runas=user)
return self.remote_get(cwd=cwd, remote=name, user=None)

Expand Down
43 changes: 43 additions & 0 deletions vcspull/testsuite/repo_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,49 @@ def test_remotes(self):
git_repo.obtain(quiet=True)
self.assertIn('myrepo', git_repo.remotes_get())

def test_remotes_vcs_prefix(self):
repo_dir, git_repo = self.create_git_repo(create_repo=True)

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

remote_url = 'https://localhost/my/git/repo.git'
remote_vcs_url = 'git+' + remote_url

git_repo = Repo(**{
'url': 'git+file://' + git_checkout_dest,
'cwd': os.path.dirname(repo_dir),
'name': os.path.basename(os.path.normpath(repo_dir)),
'remotes': [{
'remote_name': 'myrepo',
'url': remote_vcs_url
}]
})

git_repo.obtain(quiet=True)
self.assertIn((remote_url, remote_url,),
git_repo.remotes_get().values())

def test_remotes_preserves_git_ssh(self):
# Regression test for #14
repo_dir, git_repo = self.create_git_repo(create_repo=True)

git_checkout_dest = os.path.join(self.TMP_DIR, 'dontmatta')
remote_url = 'git+ssh://git@github.com/tony/AlgoXY.git'

git_repo = Repo(**{
'url': 'git+file://' + git_checkout_dest,
'cwd': os.path.dirname(repo_dir),
'name': os.path.basename(os.path.normpath(repo_dir)),
'remotes': [{
'remote_name': 'myrepo',
'url': remote_url
}]
})

git_repo.obtain(quiet=True)
self.assertIn((remote_url, remote_url,),
git_repo.remotes_get().values())


class GitRepoSSHUrl(RepoTestMixin, ConfigTestCase, unittest.TestCase):

Expand Down

0 comments on commit d189652

Please sign in to comment.