{"thread":{"id":"2934","subject":"[PATCH] Do not allow git-init-db to be called twice in the same directory","startedAt":"2005-12-26T23:54:05Z","lastAt":"2005-12-27T18:01:00Z","messageCount":5,"participants":["Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"14054","messageId":"Pine.LNX.4.63.0512270053030.14928@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2934","inReplyTo":null,"subject":"[PATCH] Do not allow git-init-db to be called twice in the same directory","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-12-26T23:54:05Z","receivedAt":"2005-12-26T23:54:05Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nt5300 is also adapted, since it relies heavily on init-db not complaining \nwhen $GIT_DIR already exists.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n init-db.c              |    3 ++-\n t/t5300-pack-object.sh |   16 ++++++----------\n 2 files changed, 8 insertions(+), 11 deletions(-)\n\n199557e282c6b7600fdb9f7ce8b203b1d634de8f\ndiff --git a/init-db.c b/init-db.c\nindex ff29496..1cb015e 100644\n--- a/init-db.c\n+++ b/init-db.c\n@@ -259,7 +259,8 @@ int main(int argc, char **argv)\n \t\tgit_dir = DEFAULT_GIT_DIR_ENVIRONMENT;\n \t\tfprintf(stderr, \"defaulting to local storage area\\n\");\n \t}\n-\tsafe_create_dir(git_dir, 0);\n+\tif (mkdir(git_dir, 0777) < 0)\n+\t\tdie(\"Cannot initialize repository twice!\");\n \n \t/* Check to see if the repository version is right.\n \t * Note that a newly created repository does not have\ndiff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh\nindex 7dfb1ab..df6549c 100755\n--- a/t/t5300-pack-object.sh\n+++ b/t/t5300-pack-object.sh\n@@ -38,13 +38,12 @@ test_expect_success \\\n     'packname_1=$(git-pack-objects --window=0 test-1 <obj-list)'\n \n rm -fr .git2\n-mkdir .git2\n \n test_expect_success \\\n     'unpack without delta' \\\n-    \"GIT_OBJECT_DIRECTORY=.git2/objects &&\n+    \"GIT_DIR=.git2 git-init-db &&\n+     GIT_OBJECT_DIRECTORY=.git2/objects &&\n      export GIT_OBJECT_DIRECTORY &&\n-     git-init-db &&\n      git-unpack-objects -n <test-1-${packname_1}.pack &&\n      git-unpack-objects <test-1-${packname_1}.pack\"\n \n@@ -69,13 +68,12 @@ test_expect_success \\\n      packname_2=$(git-pack-objects test-2 <obj-list)'\n \n rm -fr .git2\n-mkdir .git2\n \n test_expect_success \\\n     'unpack with delta' \\\n-    'GIT_OBJECT_DIRECTORY=.git2/objects &&\n+    'GIT_DIR=.git2 git-init-db &&\n+     GIT_OBJECT_DIRECTORY=.git2/objects &&\n      export GIT_OBJECT_DIRECTORY &&\n-     git-init-db &&\n      git-unpack-objects -n <test-2-${packname_2}.pack &&\n      git-unpack-objects <test-2-${packname_2}.pack'\n \n@@ -94,13 +92,12 @@ test_expect_success \\\n cd \"$TRASH\"\n \n rm -fr .git2\n-mkdir .git2\n \n test_expect_success \\\n     'use packed objects' \\\n-    'GIT_OBJECT_DIRECTORY=.git2/objects &&\n+    'GIT_DIR=.git2 git-init-db &&\n+     GIT_OBJECT_DIRECTORY=.git2/objects &&\n      export GIT_OBJECT_DIRECTORY &&\n-     git-init-db &&\n      cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && {\n \t git-diff-tree --root -p $commit &&\n \t while read object\n@@ -111,7 +108,6 @@ test_expect_success \\\n     } >current &&\n     diff expect current'\n \n-\n test_expect_success \\\n     'use packed deltified objects' \\\n     'GIT_OBJECT_DIRECTORY=.git2/objects &&\n-- \n1.0.GIT\n"},{"id":"14055","messageId":"7vbqz3ibhn.fsf@assigned-by-dhcp.cox.net","threadId":"2934","inReplyTo":"Pine.LNX.4.63.0512270053030.14928@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Do not allow git-init-db to be called twice in the same directory","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-12-27T01:18:12Z","receivedAt":"2005-12-27T01:18:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> t5300 is also adapted, since it relies heavily on init-db not complaining \n> when $GIT_DIR already exists.\n\nI think it tries not to overwrite things that are already there\nand is meant to be safe to run in an already populated\nrepository; e.g. you should be able to use it to pick up newly\nadded templates.\n\nIs there a particular reason running the current init-db twice\nis undesirable?\n"},{"id":"14063","messageId":"Pine.LNX.4.63.0512271457200.17086@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2934","inReplyTo":"7vbqz3ibhn.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Do not allow git-init-db to be called twice in the same directory","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-12-27T14:01:40Z","receivedAt":"2005-12-27T14:01:40Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 26 Dec 2005, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > t5300 is also adapted, since it relies heavily on init-db not complaining \n> > when $GIT_DIR already exists.\n> \n> I think it tries not to overwrite things that are already there\n> and is meant to be safe to run in an already populated\n> repository; e.g. you should be able to use it to pick up newly\n> added templates.\n\nAh, that is a use case I missed. I don't work too much with templates \n(only on the shared repositories' machine)...\n\n> Is there a particular reason running the current init-db twice\n> is undesirable?\n\nIn my case, yes. When I do that, it means that I did not correctly \nchange directories. I fscked up my private git repository twice that way.\n\nI like your point, though.\n\nCiao,\nDscho\n"},{"id":"14066","messageId":"7vlky6bi6f.fsf@assigned-by-dhcp.cox.net","threadId":"2934","inReplyTo":"Pine.LNX.4.63.0512271457200.17086@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Do not allow git-init-db to be called twice in the same directory","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-12-27T16:47:52Z","receivedAt":"2005-12-27T16:47:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n>> Is there a particular reason running the current init-db twice\n>> is undesirable?\n>\n> In my case, yes. When I do that, it means that I did not correctly \n> change directories. I fscked up my private git repository twice that way.\n\nMaybe a warning (e.g. \"rerunning in an already set up\nrepository\") is in order?\n"},{"id":"14068","messageId":"Pine.LNX.4.63.0512271859250.1618@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"2934","inReplyTo":"7vlky6bi6f.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Do not allow git-init-db to be called twice in the same directory","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2005-12-27T18:01:00Z","receivedAt":"2005-12-27T18:01:00Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 27 Dec 2005, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> >> Is there a particular reason running the current init-db twice\n> >> is undesirable?\n> >\n> > In my case, yes. When I do that, it means that I did not correctly \n> > change directories. I fscked up my private git repository twice that way.\n> \n> Maybe a warning (e.g. \"rerunning in an already set up\n> repository\") is in order?\n\nYeah. Or a command line parameter \"--exists\" without which it fails?\n\nCiao,\nDscho\n"}]}