summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm.test/tst/org
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2021-01-24 00:17:13 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2021-02-22 23:11:44 +0100
commit64cb7148ac64855feb7f7649d1d168d7c6d37860 (patch)
tree1fdf66e54abe9ce87d65247c1918c5ad8db5cb56 /org.eclipse.jgit.pgm.test/tst/org
parent704ccdc096e4f5cf2670c5c58eaf19fe1fdf4df3 (diff)
downloadjgit-64cb7148ac64855feb7f7649d1d168d7c6d37860.tar.gz
jgit-64cb7148ac64855feb7f7649d1d168d7c6d37860.zip
Fail clone if initial branch doesn't exist in remote repository
jgit clone --branch foo <url> did not fail if the remote branch "foo" didn't exist in the remote repository being cloned. Bug: 546580 Change-Id: I55648ad3a39da4a5711dfa8e6d6682bb8190a6d6 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.pgm.test/tst/org')
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java42
1 files changed, 42 insertions, 0 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 2f09b7f122..4cbd61c692 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
@@ -11,7 +11,9 @@ package org.eclipse.jgit.pgm;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import java.io.File;
@@ -25,6 +27,7 @@ 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.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.RefSpec;
@@ -64,6 +67,45 @@ public class CloneTest extends CLIRepositoryTestCase {
assertEquals("expected 1 branch", 1, branches.size());
}
+ @Test
+ public void testCloneInitialBranch() throws Exception {
+ createInitialCommit();
+
+ File gitDir = db.getDirectory();
+ String sourceURI = gitDir.toURI().toString();
+ File target = createTempDirectory("target");
+ String cmd = "git clone --branch master " + sourceURI + " "
+ + shellQuote(target.getPath());
+ String[] result = execute(cmd);
+ assertArrayEquals(new String[] {
+ "Cloning into '" + target.getPath() + "'...", "", "" }, result);
+
+ Git git2 = Git.open(target);
+ List<Ref> branches = git2.branchList().call();
+ assertEquals("expected 1 branch", 1, branches.size());
+
+ Repository db2 = git2.getRepository();
+ ObjectId head = db2.resolve("HEAD");
+ assertNotNull(head);
+ assertNotEquals(ObjectId.zeroId(), head);
+ ObjectId master = db2.resolve("master");
+ assertEquals(head, master);
+ }
+
+ @Test
+ public void testCloneInitialBranchMissing() throws Exception {
+ createInitialCommit();
+
+ File gitDir = db.getDirectory();
+ String sourceURI = gitDir.toURI().toString();
+ File target = createTempDirectory("target");
+ String cmd = "git clone --branch foo " + sourceURI + " "
+ + shellQuote(target.getPath());
+ Die e = assertThrows(Die.class, () -> execute(cmd));
+ assertEquals("Remote branch 'foo' not found in upstream origin",
+ e.getMessage());
+ }
+
private RevCommit createInitialCommit() throws Exception {
JGitTestUtil.writeTrashFile(db, "hello.txt", "world");
git.add().addFilepattern("hello.txt").call();