summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm.test
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.pgm.test')
-rw-r--r--org.eclipse.jgit.pgm.test/.settings/org.eclipse.jdt.core.prefs4
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CloneTest.java42
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/InitTest.java21
3 files changed, 65 insertions, 2 deletions
diff --git a/org.eclipse.jgit.pgm.test/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jgit.pgm.test/.settings/org.eclipse.jdt.core.prefs
index 3dd5840397..b853c6a7ed 100644
--- a/org.eclipse.jgit.pgm.test/.settings/org.eclipse.jdt.core.prefs
+++ b/org.eclipse.jgit.pgm.test/.settings/org.eclipse.jdt.core.prefs
@@ -51,8 +51,8 @@ org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=error
org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=protected
-org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
-org.eclipse.jdt.core.compiler.problem.missingJavadocTags=error
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=no_tag
+org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=private
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();
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/InitTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/InitTest.java
index 84474e33cd..88789d3383 100644
--- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/InitTest.java
+++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/InitTest.java
@@ -11,11 +11,14 @@
package org.eclipse.jgit.pgm;
import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
import java.io.File;
+import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.Repository;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -54,4 +57,22 @@ public class InitTest extends CLIRepositoryTestCase {
assertArrayEquals(expecteds, result);
}
+ @Test
+ public void testInitDirectoryInitialBranch() throws Exception {
+ File workDirectory = tempFolder.getRoot();
+ File gitDirectory = new File(workDirectory, Constants.DOT_GIT);
+
+ String[] result = execute(
+ "git init -b main '" + workDirectory.getCanonicalPath() + "'");
+
+ String[] expecteds = new String[] {
+ "Initialized empty Git repository in "
+ + gitDirectory.getCanonicalPath(),
+ "" };
+ assertArrayEquals(expecteds, result);
+
+ try (Repository repo = new FileRepository(gitDirectory)) {
+ assertEquals("refs/heads/main", repo.getFullBranch());
+ }
+ }
}