]> git.ipfire.org Git - thirdparty/git.git/commitdiff
refs: specify error for regular refs with `old_target`
authorKarthik Nayak <karthik.188@gmail.com>
Fri, 7 Jun 2024 13:32:59 +0000 (15:32 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Jun 2024 17:25:44 +0000 (10:25 -0700)
When a reference update tries to update a symref, but the ref in
question is actually a regular ref, we raise an error. However the error
raised in this situation is:

  verifying symref target: '<ref>': reference is missing but expected <old-target>

which is very generic and doesn't indicate the mismatch of types. Let's
make this error more specific:

  cannot lock ref '<ref>': expected symref with target '<old-target>': but is a regular ref

so that users have a clearer understanding.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs/files-backend.c
refs/reftable-backend.c

index ef760869ca65ea9cbb7995c13331f2b16fb708a1..d6f37963bc867cad2531cd1a07e9971e74dcd1f1 100644 (file)
@@ -2490,14 +2490,16 @@ static int lock_ref_for_update(struct files_ref_store *refs,
 
                /*
                 * Even if the ref is a regular ref, if `old_target` is set, we
-                * check the referent value. Ideally `old_target` should only
-                * be set for symrefs, but we're strict about its usage.
+                * fail with an error.
                 */
                if (update->old_target) {
-                       if (ref_update_check_old_target(referent.buf, update, err)) {
-                               ret = TRANSACTION_GENERIC_ERROR;
-                               goto out;
-                       }
+                       strbuf_addf(err, _("cannot lock ref '%s': "
+                                          "expected symref with target '%s': "
+                                          "but is a regular ref"),
+                                   ref_update_original_update_refname(update),
+                                   update->old_target);
+                       ret = TRANSACTION_GENERIC_ERROR;
+                       goto out;
                } else if  (check_old_oid(update, &lock->old_oid, err)) {
                        ret = TRANSACTION_GENERIC_ERROR;
                        goto out;
index 019b99181d9a9bb031b7a5d55ccf100b1da2d9e2..16f4ced7b65f612f50f02a38d441729ae9941be8 100644 (file)
@@ -931,6 +931,16 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
                 * backend returns, which keeps our tests happy.
                 */
                if (u->old_target) {
+                       if (!(u->type & REF_ISSYMREF)) {
+                               strbuf_addf(err, _("cannot lock ref '%s': "
+                                          "expected symref with target '%s': "
+                                          "but is a regular ref"),
+                                           ref_update_original_update_refname(u),
+                                           u->old_target);
+                               ret = -1;
+                               goto done;
+                       }
+
                        if (ref_update_check_old_target(referent.buf, u, err)) {
                                ret = -1;
                                goto done;