reset: allow the caller to specify the current HEAD object

When calling `reset_working_tree()` we automatically derive the commit that the callers wants to move from by reading the HEAD commit. Some callers may already have resolved it, or they may want to move from a different commit that doesn't match HEAD. Introduce a new `oid_from` option that lets the caller specify the commit. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jul 1, 2026 at 13:35 UTC 1280e92d1622484c97facb840f2788166171d460
2 files changed +9 -1
reset.c
+4 -1
@@ -122,7 +122,10 @@ int reset_working_tree(struct repository *r,
122 goto leave_reset_head;
123 }
124
125 - if (!repo_get_oid(r, "HEAD", &head_oid)) {
125 + if (opts->oid_from) {
126 + oidcpy(&head_oid, opts->oid_from);
127 + head = &head_oid;
128 + } else if (!repo_get_oid(r, "HEAD", &head_oid)) {
129 head = &head_oid;
130 } else if (!oid || !reset_hard) {
131 ret = error(_("could not determine HEAD revision"));
reset.h
+5
@@ -37,6 +37,11 @@ struct reset_working_tree_options {
37 * The commit to checkout/reset to. Defaults to HEAD.
38 */
39 const struct object_id *oid;
40 + /*
41 + * The commit to checkout/reset from when doing a two-way merge. This
42 + * is used as one of the sides to merge.
43 + */
44 + const struct object_id *oid_from;
45 /*
46 * Optional value to set ORIG_HEAD. Defaults to HEAD.
47 */