Skip to content

Commit a1b42bf

Browse files
committed
Merge branch 'mt/init-template-userpath-fix' into next
Regression fix. * mt/init-template-userpath-fix: init: fix bug regarding ~/ expansion in init.templateDir
2 parents f7659a4 + a185dd5 commit a1b42bf

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

builtin/init-db.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,9 @@ static int create_default_files(const char *template_path,
212212
* values (since we've just potentially changed what's available on
213213
* disk).
214214
*/
215-
git_config_get_value("init.templatedir", &init_template_dir);
215+
git_config_get_pathname("init.templatedir", &init_template_dir);
216216
copy_templates(template_path, init_template_dir);
217+
free((char *)init_template_dir);
217218
git_config_clear();
218219
reset_shared_repository();
219220
git_config(git_default_config, NULL);

t/t0001-init.sh

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,21 +186,33 @@ test_expect_success 'init with --template (blank)' '
186186
test_path_is_missing template-blank/.git/info/exclude
187187
'
188188

189-
test_expect_success 'init with init.templatedir set' '
190-
mkdir templatedir-source &&
191-
echo Content >templatedir-source/file &&
192-
test_config_global init.templatedir "${HOME}/templatedir-source" &&
189+
init_no_templatedir_env () {
193190
(
194-
mkdir templatedir-set &&
195-
cd templatedir-set &&
196191
sane_unset GIT_TEMPLATE_DIR &&
197192
NO_SET_GIT_TEMPLATE_DIR=t &&
198193
export NO_SET_GIT_TEMPLATE_DIR &&
199-
git init
200-
) &&
194+
git init "$1"
195+
)
196+
}
197+
198+
test_expect_success 'init with init.templatedir set' '
199+
mkdir templatedir-source &&
200+
echo Content >templatedir-source/file &&
201+
test_config_global init.templatedir "${HOME}/templatedir-source" &&
202+
203+
init_no_templatedir_env templatedir-set &&
201204
test_cmp templatedir-source/file templatedir-set/.git/file
202205
'
203206

207+
test_expect_success 'init with init.templatedir using ~ expansion' '
208+
mkdir -p templatedir-source &&
209+
echo Content >templatedir-source/file &&
210+
test_config_global init.templatedir "~/templatedir-source" &&
211+
212+
init_no_templatedir_env templatedir-expansion &&
213+
test_cmp templatedir-source/file templatedir-expansion/.git/file
214+
'
215+
204216
test_expect_success 'init --bare/--shared overrides system/global config' '
205217
test_config_global core.bare false &&
206218
test_config_global core.sharedRepository 0640 &&

0 commit comments

Comments
 (0)