Test commit
[cogito/jonas.git] / cg-admin-cat
blobf8ec853f9d9507429527f692d0046efbc00a0395
1 #!/usr/bin/env bash
3 # Cat file(s) by filename from given tree or revision
4 # Copyright (c) John Ellson, 2005
6 # Cat a file of a given filename in a given revision (or in the current
7 # one) to stdout.
9 # OPTIONS
10 # -------
11 # -r TREE_ID:: Look for file in the given revision or tree
12 # ID of the revision or tree where to look for the file, instead of
13 # HEAD.
15 # Testsuite: TODO
17 # The tale of birth:
18 # Initiated from a request from: erg@research.att.com
19 # for an equivalent to "cvs co -p <filename>"
20 # Question posted with really bad initial solution: ellson@research.att.com
21 # Suggestions offered by: Johannes.Schindelin@gmx.de
22 # rene.scharfe@lsrfire.ath.cx
23 # This solution based on posting from: torvalds@osdl.org
24 # Polish and test by: ellson@research.att.com
26 USAGE="cg-admin-cat [-r TREE_ID] FILE..."
27 _git_wc_unneeded=1
29 . "${COGITO_LIB}"cg-Xlib || exit 1
31 rev=HEAD
32 while optparse; do
33 if optparse -r=; then
34 rev="$OPTARG"
35 else
36 optfail
38 done
40 [ ${#ARGS[*]} -ge 1 ] || usage
42 id=$(cg-object-id -t "$rev") || exit 1
44 git-ls-tree "$id" "${ARGS[@]}" |
45 while read -r mode type sha name
47 case "$type" in
48 blob)
49 git-cat-file blob "$sha"
51 tree)
52 git-ls-tree "$sha"
55 exit 1
57 esac
58 done