Merge ~bjornt/gitlptools:fix-lp-propose into ~ubuntuone-hackers/gitlptools:master

Proposed by Björn Tillenius
Status: Merged
Merged at revision: dc528fcac0819424cc16300dababa0ec8a9a65b9
Proposed branch: ~bjornt/gitlptools:fix-lp-propose
Merge into: ~ubuntuone-hackers/gitlptools:master
Diff against target: 88 lines (+39/-2)
3 files modified
README.md (+17/-0)
src/gitlptools/__init__.py (+11/-2)
tests/test_gitlptools.py (+11/-0)
Reviewer Review Type Date Requested Status
Ubuntu One hackers Pending
Review via email: mp+345749@code.launchpad.net

Commit message

Handle git+ssh URLs when getting the merge target.

To post a comment you must log in.
Revision history for this message
Björn Tillenius (bjornt) wrote :

I also added docs for how to set up the development environment, since I always have trouble with that.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/README.md b/README.md
2index 95f7991..9c04786 100644
3--- a/README.md
4+++ b/README.md
5@@ -34,3 +34,20 @@ Note that in order for lp-open to work you need to install
6 snapd-xdg-open:
7
8 $ sudo apt install snapd-xdg-open
9+
10+
11+Hacking
12+-------
13+
14+Follow these steps if you want to set up an environment so that you can
15+hack on gitlptools:
16+
17+ $ sudo apt install python3-venv python3-secretstorage python3-crypto
18+ $ python3 -m venv --system-site-package .ve
19+ $ .ve/bin/pip install setuptools==27.3
20+ $ .ve/bin/pip install pytest
21+ $ .ve/bin/python3 setup.py develop
22+
23+You can now run the tests:
24+
25+ $ .ve/bin/pytest tests
26diff --git a/src/gitlptools/__init__.py b/src/gitlptools/__init__.py
27index 6a7442d..8314331 100644
28--- a/src/gitlptools/__init__.py
29+++ b/src/gitlptools/__init__.py
30@@ -71,7 +71,7 @@ class LPGitRef:
31
32 @property
33 def lp_path(self):
34- return urlsplit(self.remote.url).path.lstrip('/')
35+ return get_launchpad_path(self.remote.url)
36
37 @property
38 def lp_branch_name(self):
39@@ -99,6 +99,14 @@ class LPGitRef:
40 return candidates.pop()
41
42
43+def get_launchpad_path(remote_url):
44+ """Return the expected path in Launchpad given a remote URL.
45+
46+ The URL is expected to be either in for form of git_ssh:// or lp:
47+ """
48+ return urlsplit(remote_url).path.lstrip('/')
49+
50+
51 def get_launchpad_branch(lp, repo):
52 """Get the LP branch for the currently active branch in the repo."""
53 this_branch = repo.active_branch
54@@ -282,10 +290,11 @@ def get_merge_target(git_repo, target):
55 remote, branch = target, 'master'
56
57 try:
58- repo = git_repo.remotes[remote].url.lstrip('lp:')
59+ remote = git_repo.remotes[remote]
60 except KeyError:
61 raise InvalidMergeTarget('Unknown target remote')
62
63+ repo = get_launchpad_path(remote.url)
64 return MergeTarget(repo, branch)
65
66
67diff --git a/tests/test_gitlptools.py b/tests/test_gitlptools.py
68index 81c849f..266b94f 100644
69--- a/tests/test_gitlptools.py
70+++ b/tests/test_gitlptools.py
71@@ -113,6 +113,17 @@ def test_merge_target_remote_default_branch():
72 assert merge_target.branch == 'master'
73
74
75+def test_merge_target_remote_git_ssh():
76+ # a MergeTarget with the remote is returned
77+ git_repo = Mock(
78+ remotes={
79+ 'upstream': Mock(
80+ url='git+ssh://user@git.launchpad.net/~user/+git/testrepo')})
81+ merge_target = get_merge_target(git_repo, "upstream/master")
82+ assert merge_target.repo == '~user/+git/testrepo'
83+ assert merge_target.branch == 'master'
84+
85+
86 def test_merge_target_malformed():
87 # an error is raised if the target repo is malformed
88 git_repo = Mock(

Subscribers

People subscribed via source and target branches