All of lore.kernel.org
 help / color / mirror / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>,
	Eric Sunshine <sunshine@sunshineco.com>,
	Derrick Stolee <stolee@gmail.com>
Subject: [PATCH v2 2/7] var: add support for listing the shell
Date: Mon, 26 Jun 2023 19:00:03 +0000	[thread overview]
Message-ID: <20230626190008.644769-3-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20230626190008.644769-1-sandals@crustytoothpaste.net>

From: "brian m. carlson" <bk2204@github.com>

On most Unix systems, finding a suitable shell is easy: one simply uses
"sh" with an appropriate PATH value.  However, in many Windows
environments, the shell is shipped alongside Git, and it may or may not
be in PATH, even if Git is.

In such an environment, it can be very helpful to query Git for the
shell it's using, since other tools may want to use the same shell as
well.  To help them out, let's add a variable, GIT_SHELL_PATH, that
points to the location of the shell.

On Unix, we know our shell must be executable to be functional, so
assume that the distributor has correctly configured their environment,
and use that as a basic test.  On Git for Windows, we know that our
shell will be one of a few fixed values, all of which end in "sh" (such
as "bash").  This seems like it might be a nice test on Unix as well,
since it is customary for all shells to end in "sh", but there probably
exist such systems that don't have such a configuration, so be careful
here not to break them.

Signed-off-by: brian m. carlson <bk2204@github.com>
---
 Documentation/git-var.txt |  3 +++
 builtin/var.c             |  6 ++++++
 t/t0007-git-var.sh        | 15 +++++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/Documentation/git-var.txt b/Documentation/git-var.txt
index f40202b8e3..f0f647e14a 100644
--- a/Documentation/git-var.txt
+++ b/Documentation/git-var.txt
@@ -71,6 +71,9 @@ endif::git-default-pager[]
 GIT_DEFAULT_BRANCH::
     The name of the first branch created in newly initialized repositories.
 
+GIT_SHELL_PATH::
+    The path of the binary providing the POSIX shell for commands which use the shell.
+
 SEE ALSO
 --------
 linkgit:git-commit-tree[1]
diff --git a/builtin/var.c b/builtin/var.c
index 2149998980..f97178eed1 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -36,6 +36,11 @@ static const char *default_branch(int flag)
 	return git_default_branch_name(1);
 }
 
+static const char *shell_path(int flag)
+{
+	return SHELL_PATH;
+}
+
 struct git_var {
 	const char *name;
 	const char *(*read)(int);
@@ -47,6 +52,7 @@ static struct git_var git_vars[] = {
 	{ "GIT_SEQUENCE_EDITOR", sequence_editor },
 	{ "GIT_PAGER", pager },
 	{ "GIT_DEFAULT_BRANCH", default_branch },
+	{ "GIT_SHELL_PATH", shell_path },
 	{ "", NULL },
 };
 
diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh
index eeb8539c1b..e35f07afcb 100755
--- a/t/t0007-git-var.sh
+++ b/t/t0007-git-var.sh
@@ -147,6 +147,21 @@ test_expect_success 'get GIT_SEQUENCE_EDITOR with configuration and environment
 	)
 '
 
+test_expect_success POSIXPERM 'GIT_SHELL_PATH points to a valid executable' '
+	shellpath=$(git var GIT_SHELL_PATH) &&
+	test_path_is_executable "$shellpath"
+'
+
+# We know in this environment that our shell will be one of a few fixed values
+# that all end in "sh".
+test_expect_success MINGW 'GIT_SHELL_PATH points to a suitable shell' '
+	shellpath=$(git var GIT_SHELL_PATH) &&
+	case "$shellpath" in
+	*sh) ;;
+	*) return 1;;
+	esac
+'
+
 # For git var -l, we check only a representative variable;
 # testing the whole output would make our test too brittle with
 # respect to unrelated changes in the test suite's environment.

  parent reply	other threads:[~2023-06-26 19:01 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-22 19:50 [PATCH 0/3] Additional variables for git var brian m. carlson
2023-06-22 19:50 ` [PATCH 1/3] var: add support for listing the shell brian m. carlson
2023-06-22 20:42   ` Eric Sunshine
2023-06-22 21:05     ` Junio C Hamano
2023-06-22 21:13       ` Eric Sunshine
2023-06-22 21:25       ` brian m. carlson
2023-06-22 21:41         ` Junio C Hamano
2023-06-22 21:20     ` brian m. carlson
2023-06-22 19:50 ` [PATCH 2/3] var: add attributes files locations brian m. carlson
2023-06-22 20:19   ` Derrick Stolee
2023-06-22 21:17     ` brian m. carlson
2023-06-22 21:37       ` Junio C Hamano
2023-06-22 21:17   ` Junio C Hamano
2023-06-22 21:18   ` Eric Sunshine
2023-06-22 21:30     ` brian m. carlson
2023-06-22 21:21   ` Eric Sunshine
2023-06-22 19:50 ` [PATCH 3/3] var: add config file locations brian m. carlson
2023-06-22 21:35   ` Eric Sunshine
2023-06-26 19:00 ` [PATCH v2 0/7] Additional variables for git var brian m. carlson
2023-06-26 19:00   ` [PATCH v2 1/7] t: add a function to check executable bit brian m. carlson
2023-06-26 19:00   ` brian m. carlson [this message]
2023-06-26 19:00   ` [PATCH v2 3/7] var: format variable structure with C99 initializers brian m. carlson
2023-06-26 19:00   ` [PATCH v2 4/7] var: adjust memory allocation for strings brian m. carlson
2023-06-26 19:56     ` Junio C Hamano
2023-06-26 19:00   ` [PATCH v2 5/7] attr: expose and rename accessor functions brian m. carlson
2023-06-26 19:58     ` Junio C Hamano
2023-06-26 19:00   ` [PATCH v2 6/7] var: add attributes files locations brian m. carlson
2023-06-27  7:05     ` Jeff King
2023-06-27 16:12       ` brian m. carlson
2023-06-27 17:56         ` Junio C Hamano
2023-06-27 20:16         ` Jeff King
2023-06-26 19:00   ` [PATCH v2 7/7] var: add config file locations brian m. carlson
2023-06-26 20:02     ` Junio C Hamano
2023-06-27 16:18 ` [PATCH v3 0/8] Additional variables for git var brian m. carlson
2023-06-27 16:18   ` [PATCH v3 1/8] var: mark unused parameters in git_var callbacks brian m. carlson
2023-06-27 16:18   ` [PATCH v3 2/8] t: add a function to check executable bit brian m. carlson
2023-06-27 16:18   ` [PATCH v3 3/8] var: add support for listing the shell brian m. carlson
2023-06-27 16:18   ` [PATCH v3 4/8] var: format variable structure with C99 initializers brian m. carlson
2023-06-27 16:18   ` [PATCH v3 5/8] var: adjust memory allocation for strings brian m. carlson
2023-06-27 16:19   ` [PATCH v3 6/8] attr: expose and rename accessor functions brian m. carlson
2023-06-27 16:19   ` [PATCH v3 7/8] var: add attributes files locations brian m. carlson
2023-06-27 16:19   ` [PATCH v3 8/8] var: add config file locations brian m. carlson

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=20230626190008.644769-3-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=stolee@gmail.com \
    --cc=sunshine@sunshineco.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.