aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm/src/org/eclipse
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/src/org/eclipse
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/src/org/eclipse')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java8
1 files changed, 8 insertions, 0 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java
index 7f59ef43dc..7a0d96d419 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java
@@ -24,6 +24,7 @@ import org.eclipse.jgit.api.InitCommand;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.pgm.internal.CLIText;
+import org.eclipse.jgit.util.StringUtils;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
@@ -32,6 +33,10 @@ class Init extends TextBuiltin {
@Option(name = "--bare", usage = "usage_CreateABareRepository")
private boolean bare;
+ @Option(name = "--initial-branch", aliases = { "-b" },
+ metaVar = "metaVar_branchName", usage = "usage_initialBranch")
+ private String branch;
+
@Argument(index = 0, metaVar = "metaVar_directory")
private String directory;
@@ -54,6 +59,9 @@ class Init extends TextBuiltin {
}
Repository repository;
try {
+ if (!StringUtils.isEmptyOrNull(branch)) {
+ command.setInitialBranch(branch);
+ }
repository = command.call().getRepository();
outw.println(MessageFormat.format(
CLIText.get().initializedEmptyGitRepositoryIn,