Empty folder in git

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
milovan's picture

I noticed some modules (like GMap) have empty folder in its Git repo. By default, Git doesn't register empty folder. If so, then how does Drupal.org git system accept empty folders into repository?

Comments

.gitkeep

mparker17's picture

I couldn't find any empty folders in the 7.x-2.x, 7.x-1.x, 6.x-2.x, or 6.x-1.x versions of the gmap module: if you're running one of those versions, and you can see an empty folder in that module, then something else has emptied that folder on your filesystem.

There are a few folders which contain only a README.txt: perhaps someone ran a script to delete all the text files? (deleting CHANGELOGs and READMEs is a common security practice to attempt to prevent people from finding out which version of Drupal core / modules you are running)


Git doesn't "see" directories; only files with paths, so Git can't really track empty directories, and there is no "official" way to track them. A common practice is to add an empty file named .gitkeep (which Git can track) to tell Git to "keep" the directory. Since the file name begins with a dot, it is hidden on most Linux/Mac systems by default, and thus, not easily deleted by accident.

From the command line, you can run...

$ mkdir -p some/path
$ touch some/path/.gitkeep
$ git add some/path/.gitkeep
$ git commit

... to create the "empty" directory some/path that you want to keep, add an empty .gitkeep file to it, add the .gitkeep file to Git's staging area, and then commit it.

Hey thanks. I know that way

milovan's picture

Hey thanks. I know that way for placing hidden file in folder, which will make git commit that folder as there is file in it. git doesn't care or operate with folders, it always tracks files only.

But! In gmap module (version for D7, you can clone their git repo), there IS empty folder under vendor, called "sfEasyGMapPlugin", and it has no hidden files in it! My question is, how? This shouldn't be possible with Git.

sfEasyGMapPlugin is a broken git submodule

mparker17's picture

Hi @milovan, thanks for clarifying.

vendor/sfEasyGMapPlugin is actually a Git submodule — a place where Git is supposed to clone another repo at a commit 2f0a80c; but it shows up because it is broken because there is no corresponding .gitmodules file at the root of the gmap repository to tell it which other repo to clone:

$ git clone --branch 7.x-2.x https://git.drupal.org/project/gmap.git
$ cd gmap
$ git submodule init
fatal: No url found for submodule path 'vendor/sfEasyGMapPlugin' in .gitmodules

Ok, great explanation

milovan's picture

Ok, great explanation @mparker17! I got it, thanks a lot

Drupal And Git

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week