summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm.test/tst/org
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2021-01-25 01:54:03 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2021-02-22 23:11:45 +0100
commitcb8924a80d9e07182a056c01acd418a6beddcc0f (patch)
tree2263bc474b1524894d9321c7e667d664c9cb60f0 /org.eclipse.jgit.pgm.test/tst/org
parent64cb7148ac64855feb7f7649d1d168d7c6d37860 (diff)
downloadjgit-cb8924a80d9e07182a056c01acd418a6beddcc0f.tar.gz
jgit-cb8924a80d9e07182a056c01acd418a6beddcc0f.zip
init: allow specifying the initial branch name for the new repository
Add option --initial-branch/-b to InitCommand and the CLI init command. This is the first step to implement support for the new option init.defaultBranch. Both were added to git in release 2.28. See https://git-scm.com/docs/git-init#Documentation/git-init.txt--bltbranch-namegt Bug: 564794 Change-Id: Ia383b3f90b5549db80f99b2310450a7faf6bce4c 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/InitTest.java21
1 files changed, 21 insertions, 0 deletions
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());
+ }
+ }
}