[RFC] Storing empty directories in Git

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx> - 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: signature.asc
Description: Digital signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]