{"thread":{"id":"19048","subject":"[JGIT PATCH] Added support for creating bare repositories","startedAt":"2009-04-24T15:36:57Z","lastAt":"2009-04-27T12:46:03Z","messageCount":3,"participants":["Constantine Plotnikov","Robin Rosenberg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"112208","messageId":"1240587417-3732-1-git-send-email-constantine.plotnikov@gmail.com","threadId":"19048","inReplyTo":null,"subject":"[JGIT PATCH] Added support for creating bare repositories","fromName":"Constantine Plotnikov","fromEmail":"constantine.plotnikov@gmail.com","sentAt":"2009-04-24T15:36:57Z","receivedAt":"2009-04-24T15:36:57Z","isPatch":true,"sender":{"key":"constantine.plotnikov@gmail.com","avatar":null},"body":"Now it is possible to create bare repositories.\nThe difference from normal repository creation is\nthat directory where repository is created might\nexists and that core.bare property is set to true.\n\nSigned-off-by: Constantine Plotnikov <constantine.plotnikov@gmail.com>\n---\n .../src/org/spearce/jgit/pgm/Init.java             |    8 ++++-\n .../src/org/spearce/jgit/lib/Repository.java       |   28 ++++++++++++++++---\n 2 files changed, 29 insertions(+), 7 deletions(-)\n\ndiff --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\nindex 197864d..3ab1599 100644\n--- a/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Init.java\n+++ b/org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/Init.java\n@@ -39,10 +39,14 @@\n \n import java.io.File;\n \n+import org.kohsuke.args4j.Option;\n import org.spearce.jgit.lib.Repository;\n \n @Command(common = true, usage = \"Create an empty git repository\")\n class Init extends TextBuiltin {\n+\t@Option(name = \"--bare\", usage = \"Create a bare repository\")\n+\tprivate boolean bare;\n+\n \t@Override\n \tprotected final boolean requiresRepository() {\n \t\treturn false;\n@@ -51,9 +55,9 @@ protected final boolean requiresRepository() {\n \t@Override\n \tprotected void run() throws Exception {\n \t\tif (gitdir == null)\n-\t\t\tgitdir = new File(\".git\");\n+\t\t\tgitdir = new File(bare ? \".\" : \".git\");\n \t\tdb = new Repository(gitdir);\n-\t\tdb.create();\n+\t\tdb.create(bare);\n \t\tout.println(\"Initialized empty Git repository in \"\n \t\t\t\t+ gitdir.getAbsolutePath());\n \t}\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java\nindex cfd92b8..f2b0b3f 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java\n@@ -161,16 +161,30 @@ public Repository(final File d) throws IOException {\n \n \t/**\n \t * Create a new Git repository initializing the necessary files and\n-\t * directories.\n+\t * directories. Repository with working tree is created using this method.\n \t *\n \t * @throws IOException\n+\t * @see #create(boolean)\n \t */\n \tpublic synchronized void create() throws IOException {\n-\t\tif (gitDir.exists()) {\n+\t\tcreate(false);\n+\t}\n+\n+\t/**\n+\t * Create a new Git repository initializing the necessary files and\n+\t * directories.\n+\t * \n+\t * @param bare\n+\t *            if true, a bare repository is created.\n+\t * \n+\t * @throws IOException\n+\t *             in case of IO problem\n+\t */\n+\tpublic void create(boolean bare) throws IOException {\n+\t\tif ((bare ? new File(gitDir, \"config\") : gitDir).exists()) {\n \t\t\tthrow new IllegalStateException(\"Repository already exists: \"\n \t\t\t\t\t+ gitDir);\n \t\t}\n-\n \t\tgitDir.mkdirs();\n \t\trefs.create();\n \n@@ -183,8 +197,12 @@ public synchronized void create() throws IOException {\n \t\tfinal String master = Constants.R_HEADS + Constants.MASTER;\n \t\trefs.link(Constants.HEAD, master);\n \n-\t\tgetConfig().create();\n-\t\tgetConfig().save();\n+\t\tRepositoryConfig cfg = getConfig();\n+\t\tcfg.create();\n+\t\tif (bare) {\n+\t\t\tcfg.setString(\"core\", null, \"bare\", \"true\");\n+\t\t}\n+\t\tcfg.save();\n \t}\n \n \tprivate synchronized File[] objectsDirs(){\n-- \n1.6.1.2\n"},{"id":"112402","messageId":"200904270029.56939.robin.rosenberg.lists@dewire.com","threadId":"19048","inReplyTo":"1240587417-3732-1-git-send-email-constantine.plotnikov@gmail.com","subject":"Re: [JGIT PATCH] Added support for creating bare repositories","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg.lists@dewire.com","sentAt":"2009-04-26T22:29:56Z","receivedAt":"2009-04-26T22:29:56Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"fredag 24 april 2009 17:36:57 skrev Constantine Plotnikov <constantine.plotnikov@gmail.com>:\n> Now it is possible to create bare repositories.\n> The difference from normal repository creation is\n> that directory where repository is created might\n> exists and that core.bare property is set to true.\n\nI know C Git doesn't check if a directory is a non-bare repo, but I think\nthat's wrong, so if I try to create a bare repo in a non-bare repo that\nshould be an error. For now I'll accept it anyway since the C version allows\nit and it is useful.\n\n-- robin\n"},{"id":"112414","messageId":"85647ef50904270546w41692a50j84cc898a264998ba@mail.gmail.com","threadId":"19048","inReplyTo":"200904270029.56939.robin.rosenberg.lists@dewire.com","subject":"Re: [JGIT PATCH] Added support for creating bare repositories","fromName":"Constantine Plotnikov","fromEmail":"constantine.plotnikov@gmail.com","sentAt":"2009-04-27T12:46:03Z","receivedAt":"2009-04-27T12:46:03Z","isPatch":true,"sender":{"key":"constantine.plotnikov@gmail.com","avatar":null},"body":"On Mon, Apr 27, 2009 at 2:29 AM, Robin Rosenberg\n<robin.rosenberg.lists@dewire.com> wrote:\n> fredag 24 april 2009 17:36:57 skrev Constantine Plotnikov <constantine.plotnikov@gmail.com>:\n>> Now it is possible to create bare repositories.\n>> The difference from normal repository creation is\n>> that directory where repository is created might\n>> exists and that core.bare property is set to true.\n>\n> I know C Git doesn't check if a directory is a non-bare repo, but I think\n> that's wrong, so if I try to create a bare repo in a non-bare repo that\n> should be an error. For now I'll accept it anyway since the C version allows\n> it and it is useful.\n>\nI'm not sure that this should be an error. We have a bare git\nrepository with a test data inside the non-bare repository. And such\nfeature might be nice to have to other git related tools as well. %)\n\nConstantine\n"}]}