Merge lp:~chris-gondolin/charm-helpers/fetch-bzr-revnos into lp:charm-helpers

Proposed by Chris Stratford
Status: Merged
Merged at revision: 587
Proposed branch: lp:~chris-gondolin/charm-helpers/fetch-bzr-revnos
Merge into: lp:charm-helpers
Diff against target: 40 lines (+13/-5)
1 file modified
charmhelpers/fetch/bzrurl.py (+13/-5)
To merge this branch: bzr merge lp:~chris-gondolin/charm-helpers/fetch-bzr-revnos
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review via email: mp+289942@code.launchpad.net

Description of the change

Adds the option to specify a revno when fetching from a bzr repo.

Updated and resubmitted, since the code the original merge request was made against (8 months ago) has now changed.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Looks fine, but there is no test for the new arguments. I've added the trivial test, which demonstrated a bug (revno needs to be cast to a string), which I have also fixed.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmhelpers/fetch/bzrurl.py'
--- charmhelpers/fetch/bzrurl.py 2015-12-10 21:01:00 +0000
+++ charmhelpers/fetch/bzrurl.py 2016-03-23 17:06:53 +0000
@@ -42,15 +42,23 @@
42 else:42 else:
43 return True43 return True
4444
45 def branch(self, source, dest):45 def branch(self, source, dest, revno=None):
46 if not self.can_handle(source):46 if not self.can_handle(source):
47 raise UnhandledSource("Cannot handle {}".format(source))47 raise UnhandledSource("Cannot handle {}".format(source))
48 cmd_opts = []
49 if revno:
50 cmd_opts += ['-r', revno]
48 if os.path.exists(dest):51 if os.path.exists(dest):
49 check_call(['bzr', 'pull', '--overwrite', '-d', dest, source])52 cmd = ['bzr', 'pull']
53 cmd += cmd_opts
54 cmd += ['--overwrite', '-d', dest, source]
50 else:55 else:
51 check_call(['bzr', 'branch', source, dest])56 cmd = ['bzr', 'branch']
57 cmd += cmd_opts
58 cmd += [source, dest]
59 check_call(cmd)
5260
53 def install(self, source, dest=None):61 def install(self, source, dest=None, revno=None):
54 url_parts = self.parse_url(source)62 url_parts = self.parse_url(source)
55 branch_name = url_parts.path.strip("/").split("/")[-1]63 branch_name = url_parts.path.strip("/").split("/")[-1]
56 if dest:64 if dest:
@@ -62,7 +70,7 @@
62 if not os.path.exists(dest_dir):70 if not os.path.exists(dest_dir):
63 mkdir(dest_dir, perms=0o755)71 mkdir(dest_dir, perms=0o755)
64 try:72 try:
65 self.branch(source, dest_dir)73 self.branch(source, dest_dir, revno)
66 except OSError as e:74 except OSError as e:
67 raise UnhandledSource(e.strerror)75 raise UnhandledSource(e.strerror)
68 return dest_dir76 return dest_dir

Subscribers

People subscribed via source and target branches