git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] Storing empty directories in Git
@ 2010-05-30 14:29 Øyvind A. Holm
  0 siblings, 0 replies; only message in thread
From: Øyvind A. Holm @ 2010-05-30 14:29 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 1969 bytes --]

I sometimes need to store empty directories in Git, and instead of 
putting empty .gitignore files everywhere as has been suggested, I 
created two small shell scripts (git-store-dirs and git-restore-dirs) to 
store all empty directories in a file named ".emptydirs" at the top of 
the working tree. The directories are stored as null-separated strings 
to avoid problems with wacky things like \n or semicolons in the 
directory names.

Is this a viable method of fixing the emptydir problem? A default file 
name like ".gitdirectories" could be used, or maybe it’s possible to 
store a file like this inside the .git/ area if we can come up with a 
way to store this metadata properly.

The scripts are stored at http://gist.github.com/419015 , but I also 
include them here:

### git-store-dirs {{{

#!/bin/sh

# git-store-dirs
# Store a list of all directories to $dirfile to be able to restore empty 
# directories. The list is \0-separated in case there are some directory names 
# containing (ugh) \n. Use git-restore-dirs(1) to recreate directories.

dirfile=.emptydirs
test -d .git/. || { echo $0: Has to be run from the toplevel of the working tree >&2; exit 1; }
find -type d -empty -print0 | grep -E -v -z '/\.git(/|$)' | LC_ALL=C sort -z >$dirfile
git add $dirfile

### }}}
### git-restore-dirs {{{

#!/bin/sh

# git-restore-dirs
# Restore empty directories created by git-store-dirs(1)

dirfile=.emptydirs
test -d .git/. || { echo $0: Has to be run from the toplevel of the working tree >&2; exit 1; }
test -e $dirfile || { echo $0: No $dirfile file found >&2; exit 1; }
xargs -0 mkdir -p <$dirfile

### }}}

Cheers,
Øyvind

+-| Øyvind A. Holm <sunny@sunbase.org> - N 60.39548° E 5.31735° |-+
| OpenPGP: 0xFB0CBEE894A506E5 - http://www.sunbase.org/pubkey.asc |
| Fingerprint: A006 05D6 E676 B319 55E2  E77E FB0C BEE8 94A5 06E5 |
+------------| 06a9d9be-6bf2-11df-8623-90e6ba3022ac |-------------+

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-05-30 14:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-30 14:29 [RFC] Storing empty directories in Git Øyvind A. Holm

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 NNTP newsgroup(s).