Merge ~cjwatson/git-build-recipe:tolerate-missing-HEAD into git-build-recipe:master

Proposed by Colin Watson
Status: Merged
Merged at revision: 9f8c826e35d46c1868f562cc6f71214c88cf1f8e
Proposed branch: ~cjwatson/git-build-recipe:tolerate-missing-HEAD
Merge into: git-build-recipe:master
Diff against target: 109 lines (+40/-6)
4 files modified
debian/changelog (+4/-0)
gitbuildrecipe/recipe.py (+16/-6)
gitbuildrecipe/tests/__init__.py (+6/-0)
gitbuildrecipe/tests/test_recipe.py (+14/-0)
Reviewer Review Type Date Requested Status
Tom Wardill (community) Approve
Review via email: mp+368050@code.launchpad.net

Commit message

Tolerate remote repositories with no HEAD

We want to fetch the remote HEAD if it exists, but if the recipe doesn't
rely on it then a failure to do so doesn't need to be fatal.

LP: #1683913

To post a comment you must log in.
Revision history for this message
Tom Wardill (twom) :
Revision history for this message
Colin Watson (cjwatson) :
Revision history for this message
Tom Wardill (twom) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index f0663a3..f9a3e7a 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,7 +1,11 @@
6 git-build-recipe (0.3.6) UNRELEASED; urgency=medium
7
8+ [ Jelmer Vernooij ]
9 * Use secure URI in Vcs control header.
10
11+ [ Colin Watson ]
12+ * Tolerate remote repositories with no HEAD (LP: #1683913).
13+
14 -- Jelmer Vernooij <jelmer@debian.org> Wed, 12 Sep 2018 04:18:41 +0100
15
16 git-build-recipe (0.3.5) unstable; urgency=medium
17diff --git a/gitbuildrecipe/recipe.py b/gitbuildrecipe/recipe.py
18index d1700f2..0ff215f 100644
19--- a/gitbuildrecipe/recipe.py
20+++ b/gitbuildrecipe/recipe.py
21@@ -327,12 +327,22 @@ def fetch_branches(child_branch):
22 parsed_url = urlparse(url)
23 if not parsed_url.scheme and not parsed_url.path.startswith("/"):
24 url = os.path.abspath(url)
25- # Fetch all remote branches, the remote HEAD, and (implicitly) any
26- # tags that reference commits in those refs. Tags that aren't on a
27- # branch won't be fetched.
28+ # Fetch the remote HEAD. This may not exist, which is OK as long as the
29+ # recipe uses explicit branch names.
30+ try:
31+ child_branch.git_call(
32+ "fetch", url,
33+ "HEAD:refs/remotes/%s/HEAD" % child_branch.remote_name,
34+ silent=True)
35+ except subprocess.CalledProcessError as e:
36+ logging.info(e.output)
37+ logging.info(
38+ "Failed to fetch HEAD; recipe instructions for this repository "
39+ "that do not specify a branch name will fail.")
40+ # Fetch all remote branches and (implicitly) any tags that reference
41+ # commits in those refs. Tags that aren't on a branch won't be fetched.
42 child_branch.git_call(
43 "fetch", url,
44- "HEAD:refs/remotes/%s/HEAD" % child_branch.remote_name,
45 "refs/heads/*:refs/remotes/%s/*" % child_branch.remote_name)
46
47
48@@ -650,10 +660,10 @@ class RecipeBranch:
49 output = subprocess.check_output(
50 cmd, stderr=subprocess.STDOUT, universal_newlines=True,
51 **kwargs)
52- if silent:
53+ if not silent:
54 sys.stdout.write(output)
55 except subprocess.CalledProcessError as e:
56- if silent:
57+ if not silent:
58 sys.stderr.write(e.output)
59 raise
60
61diff --git a/gitbuildrecipe/tests/__init__.py b/gitbuildrecipe/tests/__init__.py
62index 4962e50..6b41396 100644
63--- a/gitbuildrecipe/tests/__init__.py
64+++ b/gitbuildrecipe/tests/__init__.py
65@@ -58,6 +58,9 @@ class GitRepository:
66 self._git_call("commit", "-q", "--allow-empty", "-m", message, env=env)
67 return self.last_revision()
68
69+ def branch(self, branch_name, commit):
70+ self._git_call("branch", branch_name, commit)
71+
72 def tag(self, tag_name, commit, force=False):
73 args = ["tag"]
74 if force:
75@@ -65,6 +68,9 @@ class GitRepository:
76 args.extend([tag_name, commit])
77 self._git_call(*args, stdout=subprocess.DEVNULL)
78
79+ def set_head(self, ref_path):
80+ self._git_call("symbolic-ref", "HEAD", ref_path)
81+
82 def get_parents(self, commit):
83 return self._git_output(
84 "log", "-1", "--format=%P", commit).rstrip("\n").split()
85diff --git a/gitbuildrecipe/tests/test_recipe.py b/gitbuildrecipe/tests/test_recipe.py
86index ed7634d..7628a45 100644
87--- a/gitbuildrecipe/tests/test_recipe.py
88+++ b/gitbuildrecipe/tests/test_recipe.py
89@@ -891,6 +891,20 @@ class BuildTreeTests(GitTestCase):
90 self.assertRaises(
91 TargetAlreadyExists, pull_or_clone, base_branch, "target")
92
93+ def test_pull_or_clone_with_no_HEAD(self):
94+ source = GitRepository("source")
95+ source.build_tree(["a"])
96+ source.add(["a"])
97+ commit = source.commit("one")
98+ source.branch("source/master", commit)
99+ source.set_head("refs/heads/nonexistent")
100+ base_branch = BaseRecipeBranch(
101+ "source", "1", 0.2, revspec="source/master")
102+ pull_or_clone(base_branch, "target")
103+ target = GitRepository("target", allow_create=False)
104+ self.assertEqual(commit, target.last_revision())
105+ self.assertEqual(commit, target.rev_parse("source/master"))
106+
107 def test_build_tree_runs_commands(self):
108 source = GitRepository("source")
109 commit = source.commit("one")

Subscribers

People subscribed via source and target branches