aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorIvan Frade <ifrade@google.com>2021-08-26 13:19:01 -0700
committerIvan Frade <ifrade@google.com>2022-01-31 14:47:33 -0800
commitdee4240ce86f21d262ac071ed80838223bf4d516 (patch)
tree77025bf38a8ef95378fa2ef2f5723e9463e66bae /org.eclipse.jgit.test
parent1fd15e40cc7bf67c30849abc3030de8568246a4e (diff)
downloadjgit-dee4240ce86f21d262ac071ed80838223bf4d516.tar.gz
jgit-dee4240ce86f21d262ac071ed80838223bf4d516.zip
RepoCommand: Move bare/regular superproject writing to their own classes
RepoCommand parses the manifest to get a list of projects, clears up conflicts and then writes to the superproject. The first steps are common but the writing is completely different for bare or "regular" (with working dir) repository. Split writing to bare and regular repos into its own classes. This simplifies RepoCommand class and makes clearer what happens on each side (e.g. many options apply only to bare repos). Change-Id: I256e15729bd53ee15fc56de88bce86a2edb2417a
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/BareSuperprojectWriterTest.java79
1 files changed, 79 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/BareSuperprojectWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/BareSuperprojectWriterTest.java
new file mode 100644
index 0000000000..d52292dc97
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/BareSuperprojectWriterTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2021, Google Inc. and others
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+package org.eclipse.jgit.gitrepo;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.is;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.jgit.gitrepo.BareSuperprojectWriter.BareWriterConfig;
+import org.eclipse.jgit.gitrepo.RepoCommand.RemoteReader;
+import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ObjectReader;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.junit.Test;
+
+public class BareSuperprojectWriterTest extends RepositoryTestCase {
+
+ private static final String SHA1_A = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @Test
+ public void write_setGitModulesContents() throws Exception {
+ try (Repository bareRepo = createBareRepository()) {
+ RepoProject repoProject = new RepoProject("subprojectX", "path/to",
+ "refs/heads/branch-x", "remote", "");
+ repoProject.setUrl("http://example.com/a");
+
+ RemoteReader mockRemoteReader = mock(RemoteReader.class);
+ when(mockRemoteReader.sha1("http://example.com/a",
+ "refs/heads/branch-x"))
+ .thenReturn(ObjectId.fromString(SHA1_A));
+
+ BareSuperprojectWriter w = new BareSuperprojectWriter(bareRepo,
+ null, "refs/heads/master", author, mockRemoteReader,
+ BareWriterConfig.getDefault());
+
+ RevCommit commit = w.write(Arrays.asList(repoProject));
+
+ String contents = readContents(bareRepo, commit, ".gitmodules");
+ List<String> contentLines = Arrays
+ .asList(contents.split("\n"));
+ assertThat(contentLines.get(0),
+ is("[submodule \"subprojectX\"]"));
+ assertThat(contentLines.subList(1, contentLines.size()),
+ containsInAnyOrder(is("\tbranch = refs/heads/branch-x"),
+ is("\tpath = path/to"),
+ is("\turl = http://example.com/a")));
+ }
+ }
+
+ private String readContents(Repository repo, RevCommit commit,
+ String path) throws Exception {
+ String idStr = commit.getId().name() + ":" + path;
+ ObjectId modId = repo.resolve(idStr);
+ try (ObjectReader reader = repo.newObjectReader()) {
+ return new String(
+ reader.open(modId).getCachedBytes(Integer.MAX_VALUE));
+
+ }
+ }
+}