Merge lp:~cjwatson/launchpad-buildd/git-path-tags into lp:launchpad-buildd

Proposed by Colin Watson
Status: Merged
Merged at revision: 340
Proposed branch: lp:~cjwatson/launchpad-buildd/git-path-tags
Merge into: lp:launchpad-buildd
Prerequisite: lp:~cjwatson/launchpad-buildd/refactor-vcs
Diff against target: 108 lines (+46/-5)
4 files modified
debian/changelog (+1/-0)
lpbuildd/target/build_snap.py (+3/-1)
lpbuildd/target/tests/test_build_snap.py (+29/-3)
lpbuildd/target/vcs.py (+13/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad-buildd/git-path-tags
Reviewer Review Type Date Requested Status
William Grant (community) code Approve
Review via email: mp+344995@code.launchpad.net

Commit message

Allow checking out a git tag rather than a branch.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)
330. By Colin Watson

Merge trunk.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2018-06-05 02:04:39 +0000
3+++ debian/changelog 2018-06-05 02:07:44 +0000
4@@ -9,6 +9,7 @@
5 VM that is guaranteed to be torn down after the build.
6 * Refactor VCS operations from lpbuildd.target.build_snap out to a module
7 that can be used by other targets.
8+ * Allow checking out a git tag rather than a branch (LP: #1687078).
9
10 -- Colin Watson <cjwatson@ubuntu.com> Tue, 08 May 2018 10:36:22 +0100
11
12
13=== modified file 'lpbuildd/target/build_snap.py'
14--- lpbuildd/target/build_snap.py 2018-06-05 02:04:39 +0000
15+++ lpbuildd/target/build_snap.py 2018-06-05 02:07:44 +0000
16@@ -150,7 +150,9 @@
17 self.args.git_path
18 if self.args.git_path is not None else "HEAD")
19 status["revision_id"] = self.run_build_command(
20- ["git", "rev-parse", rev],
21+ # The ^{} suffix copes with tags: we want to peel them
22+ # recursively until we get an actual commit.
23+ ["git", "rev-parse", rev + "^{}"],
24 cwd=os.path.join("/build", self.args.name),
25 get_output=True).rstrip("\n")
26 self.save_status(status)
27
28=== modified file 'lpbuildd/target/tests/test_build_snap.py'
29--- lpbuildd/target/tests/test_build_snap.py 2018-06-05 02:04:39 +0000
30+++ lpbuildd/target/tests/test_build_snap.py 2018-06-05 02:07:44 +0000
31@@ -207,7 +207,7 @@
32 ["git", "submodule", "update", "--init", "--recursive"],
33 cwd="/build/test-snap"),
34 RanBuildCommand(
35- ["git", "rev-parse", "HEAD"],
36+ ["git", "rev-parse", "HEAD^{}"],
37 cwd="/build/test-snap", get_output=True),
38 ]))
39 status_path = os.path.join(build_snap.backend.build_path, "status")
40@@ -232,7 +232,33 @@
41 ["git", "submodule", "update", "--init", "--recursive"],
42 cwd="/build/test-snap"),
43 RanBuildCommand(
44- ["git", "rev-parse", "next"],
45+ ["git", "rev-parse", "next^{}"],
46+ cwd="/build/test-snap", get_output=True),
47+ ]))
48+ status_path = os.path.join(build_snap.backend.build_path, "status")
49+ with open(status_path) as status:
50+ self.assertEqual({"revision_id": "0" * 40}, json.load(status))
51+
52+ def test_repo_git_with_tag_path(self):
53+ args = [
54+ "buildsnap",
55+ "--backend=fake", "--series=xenial", "--arch=amd64", "1",
56+ "--git-repository", "lp:foo", "--git-path", "refs/tags/1.0",
57+ "test-snap",
58+ ]
59+ build_snap = parse_args(args=args).operation
60+ build_snap.backend.build_path = self.useFixture(TempDir()).path
61+ build_snap.backend.run = FakeRevisionID("0" * 40)
62+ build_snap.repo()
63+ self.assertThat(build_snap.backend.run.calls, MatchesListwise([
64+ RanBuildCommand(
65+ ["git", "clone", "-b", "1.0", "lp:foo", "test-snap"],
66+ cwd="/build"),
67+ RanBuildCommand(
68+ ["git", "submodule", "update", "--init", "--recursive"],
69+ cwd="/build/test-snap"),
70+ RanBuildCommand(
71+ ["git", "rev-parse", "refs/tags/1.0^{}"],
72 cwd="/build/test-snap", get_output=True),
73 ]))
74 status_path = os.path.join(build_snap.backend.build_path, "status")
75@@ -263,7 +289,7 @@
76 ["git", "submodule", "update", "--init", "--recursive"],
77 cwd="/build/test-snap", **env),
78 RanBuildCommand(
79- ["git", "rev-parse", "HEAD"],
80+ ["git", "rev-parse", "HEAD^{}"],
81 cwd="/build/test-snap", get_output=True),
82 ]))
83 status_path = os.path.join(build_snap.backend.build_path, "status")
84
85=== modified file 'lpbuildd/target/vcs.py'
86--- lpbuildd/target/vcs.py 2018-03-14 14:04:22 +0000
87+++ lpbuildd/target/vcs.py 2018-06-05 02:07:44 +0000
88@@ -75,7 +75,19 @@
89 if quiet:
90 cmd.append("-q")
91 if self.args.git_path is not None:
92- cmd.extend(["-b", self.args.git_path])
93+ git_path = self.args.git_path
94+ # "git clone -b" is a bit odd: it takes either branches or
95+ # tags, but they must be in their short form, i.e. "master"
96+ # rather than "refs/heads/master" and "1.0" rather than
97+ # "refs/tags/1.0". There's thus room for ambiguity if a
98+ # repository has a branch and a tag with the same name (the
99+ # branch will win), but using tags in the first place is
100+ # pretty rare here and a name collision is rarer still.
101+ # Launchpad shortens branch names before sending them to us,
102+ # but not tag names.
103+ if git_path.startswith("refs/tags/"):
104+ git_path = git_path[len("refs/tags/"):]
105+ cmd.extend(["-b", git_path])
106 cmd.extend([self.args.git_repository, name])
107 if not self.ssl_verify:
108 env["GIT_SSL_NO_VERIFY"] = "1"

Subscribers

People subscribed via source and target branches

to all changes: