3 # Export contents of a particular revision
4 # Copyright (c) Johannes E. Schindelin, 2005
6 # Takes a destination and optionally a tree ID as a parameter,
7 # defaulting to 'HEAD'.
9 # The destination can be either a `.tar`, `.tar.gz`, `.tar.bz2` or `.tgz`
10 # for generating a tarball, or `.zip` for generating a zip file. Destination
11 # specifiers not ending by any of these extensions are assumed to be
12 # directory names, and the tree is exported to the given directory.
16 # -r TREE_ID:: Specify the tree version to export
17 # Base the export on the given tree.
21 USAGE
="cg-export [-r TREE_ID] DESTFILE"
25 .
"${COGITO_LIB}"cg-Xlib ||
exit 1
30 # We do not resolve to tree id since git-tar-tree can
31 # utilize some commit information.
32 id
="$(cg-object-id -c "$OPTARG" 2>/dev/null)" || id
="$OPTARG"
39 id
="$(cg-object-id -c)"
44 ([ -n "$dest" ] && [ -n "$id" ]) || usage
46 [ -e "$dest" ] && die
"$dest already exists."
49 *.
tar|
*.
tar.gz|
*.
tar.bz2|
*.tgz|
*.
zip)
57 git-archive
--format=tar --prefix="$base" "$id" |
gzip -c9 >"$dest"
60 git-archive
--format=tar --prefix="$base" "$id" |
bzip2 -c >"$dest"
63 git-archive
--format=tar --prefix="$base" "$id" >"$dest"
66 git-archive
--format=zip --prefix="$base" "$id" >"$dest"
71 mkdir
-p "$dest" || die
"cannot create $dest"
72 export GIT_INDEX_FILE
="$dest/.git-index"
73 id
="$(cg-object-id -t "$id")"
75 git-checkout-index
"--prefix=$dest/" -a