threads / discuss / 51793

Git does not recognise directory named '${sys:DATA_ROOT_DIR}'

Subject: Git does not recognise directory named '${sys:DATA_ROOT_DIR}'

## tl;dr

6 messages between Sep 3, 2019 and Sep 3, 2019.

replies: 5people: 4as markdown or json

Σταύρος Ντέντος· Sep 3, 2019, 12:44 UTC · lore
Hello there,

While the name is obviously a mistake, git refuses to even acknowledge the directory.

``` u@h:~/$ mkdir init-test u@h:~/$ cd init-test u@h:~/init-test$ git init Initialized empty Git repository in /home/u/init-test/.git/ u@h:~/init-test$ (master #) mkdir \$\{sys\:DATA_ROOT_DIR\}/ u@h:~/init-test$ (master #) git status On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track) u@h:~/init-test$ (master #) git add .git/ ${sys:DATA_ROOT_DIR}/ u@h:~/init-test$ (master #) git add \$\{sys\:DATA_ROOT_DIR\}/ u@h:~/init-test$ (master #) git commit --signoff -m'a' On branch master

Initial commit

nothing to commit u@h:~/init-test$ (master #) ```

Is that expected?
Ντέντος Σταύρος
Taylor Blau· Sep 3, 2019, 13:34 UTC · re: Σταύρος Ντέντος · lore

Re: Git does not recognise directory named '${sys:DATA_ROOT_DIR}'

Hi,
On Tue, Sep 03, 2019 at 03:44:14PM +0300, Σταύρος Ντέντος wrote:
Show 30 quoted lines
> Hello there,
>
> While the name is obviously a mistake, git refuses to even acknowledge
> the directory.
>
> ```
> u@h:~/$ mkdir init-test
> u@h:~/$ cd init-test
> u@h:~/init-test$ git init
> Initialized empty Git repository in /home/u/init-test/.git/
> u@h:~/init-test$ (master #) mkdir \$\{sys\:DATA_ROOT_DIR\}/
> u@h:~/init-test$ (master #) git status
> On branch master
>
> No commits yet
>
> nothing to commit (create/copy files and use "git add" to track)
> u@h:~/init-test$ (master #) git add
> .git/                    ${sys:DATA_ROOT_DIR}/
> u@h:~/init-test$ (master #) git add \$\{sys\:DATA_ROOT_DIR\}/
> u@h:~/init-test$ (master #) git commit --signoff -m'a'
> On branch master
>
> Initial commit
>
> nothing to commit
> u@h:~/init-test$ (master #)
> ```
>
> Is that expected?

Git does not track empty trees; that is to say 'git add' on an empty directory does not change the status of the index.

Try for example:
  $ git init repo && cd repo
  $ mkdir -p dir
  $ git add dir
  $ git status
And note that 'git status' says there are no changes.

On the other hand, 'git add' performs fine even in a directory named '${sys:DATA_ROOT_DIR}'; simply create a file (even an empty one) within that directory and then run 'git add'. It will stage your "changes" as expected.

If you wish to keep this directory "empty", but stored in Git, a common convention is to create an empty '.gitkeep' file in the directory. This file is not special in any way to Git, rather it serves as _a_ file to keep the directory non-empty.

Hope this helps.
> Ντέντος Σταύρος

Thanks, Taylor

Σταύρος Ντέντος· Sep 3, 2019, 14:11 UTC · re: Taylor Blau · lore

Re: Git does not recognise directory named '${sys:DATA_ROOT_DIR}'

Hey Taylor,

This was happening on a (much) more massive repository; I simply tried to dumb down the example.

The original folder did had a folder structure 3 levels deep. Unfortunately, I don't remember if the leaves were files (or directories themselves). However, since I "replicated" it, I went ahead and cleaned up my main repo (sigh).

Thank you for reminding me of the empty-tree case :-)
(Reply-all missed the list)
-- 
Until next time,
Ντέντος Σταύρος

