aboutsummaryrefslogtreecommitdiffstats
path: root/refs/files-backend.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-06-20 15:45:11 -0700
committerJunio C Hamano <gitster@pobox.com>2024-06-20 15:45:12 -0700
commit5f14d2098478cc96251b52d812c5a3ebc3e03a42 (patch)
tree6d2e5ad5e0c0649cb863490ca5c73e4c1e076043 /refs/files-backend.c
parentMerge branch 'gt/unit-test-oidtree' (diff)
parentupdate-ref: add support for 'symref-update' command (diff)
downloadgit-5f14d2098478cc96251b52d812c5a3ebc3e03a42.tar.gz
git-5f14d2098478cc96251b52d812c5a3ebc3e03a42.zip
Merge branch 'kn/update-ref-symref'
"git update-ref --stdin" learned to handle transactional updates of symbolic-refs. * kn/update-ref-symref: update-ref: add support for 'symref-update' command reftable: pick either 'oid' or 'target' for new updates update-ref: add support for 'symref-create' command update-ref: add support for 'symref-delete' command update-ref: add support for 'symref-verify' command refs: specify error for regular refs with `old_target` refs: create and use `ref_update_expects_existing_old_ref()`
Diffstat (limited to 'refs/files-backend.c')
-rw-r--r--refs/files-backend.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 4519b46171..44c5c3b201 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2457,8 +2457,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
struct strbuf *err)
{
struct strbuf referent = STRBUF_INIT;
- int mustexist = (update->flags & REF_HAVE_OLD) &&
- !is_null_oid(&update->old_oid);
+ int mustexist = ref_update_expects_existing_old_ref(update);
int ret = 0;
struct ref_lock *lock;
@@ -2537,14 +2536,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;