git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Øyvind A. Holm" <sunny@sunbase.org>
To: git@vger.kernel.org
Subject: [RFC] Storing empty directories in Git
Date: Sun, 30 May 2010 16:29:11 +0200	[thread overview]
Message-ID: <20100530142908.GA7180@triton> (raw)

[-- 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 --]

                 reply	other threads:[~2010-05-30 14:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100530142908.GA7180@triton \
    --to=sunny@sunbase.org \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).