2 # usage: gitar foo-dir >foo.gitar
5 trap 'echo "Unexpected error!
6 I am leaving the .git subdirectory around so you can troubleshoot;
7 delete the subdirectory before trying to gitar again." 1>&2' ERR
10 if [ -e '.git' ]; then
11 echo 'The source directory is already a git repository!' 1>&2
15 if ! find . -type d -empty | cmp /dev/null - >/dev/null; then
16 echo 'WARNING: The source directory contains empty directories, and git will drop them.' 1>&2
20 git init-db >/dev/null
22 # Make a dummy commit to hold all the files.
23 function list-files-to-add {
24 find . -wholename './.git' -prune -or '(' -type f -or -type l ')' -printf '%P\n'
26 list-files-to-add | git update-index --add --stdin >/dev/null
27 tree=$(git write-tree)
28 function clean-commit {
29 GIT_AUTHOR_NAME='reproducible' GIT_AUTHOR_EMAIL='' GIT_AUTHOR_DATE='946684801 +0000' GIT_COMMITTER_NAME='reproducible' GIT_COMMITTER_EMAIL='' GIT_COMMITTER_DATE='946684801 +0000' git commit-tree "$@" </dev/null
31 clean-commit $tree >.git/refs/heads/master
33 # Pack things up nicely.
34 git repack -a >/dev/null
36 mv .git/objects/pack/{pack*.$i,pack.$i}
40 # Write out git repository as a Matt-style file tree.
43 stat --format=$'f %s' -- "$1/$2"
49 echo 'ref: refs/heads/master'
53 write_file .git/refs/heads master
58 write_file .git/objects/pack pack.pack
59 write_file .git/objects/pack pack.idx