diff options
author | Matheus Tavares <matheus.bernardino@usp.br> | 2021-05-25 00:41:01 -0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-05-25 13:22:08 +0900 |
commit | a185dd58ecc17f2ea16985d59c9bb7b09bec7775 (patch) | |
tree | acbffd1454d75700aeafa8c776ad4411710a6fbc /builtin/init-db.c | |
parent | builtin/rm: avoid leaking pathspec and seen (diff) | |
download | tgif-a185dd58ecc17f2ea16985d59c9bb7b09bec7775.tar.xz |
init: fix bug regarding ~/ expansion in init.templateDir
We used to read the init.templateDir setting at builtin/init-db.c using
a git_config() callback that, in turn, called git_config_pathname(). To
simplify the config reading logic at this file and plug a memory leak,
this was replaced by a direct call to git_config_get_value() at
e4de4502e6 ("init: remove git_init_db_config() while fixing leaks",
2021-03-14). However, this function doesn't provide path expanding
semantics, like git_config_pathname() does, so paths with '~/' and
'~user/' are treated literally. This makes 'git init' fail to handle
init.templateDir paths using these constructs:
$ git config init.templateDir '~/templates_dir'
$ git init
'warning: templates not found in ~/templates_dir'
Replace the git_config_get_value() call by git_config_get_pathname(),
which does the '~/' and '~user/' expansions. Also add a regression test.
Note that unlike git_config_get_value(), the config cache does not own
the memory for the path returned by git_config_get_pathname(), so we
must free() it.
Reported on IRC by rkta.
Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/init-db.c')
-rw-r--r-- | builtin/init-db.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/builtin/init-db.c b/builtin/init-db.c index efc66523e2..7d606de7ba 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -211,8 +211,9 @@ static int create_default_files(const char *template_path, * values (since we've just potentially changed what's available on * disk). */ - git_config_get_value("init.templatedir", &init_template_dir); + git_config_get_pathname("init.templatedir", &init_template_dir); copy_templates(template_path, init_template_dir); + free((char *)init_template_dir); git_config_clear(); reset_shared_repository(); git_config(git_default_config, NULL); |