reset: rename `reset_head()`

In a subsequent commit we're about to adapt `reset_head()` so that the reference update to HEAD is optional, only. At this point the function starts to feel misnamed, as it doesn't necessarily have anything to do with the HEAD reference anymore. The gist of the function then is that we reset the working tree to a specific new commit, updating both the index and the checked-out files. Rename it to `reset_working_tree()` to better reflect that. Note that we don't adjust the flags yet. This will happen in a subsequent commit. Suggested-by: Phillip Wood <phillip.wood123@gmail.com> 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 9762e2faf7c7f6781df3b07ed1a56f1b4b99b53c
4 files changed +19 -18
builtin/rebase.c
+10 -10
@@ -592,7 +592,7 @@ static int finish_rebase(struct rebase_options *opts)
592 static int move_to_original_branch(struct rebase_options *opts)
593 {
594 struct strbuf branch_reflog = STRBUF_INIT, head_reflog = STRBUF_INIT;
595 - struct reset_head_opts ropts = { 0 };
595 + struct reset_working_tree_options ropts = { 0 };
596 int ret;
597
598 if (!opts->head_name)
@@ -610,7 +610,7 @@ static int move_to_original_branch(struct rebase_options *opts)
610 ropts.flags = RESET_HEAD_REFS_ONLY;
611 ropts.branch_msg = branch_reflog.buf;
612 ropts.head_msg = head_reflog.buf;
613 - ret = reset_head(the_repository, &ropts);
613 + ret = reset_working_tree(the_repository, &ropts);
614
615 strbuf_release(&branch_reflog);
616 strbuf_release(&head_reflog);
@@ -685,7 +685,7 @@ static int run_am(struct rebase_options *opts)
685
686 status = run_command(&format_patch);
687 if (status) {
688 - struct reset_head_opts ropts = { 0 };
688 + struct reset_working_tree_options ropts = { 0 };
689 unlink(rebased_patches);
690 free(rebased_patches);
691 child_process_clear(&am);
@@ -693,7 +693,7 @@ static int run_am(struct rebase_options *opts)
693 ropts.oid = &opts->orig_head->object.oid;
694 ropts.branch = opts->head_name;
695 ropts.default_reflog_action = opts->reflog_action;
696 - reset_head(the_repository, &ropts);
696 + reset_working_tree(the_repository, &ropts);
697 error(_("\ngit encountered an error while preparing the "
698 "patches to replay\n"
699 "these revisions:\n"
@@ -855,7 +855,7 @@ static int rebase_config(const char *var, const char *value,
855 static int checkout_up_to_date(struct rebase_options *options)
856 {
857 struct strbuf buf = STRBUF_INIT;
858 - struct reset_head_opts ropts = { 0 };
858 + struct reset_working_tree_options ropts = { 0 };
859 int ret = 0;
860
861 strbuf_addf(&buf, "%s: checkout %s",
@@ -866,7 +866,7 @@ static int checkout_up_to_date(struct rebase_options *options)
866 if (!ropts.branch)
867 ropts.flags |= RESET_HEAD_DETACH;
868 ropts.head_msg = buf.buf;
869 - if (reset_head(the_repository, &ropts) < 0)
869 + if (reset_working_tree(the_repository, &ropts) < 0)
870 ret = error(_("could not switch to %s"), options->switch_to);
871 strbuf_release(&buf);
872
@@ -1116,7 +1116,7 @@ int cmd_rebase(int argc,
1116 int reschedule_failed_exec = -1;
1117 int allow_preemptive_ff = 1;
1118 int preserve_merges_selected = 0;
1119 - struct reset_head_opts ropts = { 0 };
1119 + struct reset_working_tree_options ropts = { 0 };
1120 struct option builtin_rebase_options[] = {
1121 OPT_STRING(0, "onto", &options.onto_name,
1122 N_("revision"),
@@ -1385,7 +1385,7 @@ int cmd_rebase(int argc,
1385 rerere_clear(the_repository, &merge_rr);
1386 string_list_clear(&merge_rr, 1);
1387 ropts.flags = RESET_HEAD_HARD;
1388 - if (reset_head(the_repository, &ropts) < 0)
1388 + if (reset_working_tree(the_repository, &ropts) < 0)
1389 die(_("could not discard worktree changes"));
1390 remove_branch_state(the_repository, 0);
1391 if (read_basic_state(&options))
@@ -1410,7 +1410,7 @@ int cmd_rebase(int argc,
1410 ropts.head_msg = head_msg.buf;
1411 ropts.branch = options.head_name;
1412 ropts.flags = RESET_HEAD_HARD;
1413 - if (reset_head(the_repository, &ropts) < 0)
1413 + if (reset_working_tree(the_repository, &ropts) < 0)
1414 die(_("could not move back to %s"),
1415 oid_to_hex(&options.orig_head->object.oid));
1416 strbuf_release(&head_msg);
@@ -1880,7 +1880,7 @@ int cmd_rebase(int argc,
1880 RESET_HEAD_RUN_POST_CHECKOUT_HOOK;
1881 ropts.head_msg = msg.buf;
1882 ropts.default_reflog_action = options.reflog_action;
1883 - if (reset_head(the_repository, &ropts)) {
1883 + if (reset_working_tree(the_repository, &ropts)) {
1884 ret = error(_("Could not detach HEAD"));
1885 goto cleanup_autostash;
1886 }
reset.c
+3 -2
@@ -12,7 +12,7 @@
12 #include "hook.h"
13
14 static int update_refs(struct repository *repo,
15 - const struct reset_head_opts *opts,
15 + const struct reset_working_tree_options *opts,
16 const struct object_id *oid,
17 const struct object_id *head)
18 {
@@ -85,7 +85,8 @@ static int update_refs(struct repository *repo,
85 return ret;
86 }
87
88 -int reset_head(struct repository *r, const struct reset_head_opts *opts)
88 +int reset_working_tree(struct repository *r,
89 + const struct reset_working_tree_options *opts)
90 {
91 const struct object_id *oid = opts->oid;
92 const char *switch_to_branch = opts->branch;
reset.h
+2 -2
@@ -17,7 +17,7 @@
17 /* Update ORIG_HEAD as well as HEAD */
18 #define RESET_ORIG_HEAD (1<<4)
19
20 -struct reset_head_opts {
20 +struct reset_working_tree_options {
21 /*
22 * The commit to checkout/reset to. Defaults to HEAD.
23 */
@@ -55,6 +55,6 @@ struct reset_head_opts {
55 const char *default_reflog_action;
56 };
57
58 -int reset_head(struct repository *r, const struct reset_head_opts *opts);
58 +int reset_working_tree(struct repository *r, const struct reset_working_tree_options *opts);
59
60 #endif
sequencer.c
+4 -4
@@ -4677,7 +4677,7 @@ static void create_autostash_internal(struct repository *r,
4677 if (has_unstaged_changes(r, 1) ||
4678 has_uncommitted_changes(r, 1)) {
4679 struct child_process stash = CHILD_PROCESS_INIT;
4680 - struct reset_head_opts ropts = { .flags = RESET_HEAD_HARD };
4680 + struct reset_working_tree_options ropts = { .flags = RESET_HEAD_HARD };
4681 struct object_id oid;
4682
4683 strvec_pushl(&stash.args,
@@ -4707,7 +4707,7 @@ static void create_autostash_internal(struct repository *r,
4707
4708 if (!silent)
4709 printf(_("Created autostash: %s\n"), buf.buf);
4710 - if (reset_head(r, &ropts) < 0)
4710 + if (reset_working_tree(r, &ropts) < 0)
4711 die(_("could not reset --hard"));
4712 discard_index(r->index);
4713 if (repo_read_index(r) < 0)
@@ -4867,7 +4867,7 @@ static int checkout_onto(struct repository *r, struct replay_opts *opts,
4867 const char *onto_name, const struct object_id *onto,
4868 const struct object_id *orig_head)
4869 {
4870 - struct reset_head_opts ropts = {
4870 + struct reset_working_tree_options ropts = {
4871 .oid = onto,
4872 .orig_head = orig_head,
4873 .flags = RESET_HEAD_DETACH | RESET_ORIG_HEAD |
@@ -4876,7 +4876,7 @@ static int checkout_onto(struct repository *r, struct replay_opts *opts,
4876 onto_name),
4877 .default_reflog_action = sequencer_reflog_action(opts)
4878 };
4879 - if (reset_head(r, &ropts)) {
4879 + if (reset_working_tree(r, &ropts)) {
4880 apply_autostash(rebase_path_autostash());
4881 sequencer_remove_state(opts);
4882 return error(_("could not detach HEAD"));