Skip to content

Commit 8d7717c

Browse files
author
Edward Thomson
authored
Merge pull request libgit2#4034 from libgit2/cmn/sysdir-no-reguess
sysdir: don't re-guess when using variable substitution
2 parents f91f170 + 9f09f29 commit 8d7717c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/sysdir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ int git_sysdir_set(git_sysdir_t which, const char *search_path)
171171
expand_path = strstr(search_path, PATH_MAGIC);
172172

173173
/* reset the default if this path has been cleared */
174-
if (!search_path || expand_path)
174+
if (!search_path)
175175
git_sysdir__dirs[which].guess(&git_sysdir__dirs[which].buf);
176176

177177
/* if $PATH is not referenced, then just set the path */

tests/core/env.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,24 @@ void test_core_env__2(void)
298298
git_buf_free(&path);
299299
git_buf_free(&found);
300300
}
301+
302+
void test_core_env__substitution(void)
303+
{
304+
git_buf buf = GIT_BUF_INIT, expected = GIT_BUF_INIT;
305+
306+
/* Set it to something non-default so we have controllable values */
307+
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, "/tmp/a"));
308+
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &buf));
309+
cl_assert_equal_s("/tmp/a", buf.ptr);
310+
311+
git_buf_clear(&buf);
312+
cl_git_pass(git_buf_join(&buf, GIT_PATH_LIST_SEPARATOR, "$PATH", "/tmp/b"));
313+
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, buf.ptr));
314+
cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &buf));
315+
316+
cl_git_pass(git_buf_join(&expected, GIT_PATH_LIST_SEPARATOR, "/tmp/a", "/tmp/b"));
317+
cl_assert_equal_s(expected.ptr, buf.ptr);
318+
319+
git_buf_free(&expected);
320+
git_buf_free(&buf);
321+
}

0 commit comments

Comments
 (0)