From 3f944424ac899fb6705e7463d937c5ed581da207 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 1 Nov 2017 18:10:25 +0100 Subject: mingw: add experimental feature to redirect standard handles Particularly when calling Git from applications, such as Visual Studio's Team Explorer, it is important that stdin/stdout/stderr are closed properly. However, when spawning processes on Windows, those handles must be marked as inheritable if we want to use them, but that flag is a global flag and may very well be used by other spawned processes which then do not know to close those handles. Let's introduce a set of environment variables (GIT_REDIRECT_STDIN and friends) that specify paths to files, or even better, named pipes (which are similar to Unix sockets) and that are used by the spawned Git process. This helps work around above-mentioned issue: those named pipes will be opened in a non-inheritable way upon startup, and no handles are passed around (and therefore no inherited handles need to be closed by any spawned child). This feature shipped with Git for Windows (marked as experimental) since v2.11.0(2), so it has seen some serious testing in the meantime. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t0001-init.sh | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 't/t0001-init.sh') diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 86c1a51654..0fd2fc4538 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -453,4 +453,10 @@ test_expect_success 're-init from a linked worktree' ' ) ' +test_expect_success MINGW 'redirect std handles' ' + GIT_REDIRECT_STDOUT=output.txt git rev-parse --git-dir && + test .git = "$(cat output.txt)" && + test -z "$(GIT_REDIRECT_STDOUT=off git rev-parse --git-dir)" +' + test_done -- cgit v1.2.3 From 1a172e4ac1719a068c76384bd077ee65d915ebea Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 1 Nov 2017 18:10:30 +0100 Subject: mingw: optionally redirect stderr/stdout via the same handle The "2>&1" notation in Powershell and in Unix shells implies that stderr is redirected to the same handle into which stdout is already written. Let's use this special value to allow the same trick with GIT_REDIRECT_STDERR and GIT_REDIRECT_STDOUT: if the former's value is `2>&1`, then stderr will simply be written to the same handle as stdout. The functionality was suggested by Jeff Hostetler. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t0001-init.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 't/t0001-init.sh') diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 0fd2fc4538..c413bff9cf 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -456,7 +456,13 @@ test_expect_success 're-init from a linked worktree' ' test_expect_success MINGW 'redirect std handles' ' GIT_REDIRECT_STDOUT=output.txt git rev-parse --git-dir && test .git = "$(cat output.txt)" && - test -z "$(GIT_REDIRECT_STDOUT=off git rev-parse --git-dir)" + test -z "$(GIT_REDIRECT_STDOUT=off git rev-parse --git-dir)" && + test_must_fail env \ + GIT_REDIRECT_STDOUT=output.txt \ + GIT_REDIRECT_STDERR="2>&1" \ + git rev-parse --git-dir --verify refs/invalid && + printf ".git\nfatal: Needed a single revision\n" >expect && + test_cmp expect output.txt ' test_done -- cgit v1.2.3