From eac2dc18f11e517d995cf2db68d5675390daa02b Mon Sep 17 00:00:00 2001 From: Christian Halstrick Date: Tue, 29 Mar 2011 15:03:25 +0200 Subject: [PATCH] Allow InitCommand to run on existing git repos To be more consistent with what native git does we should allow to run the InitCommand also on existing git repos. Change-Id: I833637842631b37dce96ed9729b3a6ed24054056 Signed-off-by: Christian Halstrick --- org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 5b96cddac..77fc3042c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/InitCommand.java @@ -52,7 +52,7 @@ import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.RepositoryBuilder; /** - * Create an empty git repository + * Create an empty git repository or reinitalize an existing one * * @see Git documentation about init @@ -89,7 +89,8 @@ public class InitCommand implements Callable { builder.setGitDir(d); } Repository repository = builder.build(); - repository.create(bare); + if (!repository.getObjectDatabase().exists()) + repository.create(bare); return new Git(repository); } catch (IOException e) { throw new JGitInternalException(e.getMessage(), e);