{"thread":{"id":"36337","subject":"[PATCH] update-ref: fail create operation over stdin if ref already exists","startedAt":"2014-04-02T08:09:54Z","lastAt":"2014-04-03T13:20:30Z","messageCount":3,"participants":["Michael Haggerty","Brad King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"238287","messageId":"1396426194-3292-1-git-send-email-mhagger@alum.mit.edu","threadId":"36337","inReplyTo":null,"subject":"[PATCH] update-ref: fail create operation over stdin if ref already exists","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2014-04-02T08:09:54Z","receivedAt":"2014-04-02T08:09:54Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"From: Aman Gupta <aman@tmm1.net>\n\nSigned-off-by: Aman Gupta <aman@tmm1.net>\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\nMy colleague Aman ran across this bug and wrote the fix.  I didn't\nnotice this bug, but I just verified that it is also fixed by my\nmh/ref-transaction patch series (albeit without a test case).\n\nBecause the bug could cause somebody to overwrite a reference\nunintentionally, I propose that we apply this unintrusive fix to\nmaint.  When mh/ref-transaction makes it to a release, the bug will\ncontinue to be fixed, but in a different way.\n\n builtin/update-ref.c  |  1 +\n t/t1400-update-ref.sh | 11 +++++++++++\n 2 files changed, 12 insertions(+)\n\ndiff --git a/builtin/update-ref.c b/builtin/update-ref.c\nindex 1292cfe..5c208bb 100644\n--- a/builtin/update-ref.c\n+++ b/builtin/update-ref.c\n@@ -147,6 +147,7 @@ static void parse_cmd_create(const char *next)\n \tstruct ref_update *update;\n \n \tupdate = update_alloc();\n+\tupdate->have_old = 1;\n \n \tif ((next = parse_first_arg(next, &ref)) != NULL && ref.buf[0])\n \t\tupdate_store_ref_name(update, ref.buf);\ndiff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh\nindex 6ffd82f..e130c52 100755\n--- a/t/t1400-update-ref.sh\n+++ b/t/t1400-update-ref.sh\n@@ -820,7 +820,18 @@ test_expect_success 'stdin -z update ref fails with bad old value' '\n \ttest_must_fail git rev-parse --verify -q $c\n '\n \n+test_expect_success 'stdin -z create ref fails when ref exists' '\n+\tgit update-ref $c $m &&\n+\tgit rev-parse \"$c\" >expect &&\n+\tprintf $F \"create $c\" \"$m~1\" >stdin &&\n+\ttest_must_fail git update-ref -z --stdin <stdin 2>err &&\n+\tgrep \"fatal: Cannot lock the ref '\"'\"'$c'\"'\"'\" err &&\n+\tgit rev-parse \"$c\" >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'stdin -z create ref fails with bad new value' '\n+\tgit update-ref -d \"$c\" &&\n \tprintf $F \"create $c\" \"does-not-exist\" >stdin &&\n \ttest_must_fail git update-ref -z --stdin <stdin 2>err &&\n \tgrep \"fatal: invalid new value for ref $c: does-not-exist\" err &&\n-- \n1.9.0\n"},{"id":"238333","messageId":"533C092B.1050801@kitware.com","threadId":"36337","inReplyTo":"1396426194-3292-1-git-send-email-mhagger@alum.mit.edu","subject":"Re: [PATCH] update-ref: fail create operation over stdin if ref already exists","fromName":"Brad King","fromEmail":"brad.king@kitware.com","sentAt":"2014-04-02T12:57:15Z","receivedAt":"2014-04-02T12:57:15Z","isPatch":true,"sender":{"key":"brad.king@kitware.com","avatar":"https://avatars.githubusercontent.com/u/87268?v=4"},"body":"On 04/02/2014 04:09 AM, Michael Haggerty wrote:\n> From: Aman Gupta <aman@tmm1.net>\n[snip]\n> @@ -147,6 +147,7 @@ static void parse_cmd_create(const char *next)\n>  \tstruct ref_update *update;\n>  \n>  \tupdate = update_alloc();\n> +\tupdate->have_old = 1;\n\nLooks good.\n\n> +test_expect_success 'stdin -z create ref fails when ref exists' '\n\nStrictly speaking we should have a non-z mode test too.\n\nThanks,\n-Brad\n"},{"id":"238348","messageId":"533D601E.8020301@alum.mit.edu","threadId":"36337","inReplyTo":"533C092B.1050801@kitware.com","subject":"Re: [PATCH] update-ref: fail create operation over stdin if ref already exists","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2014-04-03T13:20:30Z","receivedAt":"2014-04-03T13:20:30Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 04/02/2014 02:57 PM, Brad King wrote:\n> On 04/02/2014 04:09 AM, Michael Haggerty wrote:\n>> From: Aman Gupta <aman@tmm1.net>\n> [snip]\n>> @@ -147,6 +147,7 @@ static void parse_cmd_create(const char *next)\n>>  \tstruct ref_update *update;\n>>  \n>>  \tupdate = update_alloc();\n>> +\tupdate->have_old = 1;\n> \n> Looks good.\n> \n>> +test_expect_success 'stdin -z create ref fails when ref exists' '\n> \n> Strictly speaking we should have a non-z mode test too.\n\nThis code path is used regardless of whether -z is used, so I don't\nthink it is necessary to duplicate the test.\n\nMichael\n\n-- \nMichael Haggerty\nmhagger@alum.mit.edu\nhttp://softwareswirl.blogspot.com/\n"}]}