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
=== modified file 'debian/changelog'
--- debian/changelog 2018-06-05 02:04:39 +0000
+++ debian/changelog 2018-06-05 02:07:44 +0000
@@ -9,6 +9,7 @@
9 VM that is guaranteed to be torn down after the build.9 VM that is guaranteed to be torn down after the build.
10 * Refactor VCS operations from lpbuildd.target.build_snap out to a module10 * Refactor VCS operations from lpbuildd.target.build_snap out to a module
11 that can be used by other targets.11 that can be used by other targets.
12 * Allow checking out a git tag rather than a branch (LP: #1687078).
1213
13 -- Colin Watson <cjwatson@ubuntu.com> Tue, 08 May 2018 10:36:22 +010014 -- Colin Watson <cjwatson@ubuntu.com> Tue, 08 May 2018 10:36:22 +0100
1415
1516
=== modified file 'lpbuildd/target/build_snap.py'
--- lpbuildd/target/build_snap.py 2018-06-05 02:04:39 +0000
+++ lpbuildd/target/build_snap.py 2018-06-05 02:07:44 +0000
@@ -150,7 +150,9 @@
150 self.args.git_path150 self.args.git_path
151 if self.args.git_path is not None else "HEAD")151 if self.args.git_path is not None else "HEAD")
152 status["revision_id"] = self.run_build_command(152 status["revision_id"] = self.run_build_command(
153 ["git", "rev-parse", rev],153 # The ^{} suffix copes with tags: we want to peel them
154 # recursively until we get an actual commit.
155 ["git", "rev-parse", rev + "^{}"],
154 cwd=os.path.join("/build", self.args.name),156 cwd=os.path.join("/build", self.args.name),
155 get_output=True).rstrip("\n")157 get_output=True).rstrip("\n")
156 self.save_status(status)158 self.save_status(status)
157159
=== modified file 'lpbuildd/target/tests/test_build_snap.py'
--- lpbuildd/target/tests/test_build_snap.py 2018-06-05 02:04:39 +0000
+++ lpbuildd/target/tests/test_build_snap.py 2018-06-05 02:07:44 +0000
@@ -207,7 +207,7 @@
207 ["git", "submodule", "update", "--init", "--recursive"],207 ["git", "submodule", "update", "--init", "--recursive"],
208 cwd="/build/test-snap"),208 cwd="/build/test-snap"),
209 RanBuildCommand(209 RanBuildCommand(
210 ["git", "rev-parse", "HEAD"],210 ["git", "rev-parse", "HEAD^{}"],
211 cwd="/build/test-snap", get_output=True),211 cwd="/build/test-snap", get_output=True),
212 ]))212 ]))
213 status_path = os.path.join(build_snap.backend.build_path, "status")213 status_path = os.path.join(build_snap.backend.build_path, "status")
@@ -232,7 +232,33 @@
232 ["git", "submodule", "update", "--init", "--recursive"],232 ["git", "submodule", "update", "--init", "--recursive"],
233 cwd="/build/test-snap"),233 cwd="/build/test-snap"),
234 RanBuildCommand(234 RanBuildCommand(
235 ["git", "rev-parse", "next"],235 ["git", "rev-parse", "next^{}"],
236 cwd="/build/test-snap", get_output=True),
237 ]))
238 status_path = os.path.join(build_snap.backend.build_path, "status")
239 with open(status_path) as status:
240 self.assertEqual({"revision_id": "0" * 40}, json.load(status))
241
242 def test_repo_git_with_tag_path(self):
243 args = [
244 "buildsnap",
245 "--backend=fake", "--series=xenial", "--arch=amd64", "1",
246 "--git-repository", "lp:foo", "--git-path", "refs/tags/1.0",
247 "test-snap",
248 ]
249 build_snap = parse_args(args=args).operation
250 build_snap.backend.build_path = self.useFixture(TempDir()).path
251 build_snap.backend.run = FakeRevisionID("0" * 40)
252 build_snap.repo()
253 self.assertThat(build_snap.backend.run.calls, MatchesListwise([
254 RanBuildCommand(
255 ["git", "clone", "-b", "1.0", "lp:foo", "test-snap"],
256 cwd="/build"),
257 RanBuildCommand(
258 ["git", "submodule", "update", "--init", "--recursive"],
259 cwd="/build/test-snap"),
260 RanBuildCommand(
261 ["git", "rev-parse", "refs/tags/1.0^{}"],
236 cwd="/build/test-snap", get_output=True),262 cwd="/build/test-snap", get_output=True),
237 ]))263 ]))
238 status_path = os.path.join(build_snap.backend.build_path, "status")264 status_path = os.path.join(build_snap.backend.build_path, "status")
@@ -263,7 +289,7 @@
263 ["git", "submodule", "update", "--init", "--recursive"],289 ["git", "submodule", "update", "--init", "--recursive"],
264 cwd="/build/test-snap", **env),290 cwd="/build/test-snap", **env),
265 RanBuildCommand(291 RanBuildCommand(
266 ["git", "rev-parse", "HEAD"],292 ["git", "rev-parse", "HEAD^{}"],
267 cwd="/build/test-snap", get_output=True),293 cwd="/build/test-snap", get_output=True),
268 ]))294 ]))
269 status_path = os.path.join(build_snap.backend.build_path, "status")295 status_path = os.path.join(build_snap.backend.build_path, "status")
270296
=== modified file 'lpbuildd/target/vcs.py'
--- lpbuildd/target/vcs.py 2018-03-14 14:04:22 +0000
+++ lpbuildd/target/vcs.py 2018-06-05 02:07:44 +0000
@@ -75,7 +75,19 @@
75 if quiet:75 if quiet:
76 cmd.append("-q")76 cmd.append("-q")
77 if self.args.git_path is not None:77 if self.args.git_path is not None:
78 cmd.extend(["-b", self.args.git_path])78 git_path = self.args.git_path
79 # "git clone -b" is a bit odd: it takes either branches or
80 # tags, but they must be in their short form, i.e. "master"
81 # rather than "refs/heads/master" and "1.0" rather than
82 # "refs/tags/1.0". There's thus room for ambiguity if a
83 # repository has a branch and a tag with the same name (the
84 # branch will win), but using tags in the first place is
85 # pretty rare here and a name collision is rarer still.
86 # Launchpad shortens branch names before sending them to us,
87 # but not tag names.
88 if git_path.startswith("refs/tags/"):
89 git_path = git_path[len("refs/tags/"):]
90 cmd.extend(["-b", git_path])
79 cmd.extend([self.args.git_repository, name])91 cmd.extend([self.args.git_repository, name])
80 if not self.ssl_verify:92 if not self.ssl_verify:
81 env["GIT_SSL_NO_VERIFY"] = "1"93 env["GIT_SSL_NO_VERIFY"] = "1"

Subscribers

People subscribed via source and target branches

to all changes: