Skip to content

Commit 2193914

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 4c5f87b commit 2193914

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
@@ -337,13 +337,15 @@ static void add_var(struct strbuf *buf, const char *name, const char *value)
337337

338338
#define RESET_HEAD_DETACH (1<<0)
339339
#define RESET_HEAD_HARD (1<<1)
340+
#define RESET_HEAD_REFS_ONLY (1<<2)
340341

341342
static int reset_head(struct object_id *oid, const char *action,
342343
const char *switch_to_branch, unsigned flags,
343344
const char *reflog_orig_head, const char *reflog_head)
344345
{
345346
unsigned detach_head = flags & RESET_HEAD_DETACH;
346347
unsigned reset_hard = flags & RESET_HEAD_HARD;
348+
unsigned refs_only = flags & RESET_HEAD_REFS_ONLY;
347349
struct object_id head_oid;
348350
struct tree_desc desc[2] = { { NULL }, { NULL } };
349351
struct lock_file lock = LOCK_INIT;
@@ -359,7 +361,7 @@ static int reset_head(struct object_id *oid, const char *action,
359361
if (switch_to_branch && !starts_with(switch_to_branch, "refs/"))
360362
BUG("Not a fully qualified branch: '%s'", switch_to_branch);
361363

362-
if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) {
364+
if (!refs_only && hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) {
363365
ret = -1;
364366
goto leave_reset_head;
365367
}
@@ -372,6 +374,9 @@ static int reset_head(struct object_id *oid, const char *action,
372374
if (!oid)
373375
oid = &head_oid;
374376

377+
if (flags & RESET_HEAD_REFS_ONLY)
378+
goto reset_head_refs;
379+
375380
memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts));
376381
setup_unpack_trees_porcelain(&unpack_tree_opts, action);
377382
unpack_tree_opts.head_idx = 1;
@@ -412,6 +417,7 @@ static int reset_head(struct object_id *oid, const char *action,
412417
goto leave_reset_head;
413418
}
414419

420+
reset_head_refs:
415421
reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT);
416422
strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase");
417423
prefix_len = msg.len;

0 commit comments

Comments
 (0)