git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
* [PATCH] init: make --template path relative to $CWD
@ 2019-05-10 10:46 Nguyễn Thái Ngọc Duy
  2019-05-13  6:12 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2019-05-10 10:46 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

During git-init we chdir() to the target directory, but --template is
not adjusted. So it's relative to the target directory instead of
current directory.

It would be ok if it's documented, but --template in git-init.txt
mentions nothing about this behavior. Change it to be relative to $CWD,
which is much more intuitive.

The changes in the test suite show that this relative-to-target behavior
is actually used. I just hope that it's only used in the test suite and
it's safe to change. Otherwise, the other option is just document
it (i.e. relative to target dir) and move on.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/init-db.c      | 3 +++
 t/t0001-init.sh        | 2 +-
 t/t1301-shared-repo.sh | 6 +++---
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/builtin/init-db.c b/builtin/init-db.c
index 93eff7618c..6b72a9bb09 100644
--- a/builtin/init-db.c
+++ b/builtin/init-db.c
@@ -494,6 +494,9 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
 	if (real_git_dir && !is_absolute_path(real_git_dir))
 		real_git_dir = real_pathdup(real_git_dir, 1);
 
+	if (template_dir && *template_dir && !is_absolute_path(template_dir))
+		template_dir = absolute_pathdup(template_dir);
+
 	if (argc == 1) {
 		int mkdir_tried = 0;
 	retry:
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index 42a263cada..802edb6c8f 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -174,7 +174,7 @@ test_expect_success 'reinit' '
 test_expect_success 'init with --template' '
 	mkdir template-source &&
 	echo content >template-source/file &&
-	git init --template=../template-source template-custom &&
+	git init --template=template-source template-custom &&
 	test_cmp template-source/file template-custom/.git/file
 '
 
diff --git a/t/t1301-shared-repo.sh b/t/t1301-shared-repo.sh
index dfece751b5..2dc853d1be 100755
--- a/t/t1301-shared-repo.sh
+++ b/t/t1301-shared-repo.sh
@@ -136,7 +136,7 @@ test_expect_success POSIXPERM 'forced modes' '
 	(
 		cd new &&
 		umask 002 &&
-		git init --shared=0660 --template=../templates &&
+		git init --shared=0660 --template=templates &&
 		>frotz &&
 		git add frotz &&
 		git commit -a -m initial &&
@@ -192,7 +192,7 @@ test_expect_success POSIXPERM 're-init respects core.sharedrepository (remote)'
 	umask 0022 &&
 	git init --bare --shared=0666 child.git &&
 	test_path_is_missing child.git/foo &&
-	git init --bare --template=../templates child.git &&
+	git init --bare --template=templates child.git &&
 	echo "-rw-rw-rw-" >expect &&
 	test_modebits child.git/foo >actual &&
 	test_cmp expect actual
@@ -203,7 +203,7 @@ test_expect_success POSIXPERM 'template can set core.sharedrepository' '
 	umask 0022 &&
 	git config core.sharedrepository 0666 &&
 	cp .git/config templates/config &&
-	git init --bare --template=../templates child.git &&
+	git init --bare --template=templates child.git &&
 	echo "-rw-rw-rw-" >expect &&
 	test_modebits child.git/HEAD >actual &&
 	test_cmp expect actual
-- 
2.21.0.1141.gd54ac2cb17


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] init: make --template path relative to $CWD
  2019-05-10 10:46 [PATCH] init: make --template path relative to $CWD Nguyễn Thái Ngọc Duy
@ 2019-05-13  6:12 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2019-05-13  6:12 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> During git-init we chdir() to the target directory, but --template is
> not adjusted. So it's relative to the target directory instead of
> current directory.

> It would be ok if it's documented, but --template in git-init.txt
> mentions nothing about this behavior. Change it to be relative to $CWD,
> which is much more intuitive.
>
> The changes in the test suite show that this relative-to-target behavior
> is actually used. I just hope that it's only used in the test suite and
> it's safe to change. Otherwise, the other option is just document
> it (i.e. relative to target dir) and move on.

Yeah, that other option does sound safer, but ...

>  	mkdir template-source &&
>  	echo content >template-source/file &&
> -	git init --template=../template-source template-custom &&
> +	git init --template=template-source template-custom &&

... the example may show that the updated behaviour may match the
end-user expectation better.  It certainly is more in line with how
the "--reference" option of "git clone" uses a relative path.

It also makes it easier to <TAB> complete if these things were
relative to the current directory at the time of command
invocation.  I often find it frustrating when I have to create a
symbolic link in a directory I am not yet in that points to
somewhere using a relative path for the exact reason ;-)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-05-13  6:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-10 10:46 [PATCH] init: make --template path relative to $CWD Nguyễn Thái Ngọc Duy
2019-05-13  6:12 ` Junio C Hamano

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).