Merge branch 'lt/gitweb'
[git/jrn.git] / git-ls-remote.sh
blob2fdcaf7886850b1f59a1775bffc23948d1b62c6a
1 #!/bin/sh
4 usage () {
5 echo >&2 "usage: $0 [--heads] [--tags] [-u|--upload-pack <upload-pack>]"
6 echo >&2 " <repository> <refs>..."
7 exit 1;
10 die () {
11 echo >&2 "$*"
12 exit 1
15 exec=
16 while case "$#" in 0) break;; esac
18 case "$1" in
19 -h|--h|--he|--hea|--head|--heads)
20 heads=heads; shift ;;
21 -t|--t|--ta|--tag|--tags)
22 tags=tags; shift ;;
23 -u|--u|--up|--upl|--uploa|--upload|--upload-|--upload-p|--upload-pa|\
24 --upload-pac|--upload-pack)
25 shift
26 exec="--exec=$1"
27 shift;;
28 --)
29 shift; break ;;
30 -*)
31 usage ;;
33 break ;;
34 esac
35 done
37 case "$#" in 0) usage ;; esac
39 case ",$heads,$tags," in
40 ,,,) heads=heads tags=tags other=other ;;
41 esac
43 . git-parse-remote
44 peek_repo="$(get_remote_url "$@")"
45 shift
47 tmp=.ls-remote-$$
48 trap "rm -fr $tmp-*" 0 1 2 3 15
49 tmpdir=$tmp-d
51 case "$peek_repo" in
52 http://* | https://* )
53 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
54 curl_extra_args="-k"
56 curl -nsf $curl_extra_args --header "Pragma: no-cache" "$peek_repo/info/refs" ||
57 echo "failed slurping"
60 rsync://* )
61 mkdir $tmpdir &&
62 rsync -rlq "$peek_repo/HEAD" $tmpdir &&
63 rsync -rq "$peek_repo/refs" $tmpdir || {
64 echo "failed slurping"
65 exit
67 head=$(cat "$tmpdir/HEAD") &&
68 case "$head" in
69 ref:' '*)
70 head=$(expr "z$head" : 'zref: \(.*\)') &&
71 head=$(cat "$tmpdir/$head") || exit
72 esac &&
73 echo "$head HEAD"
74 (cd $tmpdir && find refs -type f) |
75 while read path
77 cat "$tmpdir/$path" | tr -d '\012'
78 echo " $path"
79 done &&
80 rm -fr $tmpdir
83 * )
84 git-peek-remote $exec "$peek_repo" ||
85 echo "failed slurping"
87 esac |
88 sort -t ' ' -k 2 |
89 while read sha1 path
91 case "$sha1" in
92 failed)
93 die "Failed to find remote refs"
94 esac
95 case "$path" in
96 refs/heads/*)
97 group=heads ;;
98 refs/tags/*)
99 group=tags ;;
101 group=other ;;
102 esac
103 case ",$heads,$tags,$other," in
104 *,$group,*)
107 continue;;
108 esac
109 case "$#" in
111 match=yes ;;
113 match=no
114 for pat
116 case "/$path" in
117 */$pat )
118 match=yes
119 break ;;
120 esac
121 done
122 esac
123 case "$match" in
125 continue ;;
126 esac
127 echo "$sha1 $path"
128 done