From 31bb293d9d12e47f0f58e2de424ade2c04666e28 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 18 Jan 2019 07:09:26 -0800 Subject: [PATCH] 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 --- builtin/rebase.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 8eaf114e7e..c46b2d7a13 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -338,6 +338,7 @@ static void add_var(struct strbuf *buf, const char *name, const char *value) #define RESET_HEAD_DETACH (1<<0) #define RESET_HEAD_HARD (1<<1) #define RESET_HEAD_RUN_POST_CHECKOUT_HOOK (1<<2) +#define RESET_HEAD_REFS_ONLY (1<<3) static int reset_head(struct object_id *oid, const char *action, const char *switch_to_branch, unsigned flags, @@ -346,6 +347,7 @@ static int reset_head(struct object_id *oid, const char *action, unsigned detach_head = flags & RESET_HEAD_DETACH; unsigned reset_hard = flags & RESET_HEAD_HARD; unsigned run_hook = flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK; + unsigned refs_only = flags & RESET_HEAD_REFS_ONLY; struct object_id head_oid; struct tree_desc desc[2] = { { NULL }, { NULL } }; struct lock_file lock = LOCK_INIT; @@ -361,7 +363,7 @@ static int reset_head(struct object_id *oid, const char *action, if (switch_to_branch && !starts_with(switch_to_branch, "refs/")) BUG("Not a fully qualified branch: '%s'", switch_to_branch); - if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) { + if (!refs_only && hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) { ret = -1; goto leave_reset_head; } @@ -374,6 +376,9 @@ static int reset_head(struct object_id *oid, const char *action, if (!oid) oid = &head_oid; + if (refs_only) + goto reset_head_refs; + memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts)); setup_unpack_trees_porcelain(&unpack_tree_opts, action); unpack_tree_opts.head_idx = 1; @@ -414,6 +419,7 @@ static int reset_head(struct object_id *oid, const char *action, goto leave_reset_head; } +reset_head_refs: reflog_action = getenv(GIT_REFLOG_ACTION_ENVIRONMENT); strbuf_addf(&msg, "%s: ", reflog_action ? reflog_action : "rebase"); prefix_len = msg.len;