{"thread":{"id":"51067","subject":"[PATCH] init: make --template path relative to $CWD","startedAt":"2019-05-10T10:47:05Z","lastAt":"2019-05-13T06:12:58Z","messageCount":2,"participants":["Nguyễn Thái Ngọc Duy","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"375286","messageId":"20190510104657.26585-1-pclouds@gmail.com","threadId":"51067","inReplyTo":null,"subject":"[PATCH] init: make --template path relative to $CWD","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2019-05-10T10:46:57Z","receivedAt":"2019-05-10T10:47:05Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"During git-init we chdir() to the target directory, but --template is\nnot adjusted. So it's relative to the target directory instead of\ncurrent directory.\n\nIt would be ok if it's documented, but --template in git-init.txt\nmentions nothing about this behavior. Change it to be relative to $CWD,\nwhich is much more intuitive.\n\nThe changes in the test suite show that this relative-to-target behavior\nis actually used. I just hope that it's only used in the test suite and\nit's safe to change. Otherwise, the other option is just document\nit (i.e. relative to target dir) and move on.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/init-db.c      | 3 +++\n t/t0001-init.sh        | 2 +-\n t/t1301-shared-repo.sh | 6 +++---\n 3 files changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 93eff7618c..6b72a9bb09 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -494,6 +494,9 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)\n \tif (real_git_dir && !is_absolute_path(real_git_dir))\n \t\treal_git_dir = real_pathdup(real_git_dir, 1);\n \n+\tif (template_dir && *template_dir && !is_absolute_path(template_dir))\n+\t\ttemplate_dir = absolute_pathdup(template_dir);\n+\n \tif (argc == 1) {\n \t\tint mkdir_tried = 0;\n \tretry:\ndiff --git a/t/t0001-init.sh b/t/t0001-init.sh\nindex 42a263cada..802edb6c8f 100755\n--- a/t/t0001-init.sh\n+++ b/t/t0001-init.sh\n@@ -174,7 +174,7 @@ test_expect_success 'reinit' '\n test_expect_success 'init with --template' '\n \tmkdir template-source &&\n \techo content >template-source/file &&\n-\tgit init --template=../template-source template-custom &&\n+\tgit init --template=template-source template-custom &&\n \ttest_cmp template-source/file template-custom/.git/file\n '\n \ndiff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh\nindex dfece751b5..2dc853d1be 100755\n--- a/t/t1301-shared-repo.sh\n+++ b/t/t1301-shared-repo.sh\n@@ -136,7 +136,7 @@ test_expect_success POSIXPERM 'forced modes' '\n \t(\n \t\tcd new &&\n \t\tumask 002 &&\n-\t\tgit init --shared=0660 --template=../templates &&\n+\t\tgit init --shared=0660 --template=templates &&\n \t\t>frotz &&\n \t\tgit add frotz &&\n \t\tgit commit -a -m initial &&\n@@ -192,7 +192,7 @@ test_expect_success POSIXPERM 're-init respects core.sharedrepository (remote)'\n \tumask 0022 &&\n \tgit init --bare --shared=0666 child.git &&\n \ttest_path_is_missing child.git/foo &&\n-\tgit init --bare --template=../templates child.git &&\n+\tgit init --bare --template=templates child.git &&\n \techo \"-rw-rw-rw-\" >expect &&\n \ttest_modebits child.git/foo >actual &&\n \ttest_cmp expect actual\n@@ -203,7 +203,7 @@ test_expect_success POSIXPERM 'template can set core.sharedrepository' '\n \tumask 0022 &&\n \tgit config core.sharedrepository 0666 &&\n \tcp .git/config templates/config &&\n-\tgit init --bare --template=../templates child.git &&\n+\tgit init --bare --template=templates child.git &&\n \techo \"-rw-rw-rw-\" >expect &&\n \ttest_modebits child.git/HEAD >actual &&\n \ttest_cmp expect actual\n-- \n2.21.0.1141.gd54ac2cb17\n\n"},{"id":"375366","messageId":"xmqq5zqedgrc.fsf@gitster-ct.c.googlers.com","threadId":"51067","inReplyTo":"20190510104657.26585-1-pclouds@gmail.com","subject":"Re: [PATCH] init: make --template path relative to $CWD","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-05-13T06:12:55Z","receivedAt":"2019-05-13T06:12:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> During git-init we chdir() to the target directory, but --template is\n> not adjusted. So it's relative to the target directory instead of\n> current directory.\n\n> It would be ok if it's documented, but --template in git-init.txt\n> mentions nothing about this behavior. Change it to be relative to $CWD,\n> which is much more intuitive.\n>\n> The changes in the test suite show that this relative-to-target behavior\n> is actually used. I just hope that it's only used in the test suite and\n> it's safe to change. Otherwise, the other option is just document\n> it (i.e. relative to target dir) and move on.\n\nYeah, that other option does sound safer, but ...\n\n>  \tmkdir template-source &&\n>  \techo content >template-source/file &&\n> -\tgit init --template=../template-source template-custom &&\n> +\tgit init --template=template-source template-custom &&\n\n... the example may show that the updated behaviour may match the\nend-user expectation better.  It certainly is more in line with how\nthe \"--reference\" option of \"git clone\" uses a relative path.\n\nIt also makes it easier to <TAB> complete if these things were\nrelative to the current directory at the time of command\ninvocation.  I often find it frustrating when I have to create a\nsymbolic link in a directory I am not yet in that points to\nsomewhere using a relative path for the exact reason ;-)\n"}]}