git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Do not allow git-init-db to be called twice in the same directory
@ 2005-12-26 23:54 Johannes Schindelin
  2005-12-27  1:18 ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Johannes Schindelin @ 2005-12-26 23:54 UTC (permalink / raw)
  To: git, junkio


t5300 is also adapted, since it relies heavily on init-db not complaining 
when $GIT_DIR already exists.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>

---

 init-db.c              |    3 ++-
 t/t5300-pack-object.sh |   16 ++++++----------
 2 files changed, 8 insertions(+), 11 deletions(-)

199557e282c6b7600fdb9f7ce8b203b1d634de8f
diff --git a/init-db.c b/init-db.c
index ff29496..1cb015e 100644
--- a/init-db.c
+++ b/init-db.c
@@ -259,7 +259,8 @@ int main(int argc, char **argv)
 		git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
 		fprintf(stderr, "defaulting to local storage area\n");
 	}
-	safe_create_dir(git_dir, 0);
+	if (mkdir(git_dir, 0777) < 0)
+		die("Cannot initialize repository twice!");
 
 	/* Check to see if the repository version is right.
 	 * Note that a newly created repository does not have
diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh
index 7dfb1ab..df6549c 100755
--- a/t/t5300-pack-object.sh
+++ b/t/t5300-pack-object.sh
@@ -38,13 +38,12 @@ test_expect_success \
     'packname_1=$(git-pack-objects --window=0 test-1 <obj-list)'
 
 rm -fr .git2
-mkdir .git2
 
 test_expect_success \
     'unpack without delta' \
-    "GIT_OBJECT_DIRECTORY=.git2/objects &&
+    "GIT_DIR=.git2 git-init-db &&
+     GIT_OBJECT_DIRECTORY=.git2/objects &&
      export GIT_OBJECT_DIRECTORY &&
-     git-init-db &&
      git-unpack-objects -n <test-1-${packname_1}.pack &&
      git-unpack-objects <test-1-${packname_1}.pack"
 
@@ -69,13 +68,12 @@ test_expect_success \
      packname_2=$(git-pack-objects test-2 <obj-list)'
 
 rm -fr .git2
-mkdir .git2
 
 test_expect_success \
     'unpack with delta' \
-    'GIT_OBJECT_DIRECTORY=.git2/objects &&
+    'GIT_DIR=.git2 git-init-db &&
+     GIT_OBJECT_DIRECTORY=.git2/objects &&
      export GIT_OBJECT_DIRECTORY &&
-     git-init-db &&
      git-unpack-objects -n <test-2-${packname_2}.pack &&
      git-unpack-objects <test-2-${packname_2}.pack'
 
@@ -94,13 +92,12 @@ test_expect_success \
 cd "$TRASH"
 
 rm -fr .git2
-mkdir .git2
 
 test_expect_success \
     'use packed objects' \
-    'GIT_OBJECT_DIRECTORY=.git2/objects &&
+    'GIT_DIR=.git2 git-init-db &&
+     GIT_OBJECT_DIRECTORY=.git2/objects &&
      export GIT_OBJECT_DIRECTORY &&
-     git-init-db &&
      cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && {
 	 git-diff-tree --root -p $commit &&
 	 while read object
@@ -111,7 +108,6 @@ test_expect_success \
     } >current &&
     diff expect current'
 
-
 test_expect_success \
     'use packed deltified objects' \
     'GIT_OBJECT_DIRECTORY=.git2/objects &&
-- 
1.0.GIT

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Do not allow git-init-db to be called twice in the same directory
  2005-12-26 23:54 [PATCH] Do not allow git-init-db to be called twice in the same directory Johannes Schindelin
@ 2005-12-27  1:18 ` Junio C Hamano
  2005-12-27 14:01   ` Johannes Schindelin
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2005-12-27  1:18 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git, junkio

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> t5300 is also adapted, since it relies heavily on init-db not complaining 
> when $GIT_DIR already exists.

I think it tries not to overwrite things that are already there
and is meant to be safe to run in an already populated
repository; e.g. you should be able to use it to pick up newly
added templates.

Is there a particular reason running the current init-db twice
is undesirable?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Do not allow git-init-db to be called twice in the same directory
  2005-12-27  1:18 ` Junio C Hamano
@ 2005-12-27 14:01   ` Johannes Schindelin
  2005-12-27 16:47     ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Johannes Schindelin @ 2005-12-27 14:01 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Hi,

On Mon, 26 Dec 2005, Junio C Hamano wrote:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > t5300 is also adapted, since it relies heavily on init-db not complaining 
> > when $GIT_DIR already exists.
> 
> I think it tries not to overwrite things that are already there
> and is meant to be safe to run in an already populated
> repository; e.g. you should be able to use it to pick up newly
> added templates.

Ah, that is a use case I missed. I don't work too much with templates 
(only on the shared repositories' machine)...

> Is there a particular reason running the current init-db twice
> is undesirable?

In my case, yes. When I do that, it means that I did not correctly 
change directories. I fscked up my private git repository twice that way.

I like your point, though.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Do not allow git-init-db to be called twice in the same directory
  2005-12-27 14:01   ` Johannes Schindelin
@ 2005-12-27 16:47     ` Junio C Hamano
  2005-12-27 18:01       ` Johannes Schindelin
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2005-12-27 16:47 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

>> Is there a particular reason running the current init-db twice
>> is undesirable?
>
> In my case, yes. When I do that, it means that I did not correctly 
> change directories. I fscked up my private git repository twice that way.

Maybe a warning (e.g. "rerunning in an already set up
repository") is in order?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Do not allow git-init-db to be called twice in the same directory
  2005-12-27 16:47     ` Junio C Hamano
@ 2005-12-27 18:01       ` Johannes Schindelin
  0 siblings, 0 replies; 5+ messages in thread
From: Johannes Schindelin @ 2005-12-27 18:01 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Hi,

On Tue, 27 Dec 2005, Junio C Hamano wrote:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> >> Is there a particular reason running the current init-db twice
> >> is undesirable?
> >
> > In my case, yes. When I do that, it means that I did not correctly 
> > change directories. I fscked up my private git repository twice that way.
> 
> Maybe a warning (e.g. "rerunning in an already set up
> repository") is in order?

Yeah. Or a command line parameter "--exists" without which it fails?

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-12-27 18:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-26 23:54 [PATCH] Do not allow git-init-db to be called twice in the same directory Johannes Schindelin
2005-12-27  1:18 ` Junio C Hamano
2005-12-27 14:01   ` Johannes Schindelin
2005-12-27 16:47     ` Junio C Hamano
2005-12-27 18:01       ` Johannes Schindelin

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).