Merge lp:~tsimonq2/ubuntu-archive-tools/change-default-branch-when-branch-made-git into lp:ubuntu-archive-tools

Proposed by Simon Quigley
Status: Merged
Merged at revision: 1148
Proposed branch: lp:~tsimonq2/ubuntu-archive-tools/change-default-branch-when-branch-made-git
Merge into: lp:ubuntu-archive-tools
Diff against target: 61 lines (+20/-3)
1 file modified
branch-seeds (+20/-3)
To merge this branch: bzr merge lp:~tsimonq2/ubuntu-archive-tools/change-default-branch-when-branch-made-git
Reviewer Review Type Date Requested Status
Colin Watson Approve
Steve Langasek Pending
Review via email: mp+335863@code.launchpad.net

Description of the change

This is related to the merge proposal that was made earlier today, so adding Steve as a reviewer, but I made this a separate MP for a couple of reasons:
 1. The nature of the change is a bit different, and if discussion is needed, is likely different than the discussions needed in the other MP.
 2. I wanted to get the other MP done and merged so there's a basis; the default branch could always be changed manually pretty easily, but doing it automatically is a bit of an enhancement.
 3. I was having some problems working with launchpadlib that were since solved in #launchpad, thanks nacc and cjwatson!

Here's what this actually does:
 1. It adds Git support to the already existing remote_branch function, and does it in the same sort of way as Bazaar (I would be happy to figure out how to convert these to the respective Python libraries if the reviewers think it would be a good prerequisite to merging). This also adds an additional argument to be passed, and it's used in a way that would allow passing of the existing vcs variable, to not overcomplicate things.
 2. This uses https://git.launchpad.net/usd-importer/tree/gitubuntu/importer.py#n374 and on as a starting point to programatically change the default branch of the Git repository we're pushing to to the new branch it's creating, with the goal to always have the default branch be the development release. This shouldn't break if flavors always follow the lp:~TEAM/ubuntu-seeds/+git/FLAVOR convention and they do something like lp:~TEAM/+git/FLAVOR but I think that having flavors follow that consistent convention should be mandatory anyways.
 3. This changes the Launchpad API login to using the devel interface, because after discussing with cjwatson in #launchpad it was determined that the Git API functions aren't exposed on anything but devel. Should I leave a code comment?

Thanks.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

No need for a comment regarding using the devel API version; that should be normal practice for most new scripts anyway.

Revision history for this message
Simon Quigley (tsimonq2) wrote :

> No need for a comment regarding using the devel API version; that should be
> normal practice for most new scripts anyway.

Ok, cool.

Revision history for this message
Colin Watson (cjwatson) :
review: Needs Fixing
1145. By Simon Quigley

Split remote_branch into two different functions dependent on the VCS.

1146. By Simon Quigley

Make adjustments from Colin's suggestions.

1147. By Simon Quigley

Add additional code tweaks.

Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'branch-seeds'
2--- branch-seeds 2018-01-08 22:05:09 +0000
3+++ branch-seeds 2018-01-17 03:34:29 +0000
4@@ -45,7 +45,7 @@
5 return None
6
7
8-def remote_branch(source):
9+def remote_bzr_branch(source):
10 # TODO: should really use bzrlib instead
11 info = subprocess.check_output(
12 ["bzr", "info", source], universal_newlines=True)
13@@ -55,6 +55,14 @@
14 else:
15 raise Exception("Unable to find remote branch for %s" % source)
16
17+def remote_git_repository(source, srcbranch):
18+ fullbranch = subprocess.check_output(
19+ ["git", "rev-parse", "--symbolic-full-name", srcbranch+"@{upstream}"],
20+ universal_newlines=True, cwd=source)
21+ return subprocess.check_output(
22+ ["git", "ls-remote", "--get-url", fullbranch.split("/")[2]],
23+ universal_newlines=True, cwd=source)
24+
25
26 def lp_branch(options, url):
27 return options.launchpad.branches.getByUniqueName(
28@@ -68,7 +76,7 @@
29 if vcs:
30 if vcs is VCS.Bazaar:
31 subprocess.check_call(["bzr", "up", source])
32- remote_source = remote_branch(source)
33+ remote_source = remote_bzr_branch(source)
34 remote_dest = os.path.join(os.path.dirname(remote_source), dest)
35 subprocess.check_call(["bzr", "branch", source, dest])
36 subprocess.check_call(["bzr", "push", "-d", dest, remote_dest])
37@@ -120,6 +128,15 @@
38 subprocess.check_call(
39 ["git", "push", "origin", options.dest_series], cwd=dest)
40
41+ remote = remote_git_repository(dest, options.source_series)
42+ if "git.launchpad.net" in remote:
43+ lp_git_repo = options.launchpad.git_repositories.getByPath(
44+ path=urlparse(remote).path.lstrip("/").rstrip("\n"))
45+ lp_git_repo.default_branch = options.dest_series
46+ lp_git_repo.lp_save()
47+ else:
48+ raise Exception("Git remote URL must be on git.launchpad.net.")
49+
50
51 def main():
52 parser = OptionParser(usage="usage: %prog [options] collection ...")
53@@ -136,7 +153,7 @@
54 parser.error("You must specify at least one seed collection.")
55
56 options.launchpad = Launchpad.login_with(
57- "branch-seeds", options.launchpad_instance)
58+ "branch-seeds", options.launchpad_instance, version="devel")
59
60 distro = options.launchpad.distributions["ubuntu"]
61 if options.source_series is None:

Subscribers

People subscribed via source and target branches