diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java index 903f2e889..73530efca 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java @@ -106,7 +106,7 @@ class Clone extends AbstractFetchCommand { } } if (gitdir == null) - gitdir = new File(localName, Constants.DOT_GIT); + gitdir = new File(localName, Constants.DOT_GIT).getAbsolutePath(); dst = new FileRepository(gitdir); dst.create(); @@ -116,8 +116,7 @@ class Clone extends AbstractFetchCommand { db = dst; out.print(MessageFormat.format( - CLIText.get().initializedEmptyGitRepositoryIn, gitdir - .getAbsolutePath())); + CLIText.get().initializedEmptyGitRepositoryIn, gitdir)); out.println(); out.flush(); 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 c56540a76..98f086d46 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 @@ -47,6 +47,7 @@ package org.eclipse.jgit.pgm; +import java.io.File; import java.text.MessageFormat; import org.eclipse.jgit.api.Git; @@ -68,7 +69,7 @@ class Init extends TextBuiltin { protected void run() throws Exception { InitCommand command = Git.init(); command.setBare(bare); - command.setDirectory(gitdir); + command.setDirectory(new File(gitdir)); Repository repository = command.call().getRepository(); out.println(MessageFormat.format( CLIText.get().initializedEmptyGitRepositoryIn, repository diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java index 62ffd8d9c..654eed2cd 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java @@ -186,7 +186,7 @@ public class Main { if (cmd.requiresRepository()) cmd.init(openGitDir(gitdir), null); else - cmd.init(null, gitdir != null ? new File(gitdir) : null); + cmd.init(null, gitdir); try { cmd.execute(arguments.toArray(new String[arguments.size()])); } finally { diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java index b6f12a1ab..2988dfc54 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java @@ -49,19 +49,18 @@ import static org.eclipse.jgit.lib.Constants.R_REMOTES; import static org.eclipse.jgit.lib.Constants.R_TAGS; import java.io.BufferedWriter; -import java.io.File; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.text.MessageFormat; import java.util.ResourceBundle; -import org.kohsuke.args4j.CmdLineException; -import org.kohsuke.args4j.Option; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.pgm.opt.CmdLineParser; import org.eclipse.jgit.revwalk.RevWalk; +import org.kohsuke.args4j.CmdLineException; +import org.kohsuke.args4j.Option; /** * Abstract command which can be invoked from the command line. @@ -87,7 +86,7 @@ public abstract class TextBuiltin { protected Repository db; /** Directory supplied via --git-dir command line option. */ - protected File gitdir; + protected String gitdir; /** RevWalk used during command line parsing, if it was required. */ protected RevWalk argWalk; @@ -101,9 +100,19 @@ public abstract class TextBuiltin { return true; } - void init(final Repository repo, final File gd) { + /** + * Initialize the command to work with a repository. + * + * @param repository + * the opened repository that the command should work on. + * @param gitDir + * value of the {@code --git-dir} command line option, if + * {@code repository} is null. + */ + protected void init(final Repository repository, final String gitDir) { try { - final String outputEncoding = repo != null ? repo.getConfig() + final String outputEncoding = repository != null ? repository + .getConfig() .getString("i18n", null, "logOutputEncoding") : null; if (outputEncoding != null) out = new PrintWriter(new BufferedWriter( @@ -115,12 +124,12 @@ public abstract class TextBuiltin { throw die(CLIText.get().cannotCreateOutputStream); } - if (repo != null) { - db = repo; - gitdir = repo.getDirectory(); + if (repository != null && repository.getDirectory() != null) { + db = repository; + gitdir = repository.getDirectory().getAbsolutePath(); } else { - db = null; - gitdir = gd; + db = repository; + gitdir = gitDir; } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java index 552d70450..60d92d6be 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java @@ -135,7 +135,7 @@ class DiffAlgorithms extends TextBuiltin { if (gitDirs.isEmpty()) { RepositoryBuilder rb = new RepositoryBuilder() // - .setGitDir(gitdir) // + .setGitDir(new File(gitdir)) // .readEnvironment() // .findGitDir(); if (rb.getGitDir() == null) diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java index 5ce9d808c..61a8ecc38 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java @@ -266,7 +266,7 @@ class TextHashFunctions extends TextBuiltin { protected void run() throws Exception { if (gitDirs.isEmpty()) { RepositoryBuilder rb = new RepositoryBuilder() // - .setGitDir(gitdir) // + .setGitDir(new File(gitdir)) // .readEnvironment() // .findGitDir(); if (rb.getGitDir() == null)