Rev 5362: (spiv) Expand lp:~/ to lp:~username/ if a user has already logged in. (John in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Jul 29 11:44:43 BST 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5362 [merge]
revision-id: pqm at pqm.ubuntu.com-20100729104442-5g1m4pumcss037ic
parent: pqm at pqm.ubuntu.com-20100726115129-2uy7vwm0v2ergzk3
parent: john at arbash-meinel.com-20100726171933-vpvt3aslqwdkcykx
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2010-07-29 11:44:42 +0100
message:
  (spiv) Expand lp:~/ to lp:~username/ if a user has already logged in. (John
   A Meinel)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/plugins/launchpad/lp_directory.py lp_indirect.py-20070126012204-de5rugwlt22c7u7e-1
  bzrlib/plugins/launchpad/test_lp_directory.py test_lp_indirect.py-20070126002743-oyle362tzv9cd8mi-1
=== modified file 'NEWS'
--- a/NEWS	2010-07-21 22:29:45 +0000
+++ b/NEWS	2010-07-26 17:19:33 +0000
@@ -25,6 +25,11 @@
 New Features
 ************
 
+* The ``lp:`` prefix will now use your known username (from
+  ``bzr launchpad-login``) to expand ``~`` to your username.  For example:
+  ``bzr launchpad-login user && bzr push lp:~/project/branch`` will now
+  push to ``lp:~user/project/branch``.  (John Arbash Meinel)
+
 Bug Fixes
 *********
 

=== modified file 'bzrlib/plugins/launchpad/lp_directory.py'
--- a/bzrlib/plugins/launchpad/lp_directory.py	2010-03-30 11:05:14 +0000
+++ b/bzrlib/plugins/launchpad/lp_directory.py	2010-07-26 17:19:33 +0000
@@ -64,7 +64,16 @@
         """Resolve the base URL for this transport."""
         service = LaunchpadService.for_url(url)
         result = urlsplit(url)
-        resolve = _request_factory(result[2].strip('/'))
+        if _lp_login is None:
+            _lp_login = get_lp_login()
+        path = result[2].strip('/')
+        if path.startswith('~/'):
+            if _lp_login is None:
+                raise errors.InvalidURL(path=url,
+                    extra='Cannot resolve "~" to your username.'
+                          ' See "bzr help launchpad-login"')
+            path = '~' + _lp_login + path[1:]
+        resolve = _request_factory(path)
         try:
             result = resolve.submit(service)
         except xmlrpclib.Fault, fault:
@@ -74,8 +83,6 @@
         if 'launchpad' in debug.debug_flags:
             trace.mutter("resolve_lp_path(%r) == %r", url, result)
 
-        if _lp_login is None:
-            _lp_login = get_lp_login()
         _warned_login = False
         for url in result['urls']:
             scheme, netloc, path, query, fragment = urlsplit(url)

=== modified file 'bzrlib/plugins/launchpad/test_lp_directory.py'
--- a/bzrlib/plugins/launchpad/test_lp_directory.py	2010-06-20 11:18:38 +0000
+++ b/bzrlib/plugins/launchpad/test_lp_directory.py	2010-07-26 17:19:33 +0000
@@ -36,7 +36,7 @@
     )
 from bzrlib.plugins.launchpad.lp_directory import (
     LaunchpadDirectory)
-from bzrlib.plugins.launchpad.account import get_lp_login
+from bzrlib.plugins.launchpad.account import get_lp_login, set_lp_login
 from bzrlib.tests import (
     http_server,
     http_utils,
@@ -199,6 +199,29 @@
         self.assertRaises(errors.InvalidURL,
             directory._resolve, 'lp://ratotehunoahu')
 
+    def test_resolve_tilde_to_user(self):
+        factory = FakeResolveFactory(
+            self, '~username/apt/test', dict(urls=[
+                    'bzr+ssh://bazaar.launchpad.net/~username/apt/test']))
+        directory = LaunchpadDirectory()
+        self.assertEquals(
+            'bzr+ssh://bazaar.launchpad.net/~username/apt/test',
+            directory._resolve('lp:~/apt/test', factory, _lp_login='username'))
+        # Should also happen when the login is just set by config
+        set_lp_login('username')
+        self.assertEquals(
+            'bzr+ssh://bazaar.launchpad.net/~username/apt/test',
+            directory._resolve('lp:~/apt/test', factory))
+
+    def test_tilde_fails_no_login(self):
+        factory = FakeResolveFactory(
+            self, '~username/apt/test', dict(urls=[
+                    'bzr+ssh://bazaar.launchpad.net/~username/apt/test']))
+        self.assertIs(None, get_lp_login())
+        directory = LaunchpadDirectory()
+        e = self.assertRaises(errors.InvalidURL,
+            directory._resolve, 'lp:~/apt/test', factory)
+
 
 class DirectoryOpenBranchTests(TestCaseWithMemoryTransport):
 




More information about the bazaar-commits mailing list