Skip to content

Commit 9ddd5b8

Browse files
pks-tgitster
authored andcommitted
t: allow skipping expected object ID in ref-store update-ref
We require the caller to pass both the old and new expected object ID to our `test-tool ref-store update-ref` helper. When trying to update a symbolic reference though it's impossible to specify the expected object ID, which means that the test would instead have to force-update the reference. This is currently impossible though. Update the helper to optionally skip verification of the old object ID in case the test passes in an empty old object ID as input. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d5dbad0 commit 9ddd5b8

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

t/helper/test-ref-store.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,16 +298,19 @@ static int cmd_update_ref(struct ref_store *refs, const char **argv)
298298
const char *new_sha1_buf = notnull(*argv++, "new-sha1");
299299
const char *old_sha1_buf = notnull(*argv++, "old-sha1");
300300
unsigned int flags = arg_flags(*argv++, "flags", transaction_flags);
301-
struct object_id old_oid;
301+
struct object_id old_oid, *old_oid_ptr = NULL;
302302
struct object_id new_oid;
303303

304-
if (get_oid_hex(old_sha1_buf, &old_oid))
305-
die("cannot parse %s as %s", old_sha1_buf, the_hash_algo->name);
304+
if (*old_sha1_buf) {
305+
if (get_oid_hex(old_sha1_buf, &old_oid))
306+
die("cannot parse %s as %s", old_sha1_buf, the_hash_algo->name);
307+
old_oid_ptr = &old_oid;
308+
}
306309
if (get_oid_hex(new_sha1_buf, &new_oid))
307310
die("cannot parse %s as %s", new_sha1_buf, the_hash_algo->name);
308311

309312
return refs_update_ref(refs, msg, refname,
310-
&new_oid, &old_oid,
313+
&new_oid, old_oid_ptr,
311314
flags, UPDATE_REFS_DIE_ON_ERR);
312315
}
313316

0 commit comments

Comments
 (0)