{"thread":{"id":"23946","subject":"[RFC] Storing empty directories in Git","startedAt":"2010-05-30T14:29:11Z","lastAt":"2010-05-30T14:29:11Z","messageCount":1,"participants":["Øyvind A. Holm"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"142574","messageId":"20100530142908.GA7180@triton","threadId":"23946","inReplyTo":null,"subject":"[RFC] Storing empty directories in Git","fromName":"Øyvind A. Holm","fromEmail":"sunny@sunbase.org","sentAt":"2010-05-30T14:29:11Z","receivedAt":"2010-05-30T14:29:11Z","isPatch":false,"sender":{"key":"sunny@sunbase.org","avatar":"https://avatars.githubusercontent.com/u/113445?v=4"},"body":"I sometimes need to store empty directories in Git, and instead of \nputting empty .gitignore files everywhere as has been suggested, I \ncreated two small shell scripts (git-store-dirs and git-restore-dirs) to \nstore all empty directories in a file named \".emptydirs\" at the top of \nthe working tree. The directories are stored as null-separated strings \nto avoid problems with wacky things like \\n or semicolons in the \ndirectory names.\n\nIs this a viable method of fixing the emptydir problem? A default file \nname like \".gitdirectories\" could be used, or maybe it’s possible to \nstore a file like this inside the .git/ area if we can come up with a \nway to store this metadata properly.\n\nThe scripts are stored at http://gist.github.com/419015 , but I also \ninclude them here:\n\n### git-store-dirs {{{\n\n#!/bin/sh\n\n# git-store-dirs\n# Store a list of all directories to $dirfile to be able to restore empty \n# directories. The list is \\0-separated in case there are some directory names \n# containing (ugh) \\n. Use git-restore-dirs(1) to recreate directories.\n\ndirfile=.emptydirs\ntest -d .git/. || { echo $0: Has to be run from the toplevel of the working tree >&2; exit 1; }\nfind -type d -empty -print0 | grep -E -v -z '/\\.git(/|$)' | LC_ALL=C sort -z >$dirfile\ngit add $dirfile\n\n### }}}\n### git-restore-dirs {{{\n\n#!/bin/sh\n\n# git-restore-dirs\n# Restore empty directories created by git-store-dirs(1)\n\ndirfile=.emptydirs\ntest -d .git/. || { echo $0: Has to be run from the toplevel of the working tree >&2; exit 1; }\ntest -e $dirfile || { echo $0: No $dirfile file found >&2; exit 1; }\nxargs -0 mkdir -p <$dirfile\n\n### }}}\n\nCheers,\nØyvind\n\n+-| Øyvind A. Holm <sunny@sunbase.org> - N 60.39548° E 5.31735° |-+\n| OpenPGP: 0xFB0CBEE894A506E5 - http://www.sunbase.org/pubkey.asc |\n| Fingerprint: A006 05D6 E676 B319 55E2  E77E FB0C BEE8 94A5 06E5 |\n+------------| 06a9d9be-6bf2-11df-8623-90e6ba3022ac |-------------+\n"}]}