aboutsummaryrefslogtreecommitdiffstats
path: root/refs/reftable-backend.c
diff options
context:
space:
mode:
authorKarthik Nayak <karthik.188@gmail.com>2024-04-23 23:28:14 +0200
committerJunio C Hamano <gitster@pobox.com>2024-04-25 10:02:11 -0700
commitadac361761d3a2f9a81a1f7e60709723a7caaca8 (patch)
treef27fe8eb9e8f649edd681b493e8ef77368b310c4 /refs/reftable-backend.c
parentfiles-backend: extract out `create_symref_lock` (diff)
downloadgit-adac361761d3a2f9a81a1f7e60709723a7caaca8.tar.xz
git-adac361761d3a2f9a81a1f7e60709723a7caaca8.zip
update-ref: support symrefs in the verify command
In the previous commits, we added the required base for adding symref support to the transaction commands provided by 'git-update-ref(1)'. Using them, extend the 'verify' command to support symrefs. The 'verify' command allows users to verify if a provided symbolic reference `<ref>` contains the provided `<old-oid>` without changing the `<ref>`. Now we alternatively allow users to provide a `ref:<old-target>` instead to verify if a symref targets the provided target. Since we're checking for symbolic refs, this will only work with the 'no-deref' mode. This is because any dereferenced symbolic ref will point to an object and not a ref. Add and use `null_new_value`, a helper function which is used to check if there is a new_value in a reference update. The new value could either be a symref target `new_target` or a OID `new_oid`. We also add tests to test the command in both the regular stdin mode and also with the '-z' flag. We also disable the reference-transaction hook for symref-updates which will be tackled in its own commit. Add required tests for symref support in 'verify' while also adding reflog checks for the pre-existing 'verify' tests. Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs/reftable-backend.c')
-rw-r--r--refs/reftable-backend.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index e6122837c0a..754f413ea45 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -935,7 +935,26 @@ static int reftable_be_transaction_prepare(struct ref_store *ref_store,
* individual refs. But the error messages match what the files
* backend returns, which keeps our tests happy.
*/
- if (u->flags & REF_HAVE_OLD && !oideq(&current_oid, &u->old_oid)) {
+ if ((u->flags & REF_HAVE_OLD) && u->old_target) {
+ if (strcmp(referent.buf, u->old_target)) {
+ if (!strcmp(u->old_target, ""))
+ strbuf_addf(err, "verifying symref target: '%s': "
+ "provided target is empty",
+ original_update_refname(u));
+ else if (!strcmp(referent.buf, ""))
+ strbuf_addf(err, "verifying symref target: '%s': "
+ "reference is missing but expected %s",
+ original_update_refname(u),
+ u->old_target);
+ else
+ strbuf_addf(err, "verifying symref target: '%s': "
+ "is at %s but expected %s",
+ original_update_refname(u),
+ referent.buf, u->old_target);
+ ret = -1;
+ goto done;
+ }
+ } else if (u->flags & REF_HAVE_OLD && !oideq(&current_oid, &u->old_oid)) {
if (is_null_oid(&u->old_oid))
strbuf_addf(err, _("cannot lock ref '%s': "
"reference already exists"),