From 8e1b581d39a8e1eadfb8f2ab7590546ec89c9abe Mon Sep 17 00:00:00 2001 From: Philipp Thun Date: Fri, 11 Mar 2011 15:49:27 +0100 Subject: [PATCH] Make --git-dir optional for 'jgit init' For compatibility reasons with regards to native git and also to make the init command easier to use from the command line, argument --git-dir should not be required. Additionally the path created in case --git-dir is not supplied now is canonical and thus easier to read. Change-Id: Idb7d77e983a78c4b21fbf232fc1e75ef581e5ed1 Signed-off-by: Philipp Thun --- org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Init.java | 3 ++- org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java | 2 +- 2 files changed, 3 insertions(+), 2 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 98f086d46..e1e38e5bc 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 @@ -69,7 +69,8 @@ class Init extends TextBuiltin { protected void run() throws Exception { InitCommand command = Git.init(); command.setBare(bare); - command.setDirectory(new File(gitdir)); + if (gitdir != null) + command.setDirectory(new File(gitdir)); Repository repository = command.call().getRepository(); out.println(MessageFormat.format( CLIText.get().initializedEmptyGitRepositoryIn, repository diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java index fdadf9690..d68f4e27f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java @@ -83,7 +83,7 @@ public class InitCommand implements Callable { } else if (builder.getGitDir() == null) { File d = new File("."); if (!bare) - d = new File(d, Constants.DOT_GIT); + d = new File(d, Constants.DOT_GIT).getCanonicalFile(); builder.setGitDir(d); } Repository repository = builder.build();