{"thread":{"id":"11434","subject":"[bug] Working files created in bare repository when pushing to a rewound bare repository","startedAt":"2007-12-31T06:42:42Z","lastAt":"2008-01-03T21:29:46Z","messageCount":9,"participants":["Ping Yin","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"64246","messageId":"46dff0320712302242m34b5267dlb3f26488293d5d51@mail.gmail.com","threadId":"11434","inReplyTo":null,"subject":"[bug] Working files created in bare repository when pushing to a rewound bare repository","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2007-12-31T06:42:42Z","receivedAt":"2007-12-31T06:42:42Z","isPatch":false,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"Following scripts can reproduce the problem: in the final line,\nfoo.txt is generated in bare foo.git\n\n# create bare foo.git and its clone foo\nmkdir foo\ncd foo && echo foo>foo.txt &&\ngit init && git add . && git commit -m 'create project foo' && cd ..\ncd foo && echo foo1>foo.txt && git commit -a -m \"update foo.txt\" && cd ..\ngit clone --bare foo foo.git && rm -rf foo\ngit clone foo.git foo\n\n# reset bare and then push\ncd foo.git && git reset --hard HEAD^ && cd ..\ncd foo && git push && cd ..\nls foo.git\n\nbranches  config  description  *foo.txt*  HEAD  hooks  index  info\nobjects  ORIG_HEAD  refs\n\n-- \nPing Yin\n"},{"id":"64247","messageId":"20071231064741.GA4250@coredump.intra.peff.net","threadId":"11434","inReplyTo":"46dff0320712302242m34b5267dlb3f26488293d5d51@mail.gmail.com","subject":"Re: [bug] Working files created in bare repository when pushing to a rewound bare repository","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-12-31T06:47:42Z","receivedAt":"2007-12-31T06:47:42Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Dec 31, 2007 at 02:42:42PM +0800, Ping Yin wrote:\n\n> Following scripts can reproduce the problem: in the final line,\n> foo.txt is generated in bare foo.git\n\nNo, your script is wrong.\n\n> # create bare foo.git and its clone foo\n> mkdir foo\n> cd foo && echo foo>foo.txt &&\n> git init && git add . && git commit -m 'create project foo' && cd ..\n> cd foo && echo foo1>foo.txt && git commit -a -m \"update foo.txt\" && cd ..\n> git clone --bare foo foo.git && rm -rf foo\n> git clone foo.git foo\n> \n> # reset bare and then push\n> cd foo.git && git reset --hard HEAD^ && cd ..\n\nTry looking in foo.git after this step. The \"--hard\" to git-reset is\ncreating the file foo.txt. --hard makes no sense in a bare repository (I\nthought we were disallowing it, but apparently not).\n\n-Peff\n"},{"id":"64248","messageId":"7vd4sn73yi.fsf@gitster.siamese.dyndns.org","threadId":"11434","inReplyTo":"46dff0320712302242m34b5267dlb3f26488293d5d51@mail.gmail.com","subject":"Re: [bug] Working files created in bare repository when pushing to a rewound bare repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-31T06:50:29Z","receivedAt":"2007-12-31T06:50:29Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Ping Yin\" <pkufranky@gmail.com> writes:\n\n> Following scripts can reproduce the problem: in the final line,\n> foo.txt is generated in bare foo.git\n\n> # reset bare and then push\n> cd foo.git && git reset --hard HEAD^ && cd ..\n\n\"git reset\" is about resetting *both* the branch tip and the\nwork tree.  Doesn't it create unwanted work tree files when\nmisused this way at this point already?\n\n> cd foo && git push && cd ..\n\n\"git push\" never touches the work tree.  It is possible that\nthere is a PEBCAK hook enabled in that bare repository that\ncreates random files upon receiving a push, but that is hardly\nworth reporting _here_ on the list ;-).\n\nPuzzled...\n"},{"id":"64249","messageId":"46dff0320712302302p4c125ee1n2abc1561ba10c47e@mail.gmail.com","threadId":"11434","inReplyTo":"20071231064741.GA4250@coredump.intra.peff.net","subject":"Re: [bug] Working files created in bare repository when pushing to a rewound bare repository","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2007-12-31T07:02:25Z","receivedAt":"2007-12-31T07:02:25Z","isPatch":false,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"On Dec 31, 2007 2:47 PM, Jeff King <peff@peff.net> wrote:\n> On Mon, Dec 31, 2007 at 02:42:42PM +0800, Ping Yin wrote:\n>\n> > Following scripts can reproduce the problem: in the final line,\n> > foo.txt is generated in bare foo.git\n>\n> No, your script is wrong.\n>\n> > # create bare foo.git and its clone foo\n> > mkdir foo\n> > cd foo && echo foo>foo.txt &&\n> > git init && git add . && git commit -m 'create project foo' && cd ..\n> > cd foo && echo foo1>foo.txt && git commit -a -m \"update foo.txt\" && cd ..\n> > git clone --bare foo foo.git && rm -rf foo\n> > git clone foo.git foo\n> >\n> > # reset bare and then push\n> > cd foo.git && git reset --hard HEAD^ && cd ..\n>\n> Try looking in foo.git after this step. The \"--hard\" to git-reset is\n> creating the file foo.txt. --hard makes no sense in a bare repository (I\n> thought we were disallowing it, but apparently not).\n>\n\nSorry for my inattention. However, i remembered the reason i added\n'--hard' is to avoid  the warn 'foo.txt: needs update'  when 'git\nreset HEAD^'. Now i know  '--soft' will do the right thing.\n\nSo how about use '--soft' as default in the bare repository?\n\n\n\n-- \nPing Yin\n"},{"id":"64250","messageId":"20071231070749.GB4250@coredump.intra.peff.net","threadId":"11434","inReplyTo":"46dff0320712302302p4c125ee1n2abc1561ba10c47e@mail.gmail.com","subject":"Re: [bug] Working files created in bare repository when pushing to a rewound bare repository","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-12-31T07:07:50Z","receivedAt":"2007-12-31T07:07:50Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Dec 31, 2007 at 03:02:25PM +0800, Ping Yin wrote:\n\n> Sorry for my inattention. However, i remembered the reason i added\n> '--hard' is to avoid  the warn 'foo.txt: needs update'  when 'git\n> reset HEAD^'. Now i know  '--soft' will do the right thing.\n> \n> So how about use '--soft' as default in the bare repository?\n\nI started on this when I realized that --soft doesn't even work. I\nremember posting a patch to make --soft work in a bare repo when\ngit-reset was still a script. However, Junio indicated that using \"git\nbranch -f\" is the recommended workflow. Perhaps git-reset should be\ndisabled in bare repos totally?\n\n-Peff\n"},{"id":"64251","messageId":"20071231071352.GC4250@coredump.intra.peff.net","threadId":"11434","inReplyTo":"20071231070749.GB4250@coredump.intra.peff.net","subject":"Re: [bug] Working files created in bare repository when pushing to a rewound bare repository","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-12-31T07:13:52Z","receivedAt":"2007-12-31T07:13:52Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Dec 31, 2007 at 02:07:50AM -0500, Jeff King wrote:\n\n> I started on this when I realized that --soft doesn't even work. I\n\nEr, sorry, I'm somehow incompetent and failed to perform my test\ncorrectly. --soft does work. I think the following is probably worth\ndoing.\n\n-- >8 --\ngit-reset: refuse to do hard reset in a bare repository\n\nIt makes no sense since there is no working tree. A soft\nreset should be fine, though.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n builtin-reset.c       |    3 +++\n t/t7103-reset-bare.sh |   28 ++++++++++++++++++++++++++++\n 2 files changed, 31 insertions(+), 0 deletions(-)\n create mode 100755 t/t7103-reset-bare.sh\n\ndiff --git a/builtin-reset.c b/builtin-reset.c\nindex 713c2d5..10dba60 100644\n--- a/builtin-reset.c\n+++ b/builtin-reset.c\n@@ -244,6 +244,9 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \tif (reset_type == NONE)\n \t\treset_type = MIXED; /* by default */\n \n+\tif (reset_type == HARD && is_bare_repository())\n+\t\tdie(\"hard reset makes no sense in a bare repository\");\n+\n \t/* Soft reset does not touch the index file nor the working tree\n \t * at all, but requires them in a good order.  Other resets reset\n \t * the index file to the tree object we are switching to. */\ndiff --git a/t/t7103-reset-bare.sh b/t/t7103-reset-bare.sh\nnew file mode 100755\nindex 0000000..333d5ea\n--- /dev/null\n+++ b/t/t7103-reset-bare.sh\n@@ -0,0 +1,28 @@\n+#!/bin/sh\n+\n+test_description='git-reset in a bare repository'\n+. ./test-lib.sh\n+\n+test_expect_success 'setup non-bare' '\n+\techo one >file &&\n+\tgit add file &&\n+\tgit commit -m one\n+\techo two >file &&\n+\tgit commit -a -m two\n+'\n+\n+test_expect_success 'setup bare' '\n+\tgit clone --bare . bare.git &&\n+\tcd bare.git\n+'\n+\n+test_expect_success 'hard reset is not allowed' '\n+\t! git reset --hard HEAD^\n+'\n+\n+test_expect_success 'soft reset is allowed' '\n+\tgit reset --soft HEAD^ &&\n+\ttest \"`git show --pretty=format:%s | head -n 1`\" = \"one\"\n+'\n+\n+test_done\n-- \n1.5.4.rc2.1101.g236e-dirty\n"},{"id":"64252","messageId":"20071231071943.GA10293@coredump.intra.peff.net","threadId":"11434","inReplyTo":"20071231071352.GC4250@coredump.intra.peff.net","subject":"Re: [bug] Working files created in bare repository when pushing to a rewound bare repository","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-12-31T07:19:43Z","receivedAt":"2007-12-31T07:19:43Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Dec 31, 2007 at 02:13:52AM -0500, Jeff King wrote:\n\n> +test_expect_success 'setup non-bare' '\n> +\techo one >file &&\n> +\tgit add file &&\n> +\tgit commit -m one\n\nThis is of course missing a && at the end.\n\n-Peff\n"},{"id":"64253","messageId":"20071231072632.GA11451@coredump.intra.peff.net","threadId":"11434","inReplyTo":"20071231071352.GC4250@coredump.intra.peff.net","subject":"Re: [bug] Working files created in bare repository when pushing to a rewound bare repository","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-12-31T07:26:32Z","receivedAt":"2007-12-31T07:26:32Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Dec 31, 2007 at 02:13:52AM -0500, Jeff King wrote:\n\n> git-reset: refuse to do hard reset in a bare repository\n> \n> It makes no sense since there is no working tree. A soft\n> reset should be fine, though.\n\nAnd then on top of this (plus one-liner fix I posted), as Ping Yin\nsuggested, we can do:\n\n-- >8 --\ngit-reset: default to --soft in a bare repo\n\n--mixed doesn't make sense, since we don't generally have an\nindex.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nThis is a bit more contentious. There's no reason you can't have an\nindex in a bare repo, and this is changing the behavior of those who do.\nThey can always explicitly specify --mixed (since we haven't disallowed\nthat), but it might break some scripts.\n\n builtin-reset.c       |    2 +-\n t/t7103-reset-bare.sh |    9 ++++++++-\n 2 files changed, 9 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-reset.c b/builtin-reset.c\nindex 10dba60..44e4eb4 100644\n--- a/builtin-reset.c\n+++ b/builtin-reset.c\n@@ -242,7 +242,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \t\treturn read_from_tree(prefix, argv + i, sha1);\n \t}\n \tif (reset_type == NONE)\n-\t\treset_type = MIXED; /* by default */\n+\t\treset_type = is_bare_repository() ? SOFT : MIXED;\n \n \tif (reset_type == HARD && is_bare_repository())\n \t\tdie(\"hard reset makes no sense in a bare repository\");\ndiff --git a/t/t7103-reset-bare.sh b/t/t7103-reset-bare.sh\nindex b25a77f..c2cdba4 100755\n--- a/t/t7103-reset-bare.sh\n+++ b/t/t7103-reset-bare.sh\n@@ -7,8 +7,10 @@ test_expect_success 'setup non-bare' '\n \techo one >file &&\n \tgit add file &&\n \tgit commit -m one &&\n+\tgit tag one &&\n \techo two >file &&\n-\tgit commit -a -m two\n+\tgit commit -a -m two &&\n+\tgit tag two\n '\n \n test_expect_success 'setup bare' '\n@@ -25,4 +27,9 @@ test_expect_success 'soft reset is allowed' '\n \ttest \"`git show --pretty=format:%s | head -n 1`\" = \"one\"\n '\n \n+test_expect_success 'default to soft reset' '\n+\tgit reset two &&\n+\ttest \"`git show --pretty=format:%s | head -n 1`\" = \"two\"\n+'\n+\n test_done\n-- \n1.5.4.rc2.1102.g4735f-dirty\n"},{"id":"64397","messageId":"7v3atepph1.fsf@gitster.siamese.dyndns.org","threadId":"11434","inReplyTo":"20071231072632.GA11451@coredump.intra.peff.net","subject":"Re: [bug] Working files created in bare repository when pushing to a rewound bare repository","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-01-03T21:29:46Z","receivedAt":"2008-01-03T21:29:46Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> And then on top of this (plus one-liner fix I posted), as Ping Yin\n> suggested, we can do:\n>\n> -- >8 --\n> git-reset: default to --soft in a bare repo\n>\n> --mixed doesn't make sense, since we don't generally have an\n> index.\n>\n> Signed-off-by: Jeff King <peff@peff.net>\n> ---\n> This is a bit more contentious. There's no reason you can't have an\n> index in a bare repo, and this is changing the behavior of those who do.\n> They can always explicitly specify --mixed (since we haven't disallowed\n> that), but it might break some scripts.\n\nI'd prefer to error out if something does not make sense rather\nthan defaulting differently depending on the bareness of the\nrepository, but that is probably the matter of taste.\n\nPlease re-raise the issue post 1.5.4\n"}]}