On Tue, Sep 3, 2019 at 4:34 PM Taylor Blau <me@ttaylorr.com> wrote:
>
> Hi,
>
> On Tue, Sep 03, 2019 at 03:44:14PM +0300, Σταύρος Ντέντος wrote:
> > Hello there,
> >
> > While the name is obviously a mistake, git refuses to even acknowledge
> > the directory.
> >
> > ```
> > u@h:~/$ mkdir init-test
> > u@h:~/$ cd init-test
> > u@h:~/init-test$ git init
> > Initialized empty Git repository in /home/u/init-test/.git/
> > u@h:~/init-test$ (master #) mkdir \$\{sys\:DATA_ROOT_DIR\}/
> > u@h:~/init-test$ (master #) git status
> > On branch master
> >
> > No commits yet
> >
> > nothing to commit (create/copy files and use "git add" to track)
> > u@h:~/init-test$ (master #) git add
> > .git/                    ${sys:DATA_ROOT_DIR}/
> > u@h:~/init-test$ (master #) git add \$\{sys\:DATA_ROOT_DIR\}/
> > u@h:~/init-test$ (master #) git commit --signoff -m'a'
> > On branch master
> >
> > Initial commit
> >
> > nothing to commit
> > u@h:~/init-test$ (master #)
> > ```
> >
> > Is that expected?
>
> Git does not track empty trees; that is to say 'git add' on an empty
> directory does not change the status of the index.
>
> Try for example:
>
>   $ git init repo && cd repo
>   $ mkdir -p dir
>   $ git add dir
>   $ git status
>
> And note that 'git status' says there are no changes.
>
> On the other hand, 'git add' performs fine even in a directory named
> '${sys:DATA_ROOT_DIR}'; simply create a file (even an empty one) within
> that directory and then run 'git add'. It will stage your "changes" as
> expected.
>
> If you wish to keep this directory "empty", but stored in Git, a common
> convention is to create an empty '.gitkeep' file in the directory. This
> file is not special in any way to Git, rather it serves as _a_ file to
> keep the directory non-empty.
>
> Hope this helps.
>
> > Ντέντος Σταύρος
>
> Thanks,
> Taylor
Philip Oakley· Sep 3, 2019, 16:45 UTC · re: Σταύρος Ντέντος · lore

Re: Git does not recognise directory named '${sys:DATA_ROOT_DIR}'

On 03/09/2019 15:11, Σταύρος Ντέντος wrote:
Show 6 quoted lines
> The original folder did had a folder structure 3 levels deep.
> Unfortunately, I don't remember if the leaves were files (or
> directories themselves). However, since I "replicated" it, I went
> ahead and cleaned up my main repo (sigh).
>
> Thank you for reminding me of the empty-tree case :-)

Makes me wonder if git status could maybe warn about empty trees as 'untracked'?

Philip
Junio C Hamano· Sep 3, 2019, 19:08 UTC · re: Taylor Blau · lore

Re: Git does not recognise directory named '${sys:DATA_ROOT_DIR}'

Taylor Blau <me@ttaylorr.com> writes:
> If you wish to keep this directory "empty", but stored in Git, a common
> convention is to create an empty '.gitkeep' file in the directory. This
> file is not special in any way to Git, rather it serves as _a_ file to
> keep the directory non-empty.

Hmph, I thought the common convention was to create a ".gitignore" file in the directory with catch-all pattern, so that no matter what cruft you had there "git add" will not add anything from it, if you wish to keep this directory "empty".

Σταύρος Ντέντος· Sep 3, 2019, 19:55 UTC · re: Junio C Hamano · lore

Re: Git does not recognise directory named '${sys:DATA_ROOT_DIR}'

> Makes me wonder if git status could maybe warn about empty trees as 'untracked'?

Well, I "suppose" git-add could warn you that you are adding an empty tree (and I'd like if that happened, implicit vs explicit action i.e. ignoring). However, I assume the no-empty-tree case was a design decision; hence, it's been 2.2# versions without such warning.

I doubt it would be considered to be added now.
On Tue, Sep 3, 2019 at 10:08 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 12 quoted lines
>
> Taylor Blau <me@ttaylorr.com> writes:
>
> > If you wish to keep this directory "empty", but stored in Git, a common
> > convention is to create an empty '.gitkeep' file in the directory. This
> > file is not special in any way to Git, rather it serves as _a_ file to
> > keep the directory non-empty.
>
> Hmph, I thought the common convention was to create a ".gitignore"
> file in the directory with catch-all pattern, so that no matter what
> cruft you had there "git add" will not add anything from it, if you
> wish to keep this directory "empty".

I believe Taylor is talking about explicitly keeping a directory empty, that may or may not, in the future, contain files (that will be tracked) [1]. You are infering that, regardless if there are files or will be added in the future, you don't want to check anything in.

While [1] is a very niche corner case (and maybe it doesn't make sense to the most of us, true), there is a "debian-equivalent" behavior https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=812223

(I cannot find the definition of this behavior, but you can see an example usecase)

← back to recent threads