[PATCH v3 5/9] reset: introduce ability to skip reference updates
From: Patrick Steinhardt <hidden>
Date: 2026-06-08 10:23:45
Subsystem:
the rest · Maintainer:
Linus Torvalds
In a subsequent commit we'll introduce a new caller to `reset_head()` that really only wants to update the index and working tree, without updating any references. Introduce a new flag that lets the caller perform this operation. Signed-off-by: Patrick Steinhardt <redacted> --- reset.c | 7 ++++++- reset.h | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/reset.c b/reset.c
index 8fb39d4c51..f88f32d563 100644
--- a/reset.c
+++ b/reset.c@@ -93,6 +93,7 @@ int reset_head(struct repository *r, const struct reset_head_opts *opts) unsigned refs_only = opts->flags & RESET_HEAD_REFS_ONLY; unsigned update_orig_head = opts->flags & RESET_HEAD_UPDATE_ORIG_HEAD; unsigned dry_run = opts->flags & RESET_HEAD_DRY_RUN; + unsigned skip_ref_updates = opts->flags & RESET_HEAD_SKIP_REF_UPDATES; struct object_id *head = NULL, head_oid; struct tree_desc desc[2] = { { NULL }, { NULL } }; struct lock_file lock = LOCK_INIT;
@@ -112,6 +113,9 @@ int reset_head(struct repository *r, const struct reset_head_opts *opts) if (opts->branch_msg && !opts->branch) BUG("branch reflog message given without a branch"); + if (skip_ref_updates && (opts->branch || refs_only || update_orig_head)) + BUG("asked to perform ref updates and skip them at the same time"); + if (!refs_only && !dry_run && repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) { ret = -1; goto leave_reset_head;
@@ -196,7 +200,8 @@ int reset_head(struct repository *r, const struct reset_head_opts *opts) goto leave_reset_head; } - if (oid != &head_oid || update_orig_head || switch_to_branch) + if (!skip_ref_updates && + (oid != &head_oid || update_orig_head || switch_to_branch)) ret = update_refs(r, opts, oid, head); leave_reset_head:
diff --git a/reset.h b/reset.h
index cc9fd4378a..d2f8546844 100644
--- a/reset.h
+++ b/reset.h@@ -27,6 +27,9 @@ enum reset_head_flags { * any user-visible state. */ RESET_HEAD_DRY_RUN = (1 << 5), + + /* Skip updating any references, only update the worktree and index. */ + RESET_HEAD_SKIP_REF_UPDATES = (1 << 6), }; struct reset_head_opts {
--
2.54.0.1136.gdb2ca164c4.dirty