Skip to content

Commit 31bb293

Browse files
committed
rebase: teach reset_head() to optionally skip the worktree
This is what the legacy (scripted) rebase does in `move_to_original_branch`, and we will need this functionality in the next commit. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 1ae77db commit 31bb293

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

builtin/rebase.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ static void add_var(struct strbuf *buf, const char *name, const char *value)
338338
#define RESET_HEAD_DETACH (1<<0)
339339
#define RESET_HEAD_HARD (1<<1)
340340
#define RESET_HEAD_RUN_POST_CHECKOUT_HOOK (1<<2)
341+
#define RESET_HEAD_REFS_ONLY (1<<3)
341342

342343
static int reset_head(struct object_id *oid, const char *action,
343344
const char *switch_to_branch, unsigned flags,
@@ -346,6 +347,7 @@ static int reset_head(struct object_id *oid, const char *action,
346347
unsigned detach_head = flags & RESET_HEAD_DETACH;
347348
unsigned reset_hard = flags & RESET_HEAD_HARD;
348349
unsigned run_hook = flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK;
350+
unsigned refs_only = flags & RESET_HEAD_REFS_ONLY;
349351
struct object_id head_oid;
350352
struct tree_desc desc[2] = { { NULL }, { NULL } };
351353
struct lock_file lock = LOCK_INIT;
@@ -361,7 +363,7 @@ static int reset_head(struct object_id *oid, const char *action,
361363
if (switch_to_branch && !starts_with(switch_to_branch, "refs/"))
362364
BUG("Not a fully qualified branch: '%s'", switch_to_branch);
363365

364-
if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) {
366+
if (!refs_only && hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) {
365367
ret = -1;
366368
goto leave_reset_head;
367369
}
@@ -374,6 +376,9 @@ static int reset_head(struct object_id *oid, const char *action,
374376
if (!oid)
375377
oid = &head_oid;
376378

379+
if (refs_only)
380+
goto reset_head_refs;
381+
377382
memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts));
378383
setup_unpack_trees_porcelain(&unpack_tree_opts, action);
379384
unpack_tree_opts.head_idx = 1;
@@ -414,6 +419,7 @@ static int reset_head(struct object_id *oid, const char *action,
414419
goto leave_reset_head;
415420
}
416421

422+
reset_head_refs:
417423
reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
418424
strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase");
419425
prefix_len = msg.len;

0 commit comments

Comments
 (0)