Skip to content

Commit 1e65721

Browse files
bk2204gitster
authored andcommitted
var: add support for listing the shell
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d6546af commit 1e65721

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

Documentation/git-var.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ endif::git-default-pager[]
7171
GIT_DEFAULT_BRANCH::
7272
The name of the first branch created in newly initialized repositories.
7373

74+
GIT_SHELL_PATH::
75+
The path of the binary providing the POSIX shell for commands which use the shell.
76+
7477
SEE ALSO
7578
--------
7679
linkgit:git-commit-tree[1]

builtin/var.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ static const char *default_branch(int ident_flag UNUSED)
3636
return git_default_branch_name(1);
3737
}
3838

39+
static const char *shell_path(int ident_flag UNUSED)
40+
{
41+
return SHELL_PATH;
42+
}
43+
3944
struct git_var {
4045
const char *name;
4146
const char *(*read)(int);
@@ -47,6 +52,7 @@ static struct git_var git_vars[] = {
4752
{ "GIT_SEQUENCE_EDITOR", sequence_editor },
4853
{ "GIT_PAGER", pager },
4954
{ "GIT_DEFAULT_BRANCH", default_branch },
55+
{ "GIT_SHELL_PATH", shell_path },
5056
{ "", NULL },
5157
};
5258

t/t0007-git-var.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,21 @@ test_expect_success 'get GIT_SEQUENCE_EDITOR with configuration and environment
147147
)
148148
'
149149

150+
test_expect_success POSIXPERM 'GIT_SHELL_PATH points to a valid executable' '
151+
shellpath=$(git var GIT_SHELL_PATH) &&
152+
test_path_is_executable "$shellpath"
153+
'
154+
155+
# We know in this environment that our shell will be one of a few fixed values
156+
# that all end in "sh".
157+
test_expect_success MINGW 'GIT_SHELL_PATH points to a suitable shell' '
158+
shellpath=$(git var GIT_SHELL_PATH) &&
159+
case "$shellpath" in
160+
*sh) ;;
161+
*) return 1;;
162+
esac
163+
'
164+
150165
# For git var -l, we check only a representative variable;
151166
# testing the whole output would make our test too brittle with
152167
# respect to unrelated changes in the test suite's environment.

0 commit comments

Comments
 (0)