From 47fd412affd8d7578606ae9b3015a911b71b13ed Mon Sep 17 00:00:00 2001 From: Kaushik Lingarkar Date: Fri, 28 Jun 2024 10:02:05 -0700 Subject: [PATCH] RepoProject: read the 'dest-branch' attribute of a project The manifest spec [1] defines a "dest-branch" attribute. Parse its value and store it in the RepoProject. Also, create a getter/setter for dest-branch. [1] https://gerrit.googlesource.com/git-repo/+/master/docs/manifest-format.md#Element-project Change-Id: I8ad83b0fec59d2b0967864e4de4fefde4ab971ff --- .../jgit/gitrepo/ManifestParserTest.java | 30 +++++++++++++++++++ .../eclipse/jgit/gitrepo/ManifestParser.java | 2 ++ .../org/eclipse/jgit/gitrepo/RepoProject.java | 26 ++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java index 76176fe347..fca27d32aa 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java @@ -177,6 +177,36 @@ public class ManifestParserTest { assertNull(bar.getUpstream()); } + @Test + public void testWithDestBranch() throws Exception { + StringBuilder xmlContent = new StringBuilder(); + xmlContent.append("\n") + .append("") + .append("") + .append("") + .append("") + .append("") + .append(""); + + ManifestParser parser = new ManifestParser(null, null, "master", + "https://git.google.com/", null, null); + parser.read(new ByteArrayInputStream( + xmlContent.toString().getBytes(UTF_8))); + + Map repos = parser.getProjects().stream().collect( + Collectors.toMap(RepoProject::getName, Function.identity())); + assertEquals(2, repos.size()); + + RepoProject foo = repos.get("foo"); + assertEquals("foo", foo.getName()); + assertEquals("branchX", foo.getDestBranch()); + + RepoProject bar = repos.get("bar"); + assertEquals("bar", bar.getName()); + assertNull(bar.getDestBranch()); + } + void testNormalize(String in, String want) { URI got = ManifestParser.normalizeEmptyPath(URI.create(in)); if (!got.toString().equals(want)) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java index 7402c760c3..b033177e05 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java @@ -178,6 +178,8 @@ public class ManifestParser extends DefaultHandler { .setRecommendShallow(attributes.getValue("clone-depth")); currentProject .setUpstream(attributes.getValue("upstream")); + currentProject + .setDestBranch(attributes.getValue("dest-branch")); break; case "remote": String alias = attributes.getValue("alias"); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java index 09ce28386c..d8fec78493 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java @@ -39,6 +39,7 @@ public class RepoProject implements Comparable { private final List copyfiles; private final List linkfiles; private String upstream; + private String destBranch; private String recommendShallow; private String url; private String defaultRevision; @@ -401,6 +402,17 @@ public class RepoProject implements Comparable { return this.upstream; } + /** + * Return the dest-branch attribute of the project + * + * @return the dest-branch value if present, null otherwise. + * + * @since 7.0 + */ + public String getDestBranch() { + return this.destBranch; + } + /** * Set the upstream attribute of the project * @@ -416,6 +428,20 @@ public class RepoProject implements Comparable { this.upstream = upstream; } + /** + * Set the dest-branch attribute of the project + * + * Name of a Git branch. + * + * @param destBranch + * value of the attribute in the manifest + * + * @since 7.0 + */ + public void setDestBranch(String destBranch) { + this.destBranch = destBranch; + } + private String getPathWithSlash() { if (path.endsWith("/")) { //$NON-NLS-1$ return path; -- 2.39.5