]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'en/keep-cwd'
authorJunio C Hamano <gitster@pobox.com>
Thu, 27 Jan 2022 06:22:24 +0000 (22:22 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 27 Jan 2022 06:22:24 +0000 (22:22 -0800)
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

builtin/stash.c
sequencer.c
t/t3400-rebase.sh

index 1ef2017c595dc09d09457affb3f5e3c3a0e352ab..86cd0b456e7752d7ffdb578ce892ca17c4e9c6a9 100644 (file)
@@ -1539,8 +1539,12 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
                        struct child_process cp = CHILD_PROCESS_INIT;
 
                        cp.git_cmd = 1;
-                       if (startup_info->original_cwd)
+                       if (startup_info->original_cwd) {
                                cp.dir = startup_info->original_cwd;
+                               strvec_pushf(&cp.env_array, "%s=%s",
+                                            GIT_WORK_TREE_ENVIRONMENT,
+                                            the_repository->worktree);
+                       }
                        strvec_pushl(&cp.args, "clean", "--force",
                                     "--quiet", "-d", ":/", NULL);
                        if (include_untracked == INCLUDE_ALL_FILES)
index 6abd72160ccd46791d5a262021804e07ab9ea37f..5213d16e97174adbf10fc487edb0f3d3a726f7d7 100644 (file)
@@ -4223,8 +4223,11 @@ static int run_git_checkout(struct repository *r, struct replay_opts *opts,
 
        cmd.git_cmd = 1;
 
-       if (startup_info->original_cwd)
+       if (startup_info->original_cwd) {
                cmd.dir = startup_info->original_cwd;
+               strvec_pushf(&cmd.env_array, "%s=%s",
+                            GIT_WORK_TREE_ENVIRONMENT, r->worktree);
+       }
        strvec_push(&cmd.args, "checkout");
        strvec_push(&cmd.args, commit);
        strvec_pushf(&cmd.env_array, GIT_REFLOG_ACTION "=%s", action);
index 23dbd3c82ed6a21ff7bd883c20a7c45822421250..71b1735e1dd180bb16a72df76b1b49f49a59072d 100755 (executable)
@@ -416,4 +416,25 @@ test_expect_success MINGW,SYMLINKS_WINDOWS 'rebase when .git/logs is a symlink'
        mv actual_logs .git/logs
 '
 
+test_expect_success 'rebase when inside worktree subdirectory' '
+       git init main-wt &&
+       (
+               cd main-wt &&
+               git commit --allow-empty -m "initial" &&
+               mkdir -p foo/bar &&
+               test_commit foo/bar/baz &&
+               mkdir -p a/b &&
+               test_commit a/b/c &&
+               # create another branch for our other worktree
+               git branch other &&
+               git worktree add ../other-wt other &&
+               cd ../other-wt &&
+               # create and cd into a subdirectory
+               mkdir -p random/dir &&
+               cd random/dir &&
+               # now do the rebase
+               git rebase --onto HEAD^^ HEAD^  # drops the HEAD^ commit
+       )
+'
+
 test_done