Skip to content

Commit f120b65

Browse files
committed
Merge branch 'en/keep-cwd' into maint
Fix a regression in 2.35 that roke the use of "rebase" and "stash" in a secondary worktree. * en/keep-cwd: sequencer, stash: fix running from worktree subdir
2 parents 89bece5 + ff5b791 commit f120b65

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

builtin/stash.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1539,8 +1539,12 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
15391539
struct child_process cp = CHILD_PROCESS_INIT;
15401540

15411541
cp.git_cmd = 1;
1542-
if (startup_info->original_cwd)
1542+
if (startup_info->original_cwd) {
15431543
cp.dir = startup_info->original_cwd;
1544+
strvec_pushf(&cp.env_array, "%s=%s",
1545+
GIT_WORK_TREE_ENVIRONMENT,
1546+
the_repository->worktree);
1547+
}
15441548
strvec_pushl(&cp.args, "clean", "--force",
15451549
"--quiet", "-d", ":/", NULL);
15461550
if (include_untracked == INCLUDE_ALL_FILES)

sequencer.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4223,8 +4223,11 @@ static int run_git_checkout(struct repository *r, struct replay_opts *opts,
42234223

42244224
cmd.git_cmd = 1;
42254225

4226-
if (startup_info->original_cwd)
4226+
if (startup_info->original_cwd) {
42274227
cmd.dir = startup_info->original_cwd;
4228+
strvec_pushf(&cmd.env_array, "%s=%s",
4229+
GIT_WORK_TREE_ENVIRONMENT, r->worktree);
4230+
}
42284231
strvec_push(&cmd.args, "checkout");
42294232
strvec_push(&cmd.args, commit);
42304233
strvec_pushf(&cmd.env_array, GIT_REFLOG_ACTION "=%s", action);

t/t3400-rebase.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,4 +416,25 @@ test_expect_success MINGW,SYMLINKS_WINDOWS 'rebase when .git/logs is a symlink'
416416
mv actual_logs .git/logs
417417
'
418418

419+
test_expect_success 'rebase when inside worktree subdirectory' '
420+
git init main-wt &&
421+
(
422+
cd main-wt &&
423+
git commit --allow-empty -m "initial" &&
424+
mkdir -p foo/bar &&
425+
test_commit foo/bar/baz &&
426+
mkdir -p a/b &&
427+
test_commit a/b/c &&
428+
# create another branch for our other worktree
429+
git branch other &&
430+
git worktree add ../other-wt other &&
431+
cd ../other-wt &&
432+
# create and cd into a subdirectory
433+
mkdir -p random/dir &&
434+
cd random/dir &&
435+
# now do the rebase
436+
git rebase --onto HEAD^^ HEAD^ # drops the HEAD^ commit
437+
)
438+
'
439+
419440
test_done

0 commit comments

Comments
 (0)