All of lore.kernel.org
 help / color / mirror / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: git@vger.kernel.org
Cc: Jacob Keller <jacob.keller@gmail.com>, Jeff King <peff@peff.net>,
	Junio C Hamano <gitster@pobox.com>,
	Johannes Schindelin <johannes.schindelin@gmx.de>,
	Vitali Lovich <vlovich@gmail.com>
Subject: [PATCH v2] sequencer: pass absolute GIT_WORK_TREE to exec commands
Date: Sat, 14 Jul 2018 18:38:59 +0000	[thread overview]
Message-ID: <20180714183859.97988-1-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20180714175555.GD1042117@genre.crustytoothpaste.net>

The sequencer currently passes GIT_DIR, but not GIT_WORK_TREE, to exec
commands.  In that configuration, we assume that whatever directory
we're in is the top level of the work tree, and git rev-parse
--show-toplevel responds accordingly.  However, when we're in a
subdirectory, that isn't correct: we respond with the subdirectory as
the top level, resulting in unexpected behavior.

Ensure that we pass GIT_WORK_TREE as well as GIT_DIR so that git
operations within subdirectories work correctly.

Note that we are guaranteed to have a work tree in this case: the
relevant sequencer functions are called only from revert, cherry-pick,
and rebase--helper; all of these commands require a working tree.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 sequencer.c                   | 2 ++
 t/t3404-rebase-interactive.sh | 9 +++++++++
 2 files changed, 11 insertions(+)

diff --git a/sequencer.c b/sequencer.c
index 5354d4d51e..c8e16f9168 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2636,6 +2636,8 @@ static int do_exec(const char *command_line)
 	fprintf(stderr, "Executing: %s\n", command_line);
 	child_argv[0] = command_line;
 	argv_array_pushf(&child_env, "GIT_DIR=%s", absolute_path(get_git_dir()));
+	argv_array_pushf(&child_env, "GIT_WORK_TREE=%s",
+			 absolute_path(get_git_work_tree()));
 	status = run_command_v_opt_cd_env(child_argv, RUN_USING_SHELL, NULL,
 					  child_env.argv);
 
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index 352a52e59d..d03055d149 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -119,6 +119,15 @@ test_expect_success 'rebase -i with exec allows git commands in subdirs' '
 	)
 '
 
+test_expect_success 'rebase -i sets work tree properly' '
+	test_when_finished "rm -rf subdir" &&
+	test_when_finished "test_might_fail git rebase --abort" &&
+	mkdir subdir &&
+	git rebase -x "(cd subdir && git rev-parse --show-toplevel)" HEAD^ \
+		>actual &&
+	! grep "/subdir$" actual
+'
+
 test_expect_success 'rebase -i with the exec command checks tree cleanness' '
 	git checkout master &&
 	set_fake_editor &&

  reply	other threads:[~2018-07-14 18:39 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-12  2:50 rev-parse --show-toplevel broken during exec'ed rebase? Vitali Lovich
2018-07-12  2:53 ` Vitali Lovich
2018-07-12 14:49   ` Johannes Schindelin
2018-07-12 15:02     ` Johannes Schindelin
2018-07-12 15:23 ` Junio C Hamano
2018-07-12 17:39   ` Vitali Lovich
2018-07-13 18:47   ` brian m. carlson
2018-07-13 20:19     ` Jeff King
2018-07-13 23:05       ` brian m. carlson
2018-07-14  0:35         ` [PATCH] sequencer: pass absolute GIT_WORK_TREE to exec commands brian m. carlson
2018-07-14  0:57           ` Jeff King
2018-07-14 17:55             ` brian m. carlson
2018-07-14 18:38               ` brian m. carlson [this message]
2018-07-14 21:19                 ` [PATCH v2] " Jeff King
2018-07-14 21:05           ` [PATCH] " Johannes Schindelin
2018-07-14 21:09             ` brian m. carlson
2018-07-16 18:14       ` rev-parse --show-toplevel broken during exec'ed rebase? Junio C Hamano
2018-07-16 18:39         ` Jeff King
2018-07-16 21:10           ` Junio C Hamano
2018-07-19 20:28         ` Johannes Schindelin
2018-07-19 22:09           ` SZEDER Gábor
2018-07-19 22:34             ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180714183859.97988-1-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jacob.keller@gmail.com \
    --cc=johannes.schindelin@gmx.de \
    --cc=peff@peff.net \
    --cc=vlovich@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.