]> git.ipfire.org Git - thirdparty/git.git/commitdiff
reset: allow the caller to specify the current HEAD object
authorPatrick Steinhardt <ps@pks.im>
Wed, 1 Jul 2026 11:35:34 +0000 (13:35 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 3 Jul 2026 17:32:47 +0000 (10:32 -0700)
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>
reset.c
reset.h

diff --git a/reset.c b/reset.c
index 490194380e603089dc3814841b80cf41fc6d080b..c1538cac1678f792543e602b338d42a08d8bbf9d 100644 (file)
--- a/reset.c
+++ b/reset.c
@@ -122,7 +122,10 @@ int reset_working_tree(struct repository *r,
                goto leave_reset_head;
        }
 
-       if (!repo_get_oid(r, "HEAD", &head_oid)) {
+       if (opts->oid_from) {
+               oidcpy(&head_oid, opts->oid_from);
+               head = &head_oid;
+       } else if (!repo_get_oid(r, "HEAD", &head_oid)) {
                head = &head_oid;
        } else if (!oid || !reset_hard) {
                ret = error(_("could not determine HEAD revision"));
diff --git a/reset.h b/reset.h
index 38b2891b53785f79d78b394bafac89c010a65863..4c992ba671c7f16be708288a65b2f25248b06f3a 100644 (file)
--- a/reset.h
+++ b/reset.h
@@ -37,6 +37,11 @@ struct reset_working_tree_options {
         * The commit to checkout/reset to. Defaults to HEAD.
         */
        const struct object_id *oid;
+       /*
+        * The commit to checkout/reset from when doing a two-way merge. This
+        * is used as one of the sides to merge.
+        */
+       const struct object_id *oid_from;
        /*
         * Optional value to set ORIG_HEAD. Defaults to HEAD.
         */