threads / discuss / 45161

dotfiles in git template dir are not copied

Subject: dotfiles in git template dir are not copied

## tl;dr

12 messages between Feb 17, 2017 and Feb 17, 2017.

replies: 11people: 4as markdown or json

greg0ire· Feb 17, 2017, 09:31 UTC · lore
Hi,

I noticed yesterday that dotfiles inside the directory configured in init.templatedir are not copied when creating a new repository.

Here is the line I think is responsible for this behavior : https://github.com/git/git/blob/master/builtin/init-db.c#L48

Is it a bug or a feature?
Steps to reproduce, provided you already have a template dir configured :

cd $(git config --path --get init.templatedir) touch copied touch .not_copied cd /tmp mkdir whatever cd whatever git init ls -la .git

On my machine, the last command does not list .not_copied .

-- greg0ire

Jeff King· Feb 17, 2017, 20:44 UTC · re: greg0ire · lore

Re: dotfiles in git template dir are not copied

On Fri, Feb 17, 2017 at 10:31:37AM +0100, greg0ire wrote:
Show 7 quoted lines
> I noticed yesterday that dotfiles inside the directory configured in
> init.templatedir are not copied when creating a new repository.
> 
> Here is the line I think is responsible for this behavior :
> https://github.com/git/git/blob/master/builtin/init-db.c#L48
> 
> Is it a bug or a feature?

I think it's probably a feature. You could, for example, have your template directory itself be a git repository. You would not want to copy the ".git" directory around.

I wouldn't be surprised if the documentation could be improved, though.
-Peff
Grégoire PARIS· Feb 17, 2017, 21:42 UTC · re: Jeff King · lore

Re: Re: dotfiles in git template dir are not copied

 > You could, for example, have your template directory itself be a git 
repository.

I can and I do and indeed, that might be the reason behind this. I made a PR to document this : https://github.com/git/git/pull/325

-- greg0ire

Junio C Hamano· Feb 17, 2017, 22:12 UTC · re: Grégoire PARIS · lore

Re: dotfiles in git template dir are not copied

Grégoire PARIS <postmaster@greg0ire.fr> writes:
>> You could, for example, have your template directory itself be a git 
> repository.
>
> I can and I do and indeed, that might be the reason behind this.

An embedded .git was _not_ the reason behind the current behaviour when we wrote it. The primary reason is because we did not ship and did not plan to ship anything .dot in our standard template set and there wasn't any reason to copy what we were not going to ever ship ;-).

As a justification after the fact, "you wouldn't want to copy .git do you?" is a good one, though, and I do not think we should change the behaviour to copy files whose names begin with a dot.

Grégoire PARIS· Feb 17, 2017, 22:37 UTC · re: Junio C Hamano · lore

Re: dotfiles in git template dir are not copied

 > I do not think we should change the behaviour
 > to copy files whose names begin with a dot.
So bug turned feature it is :)
I amended my commit message accordingly.

In my case, my template dir is not at the root of the repository where it is versioned, so it would not be a problem for me, but I think some people might use this feature to add tests/docs without having them copied.

my template dir repository : https://github.com/greg0ire/git_template
Junio C Hamano· Feb 17, 2017, 22:44 UTC · re: Grégoire PARIS · lore

Re: dotfiles in git template dir are not copied

Grégoire PARIS <postmaster@greg0ire.fr> writes:
>> I do not think we should change the behaviour
>> to copy files whose names begin with a dot.
>
> So bug turned feature it is :)
There was no 'bug' either.  It's just the way it is ;-)
Philip Oakley· Feb 17, 2017, 22:39 UTC · re: Grégoire PARIS · lore

Re: Re: dotfiles in git template dir are not copied

From: "Grégoire PARIS" <postmaster@greg0ire.fr>
Show 6 quoted lines
> > You could, for example, have your template directory itself be a git
> repository.
>
> I can and I do and indeed, that might be the reason behind this.
> I made a PR to document this : https://github.com/git/git/pull/325
>

While the PR is a simple one line change to the documention, the patch should be submitted to the list. See Documenation/SubmittingPatches

Don't forget to Sign Off your patch (see the Developer's Certificate of Origin section). -- Philip

Grégoire PARIS· Feb 17, 2017, 22:49 UTC · re: Philip Oakley · lore

Re: dotfiles in git template dir are not copied

Le 17/02/2017 à 23:39, Philip Oakley a écrit :
Show 16 quoted lines
> From: "Grégoire PARIS" <postmaster@greg0ire.fr>
>> > You could, for example, have your template directory itself be a git
>> repository.
>>
>> I can and I do and indeed, that might be the reason behind this.
>> I made a PR to document this : https://github.com/git/git/pull/325
>>
> While the PR is a simple one line change to the documention, the patch 
> should be submitted to the list.
> See Documenation/SubmittingPatches
>
> Don't forget to Sign Off your patch (see the Developer's Certificate 
> of Origin section).
> -- 
> Philip
>

Ok sorry, I'll fix this rightaway! -- greg0ire

Junio C Hamano· Feb 17, 2017, 22:56 UTC · re: Grégoire PARIS · lore

Re: dotfiles in git template dir are not copied

Grégoire PARIS <postmaster@greg0ire.fr> writes:
Show 5 quoted lines
>> You could, for example, have your template directory itself be a git 
> repository.
>
> I can and I do and indeed, that might be the reason behind this.
> I made a PR to document this : https://github.com/git/git/pull/325
Let's take a look.
Show 12 quoted lines
> From: Grégoire PARIS <postmaster@greg0ire.fr>
> Date: Fri, 17 Feb 2017 22:33:40 +0100
> Subject: [PATCH] Document dotfiles exclusion on template copy
> 
> Since there is no dotfile in the default template directory, there was
> no point in making the check for . or .. more accurate when copying. Now
> that you can customize the template directory, it would make sense, but
> it's actually a good thing to at this because you would not want to have
> your git directory copied in every git directory that is created should
> you decide to put your template directory under version control. Plus it
> might be used as a feature by people who would want to exclude some
> files.
OK.
> See https://public-inbox.org/git/20170217204411.2yixhuazgczxmmxa@sigill.intra.peff.net/T/#t
I do not think what was discussed there adds much.  Drop this line.
Instead, add your sign-off (Documentation/SubmittingPatches) here
    Signed-off-by: Grégoire PARIS <postmaster@greg0ire.fr>
Show 14 quoted lines
> ---
>  Documentation/git-init.txt | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/Documentation/git-init.txt b/Documentation/git-init.txt
> index 9d27197de8..e3b185cf86 100644
> --- a/Documentation/git-init.txt
> +++ b/Documentation/git-init.txt
> @@ -117,7 +117,7 @@ TEMPLATE DIRECTORY
>  ------------------
>  
>  The template directory contains files and directories that will be copied to
> -the `$GIT_DIR` after it is created.
> +the `$GIT_DIR` after it is created, unless their name starts with a dot.

"... that will be copied ..., unless they are dot" is not incorrect per-se, but perhaps rewriting the whole sentence, e.g. "Files and directories in the template directory whose name do not start with a dot will be copied to ...", may make it easier to read, I suspect.

Grégoire PARIS· Feb 17, 2017, 23:30 UTC · re: Grégoire PARIS · lore

Re: dotfiles in git template dir are not copied

 > Thanks for your guidance. I believe I just sent the patch to the 
mailing list.

I just retried with the Gmail SMTP, and now I am sure it worked. Sorry for the noobery.

← back to recent threads