diff options
author | Junio C Hamano <gitster@pobox.com> | 2018-05-30 08:04:08 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-05-30 08:04:08 +0300 |
commit | 26597cb0cceb82b315c543f1cc02bbb72c537eaa (patch) | |
tree | 99051d4931818a123a6123bbcb6cfe6f512d6586 /refs.c | |
parent | cf315793c1ef90788470438a7ef8dc281ea97806 (diff) | |
parent | db0210d445963e5d85f98e48d6a93b971779d449 (diff) |
Merge branch 'ma/create-pseudoref-with-null-old-oid'
"git update-ref A B" is supposed to ensure that ref A does not yet
exist when B is a NULL OID, but this check was not done correctly
for pseudo-refs outside refs/ hierarchy, e.g. MERGE_HEAD.
* ma/create-pseudoref-with-null-old-oid:
refs: handle zero oid for pseudorefs
t1400: add tests around adding/deleting pseudorefs
refs.c: refer to "object ID", not "sha1", in error messages
Diffstat (limited to 'refs.c')
-rw-r--r-- | refs.c | 22 |
1 files changed, 17 insertions, 5 deletions
@@ -681,10 +681,21 @@ static int write_pseudoref(const char *pseudoref, const struct object_id *oid, if (old_oid) { struct object_id actual_old_oid; - if (read_ref(pseudoref, &actual_old_oid)) - die("could not read ref '%s'", pseudoref); - if (oidcmp(&actual_old_oid, old_oid)) { - strbuf_addf(err, "unexpected sha1 when writing '%s'", pseudoref); + if (read_ref(pseudoref, &actual_old_oid)) { + if (!is_null_oid(old_oid)) { + strbuf_addf(err, "could not read ref '%s'", + pseudoref); + rollback_lock_file(&lock); + goto done; + } + } else if (is_null_oid(old_oid)) { + strbuf_addf(err, "ref '%s' already exists", + pseudoref); + rollback_lock_file(&lock); + goto done; + } else if (oidcmp(&actual_old_oid, old_oid)) { + strbuf_addf(err, "unexpected object ID when writing '%s'", + pseudoref); rollback_lock_file(&lock); goto done; } @@ -725,7 +736,8 @@ static int delete_pseudoref(const char *pseudoref, const struct object_id *old_o if (read_ref(pseudoref, &actual_old_oid)) die("could not read ref '%s'", pseudoref); if (oidcmp(&actual_old_oid, old_oid)) { - warning("Unexpected sha1 when deleting %s", pseudoref); + error("unexpected object ID when deleting '%s'", + pseudoref); rollback_lock_file(&lock); return -1; } |