git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Constantine Plotnikov <constantine.plotnikov@gmail.com>
To: git@vger.kernel.org
Cc: Constantine Plotnikov <constantine.plotnikov@gmail.com>
Subject: [JGIT PATCH] Added support for creating bare repositories
Date: Fri, 24 Apr 2009 19:36:57 +0400	[thread overview]
Message-ID: <1240587417-3732-1-git-send-email-constantine.plotnikov@gmail.com> (raw)

Now it is possible to create bare repositories.
The difference from normal repository creation is
that directory where repository is created might
exists and that core.bare property is set to true.

Signed-off-by: Constantine Plotnikov <constantine.plotnikov@gmail.com>
---
 .../src/org/spearce/jgit/pgm/Init.java             |    8 ++++-
 .../src/org/spearce/jgit/lib/Repository.java       |   28 ++++++++++++++++---
 2 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Init.java b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Init.java
index 197864d..3ab1599 100644
--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Init.java
+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Init.java
@@ -39,10 +39,14 @@
 
 import java.io.File;
 
+import org.kohsuke.args4j.Option;
 import org.spearce.jgit.lib.Repository;
 
 @Command(common = true, usage = "Create an empty git repository")
 class Init extends TextBuiltin {
+	@Option(name = "--bare", usage = "Create a bare repository")
+	private boolean bare;
+
 	@Override
 	protected final boolean requiresRepository() {
 		return false;
@@ -51,9 +55,9 @@ protected final boolean requiresRepository() {
 	@Override
 	protected void run() throws Exception {
 		if (gitdir == null)
-			gitdir = new File(".git");
+			gitdir = new File(bare ? "." : ".git");
 		db = new Repository(gitdir);
-		db.create();
+		db.create(bare);
 		out.println("Initialized empty Git repository in "
 				+ gitdir.getAbsolutePath());
 	}
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
index cfd92b8..f2b0b3f 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
@@ -161,16 +161,30 @@ public Repository(final File d) throws IOException {
 
 	/**
 	 * Create a new Git repository initializing the necessary files and
-	 * directories.
+	 * directories. Repository with working tree is created using this method.
 	 *
 	 * @throws IOException
+	 * @see #create(boolean)
 	 */
 	public synchronized void create() throws IOException {
-		if (gitDir.exists()) {
+		create(false);
+	}
+
+	/**
+	 * Create a new Git repository initializing the necessary files and
+	 * directories.
+	 * 
+	 * @param bare
+	 *            if true, a bare repository is created.
+	 * 
+	 * @throws IOException
+	 *             in case of IO problem
+	 */
+	public void create(boolean bare) throws IOException {
+		if ((bare ? new File(gitDir, "config") : gitDir).exists()) {
 			throw new IllegalStateException("Repository already exists: "
 					+ gitDir);
 		}
-
 		gitDir.mkdirs();
 		refs.create();
 
@@ -183,8 +197,12 @@ public synchronized void create() throws IOException {
 		final String master = Constants.R_HEADS + Constants.MASTER;
 		refs.link(Constants.HEAD, master);
 
-		getConfig().create();
-		getConfig().save();
+		RepositoryConfig cfg = getConfig();
+		cfg.create();
+		if (bare) {
+			cfg.setString("core", null, "bare", "true");
+		}
+		cfg.save();
 	}
 
 	private synchronized File[] objectsDirs(){
-- 
1.6.1.2

             reply	other threads:[~2009-04-24 15:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-24 15:36 Constantine Plotnikov [this message]
2009-04-26 22:29 ` [JGIT PATCH] Added support for creating bare repositories Robin Rosenberg
2009-04-27 12:46   ` Constantine Plotnikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1240587417-3732-1-git-send-email-constantine.plotnikov@gmail.com \
    --to=constantine.plotnikov@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).