]> source.dussan.org Git - jgit.git/commitdiff
RepoProject: read the 'dest-branch' attribute of a project 58/1197358/1
authorKaushik Lingarkar <quic_kaushikl@quicinc.com>
Fri, 28 Jun 2024 17:02:05 +0000 (10:02 -0700)
committerMatthias Sohn <matthias.sohn@sap.com>
Mon, 8 Jul 2024 12:06:03 +0000 (14:06 +0200)
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
(cherry picked from commit 47fd412affd8d7578606ae9b3015a911b71b13ed)

org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java
org.eclipse.jgit/.settings/.api_filters [new file with mode: 0644]
org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java
org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java

index 76176fe34773f7b90ee714d7799f209c842a359b..fca27d32aa4bb29d5468981aae9217607f4c8bd8 100644 (file)
@@ -177,6 +177,36 @@ public class ManifestParserTest {
                assertNull(bar.getUpstream());
        }
 
+       @Test
+       public void testWithDestBranch() throws Exception {
+               StringBuilder xmlContent = new StringBuilder();
+               xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
+                               .append("<manifest>")
+                               .append("<remote name=\"remote1\" fetch=\".\" />")
+                               .append("<default revision=\"master\" remote=\"remote1\" />")
+                               .append("<project path=\"foo\" name=\"foo\"")
+                               .append("  dest-branch=\"branchX\"/>")
+                               .append("<project path=\"bar\" name=\"bar\"/>")
+                               .append("</manifest>");
+
+               ManifestParser parser = new ManifestParser(null, null, "master",
+                               "https://git.google.com/", null, null);
+               parser.read(new ByteArrayInputStream(
+                               xmlContent.toString().getBytes(UTF_8)));
+
+               Map<String, RepoProject> 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/.settings/.api_filters b/org.eclipse.jgit/.settings/.api_filters
new file mode 100644 (file)
index 0000000..50a04d2
--- /dev/null
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<component id="org.eclipse.jgit" version="2">
+    <resource path="src/org/eclipse/jgit/gitrepo/RepoProject.java" type="org.eclipse.jgit.gitrepo.RepoProject">
+        <filter id="1141899266">
+            <message_arguments>
+                <message_argument value="7.0"/>
+                <message_argument value="6.10"/>
+                <message_argument value="getDestBranch()"/>
+            </message_arguments>
+        </filter>
+        <filter id="1141899266">
+            <message_arguments>
+                <message_argument value="7.0"/>
+                <message_argument value="6.10"/>
+                <message_argument value="setDestBranch(String)"/>
+            </message_arguments>
+        </filter>
+    </resource>
+</component>
index 7402c760c3fc6035bcf8a0cf375328531e837fd4..b033177e05a9a6e5ff2c9244c82c43941ef03c9a 100644 (file)
@@ -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");
index 3ed0bef317fc31bedd0b5cf4c214ea3528a39549..b7a9ac5b7338e0c6ed7e637c41cdd3f8810b68cc 100644 (file)
@@ -39,6 +39,7 @@ public class RepoProject implements Comparable<RepoProject> {
        private final List<CopyFile> copyfiles;
        private final List<LinkFile> 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<RepoProject> {
                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
         *
@@ -415,6 +427,20 @@ public class RepoProject implements Comparable<RepoProject> {
                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;