summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm.test/tst/org/eclipse
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2019-10-20 18:08:59 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2019-10-21 09:29:52 +0200
commitc24eee4fa4db682b138a7a212cf711ab682d02f6 (patch)
treea0b756998f5ceb64fadef2b514f2cef68c8b9524 /org.eclipse.jgit.pgm.test/tst/org/eclipse
parentbceac7bd03e5a7660cb4f934f0db7ada7eab7b54 (diff)
downloadjgit-c24eee4fa4db682b138a7a212cf711ab682d02f6.tar.gz
jgit-c24eee4fa4db682b138a7a212cf711ab682d02f6.zip
[pgm] Add --mirror option to clone command
Bug: 552173 Change-Id: Ic8a98b2e0f8f29afd599723f93e51b06b9f13314 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.pgm.test/tst/org/eclipse')
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java44
1 files changed, 42 insertions, 2 deletions
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java
index c31f28c256..0ecbd656ed 100644
--- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java
@@ -44,6 +44,7 @@ package org.eclipse.jgit.pgm;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
@@ -54,7 +55,13 @@ import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.RefUpdate;
+import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.transport.RefSpec;
+import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.util.SystemReader;
import org.junit.Before;
@@ -90,10 +97,10 @@ public class CloneTest extends CLIRepositoryTestCase {
assertEquals("expected 1 branch", 1, branches.size());
}
- private void createInitialCommit() throws Exception {
+ private RevCommit createInitialCommit() throws Exception {
JGitTestUtil.writeTrashFile(db, "hello.txt", "world");
git.add().addFilepattern("hello.txt").call();
- git.commit().setMessage("Initial commit").call();
+ return git.commit().setMessage("Initial commit").call();
}
@Test
@@ -154,4 +161,37 @@ public class CloneTest extends CLIRepositoryTestCase {
assertEquals("expected 1 branch", 1, branches.size());
assertTrue("expected bare repository", git2.getRepository().isBare());
}
+
+ @Test
+ public void testCloneMirror() throws Exception {
+ ObjectId head = createInitialCommit();
+ // create a non-standard ref
+ RefUpdate ru = db.updateRef("refs/meta/foo/bar");
+ ru.setNewObjectId(head);
+ ru.update();
+
+ File gitDir = db.getDirectory();
+ String sourcePath = gitDir.getAbsolutePath();
+ String targetPath = (new File(sourcePath)).getParentFile()
+ .getParentFile().getAbsolutePath() + File.separator
+ + "target.git";
+ String cmd = "git clone --mirror " + shellQuote(sourcePath) + " "
+ + shellQuote(targetPath);
+ String[] result = execute(cmd);
+ assertArrayEquals(
+ new String[] { "Cloning into '" + targetPath + "'...", "", "" },
+ result);
+ Git git2 = Git.open(new File(targetPath));
+ List<Ref> branches = git2.branchList().call();
+ assertEquals("expected 1 branch", 1, branches.size());
+ assertTrue("expected bare repository", git2.getRepository().isBare());
+ StoredConfig config = git2.getRepository().getConfig();
+ RemoteConfig rc = new RemoteConfig(config, "origin");
+ assertTrue("expected mirror configuration", rc.isMirror());
+ RefSpec fetchRefSpec = rc.getFetchRefSpecs().get(0);
+ assertTrue("exected force udpate", fetchRefSpec.isForceUpdate());
+ assertEquals("refs/*", fetchRefSpec.getSource());
+ assertEquals("refs/*", fetchRefSpec.getDestination());
+ assertNotNull(git2.getRepository().exactRef("refs/meta/foo/bar"));
+ }
}