diff options
author | Michael Haggerty <mhagger@alum.mit.edu> | 2014-12-11 00:47:52 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-12-11 11:56:53 -0800 |
commit | 0e729c7ed5b3c0c6be38bf8d8405b1b7f5a74a3f (patch) | |
tree | cfa87ef159e1839d622ce73648a4b0182f24bd0a /builtin/update-ref.c | |
parent | a46e41fca301be48130cca80b45027eff328903d (diff) | |
download | git-0e729c7ed5b3c0c6be38bf8d8405b1b7f5a74a3f.tar.gz |
update-ref: fix "verify" command with missing <oldvalue>mh/update-ref-verify
If "git update-ref --stdin" was given a "verify" command with no
"<newvalue>" at all (not even zeros), the code was mistakenly setting
have_old=0 (and leaving old_sha1 uninitialized). But this is
incorrect: this command is supposed to verify that the reference
doesn't exist. So in this case we really need old_sha1 to be set to
null_sha1 and have_old to be set to 1.
Moreover, since have_old was being set to zero, *no* check of the old
value was being done, so the new value of the reference was being set
unconditionally to the value in new_sha1. new_sha1, in turn, was set
to null_sha1 in the expectation that that was the old value and it
shouldn't be changed. But because the precondition was not being
checked, the result was that the reference was being deleted
unconditionally.
So, if <oldvalue> is missing, set have_old unconditionally and set
old_sha1 to null_sha1.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Acked-by: Brad King <brad.king@kitware.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/update-ref.c')
-rw-r--r-- | builtin/update-ref.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 6c9be05128..1993529521 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -282,26 +282,22 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction, char *refname; unsigned char new_sha1[20]; unsigned char old_sha1[20]; - int have_old; refname = parse_refname(input, &next); if (!refname) die("verify: missing <ref>"); if (parse_next_sha1(input, &next, old_sha1, "verify", refname, - PARSE_SHA1_OLD)) { - hashclr(new_sha1); - have_old = 0; - } else { - hashcpy(new_sha1, old_sha1); - have_old = 1; - } + PARSE_SHA1_OLD)) + hashclr(old_sha1); + + hashcpy(new_sha1, old_sha1); if (*next != line_termination) die("verify %s: extra input: %s", refname, next); if (ref_transaction_update(transaction, refname, new_sha1, old_sha1, - update_flags, have_old, msg, &err)) + update_flags, 1, msg, &err)) die("%s", err.buf); update_flags = 0; |