Merge git://git.kernel.org/pub/scm/gitk/gitk
[git/jnareb-git.git] / git-ls-remote.sh
blob03b624ef33dd3690a3cf24b4eaab830e5875789b
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://* | ftp://* )
53 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
54 curl_extra_args="-k"
56 if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
57 "`git-repo-config --bool http.noEPSV`" = true ]; then
58 curl_extra_args="${curl_extra_args} --disable-epsv"
60 curl -nsf $curl_extra_args --header "Pragma: no-cache" "$peek_repo/info/refs" ||
61 echo "failed slurping"
64 rsync://* )
65 mkdir $tmpdir &&
66 rsync -rlq "$peek_repo/HEAD" $tmpdir &&
67 rsync -rq "$peek_repo/refs" $tmpdir || {
68 echo "failed slurping"
69 exit
71 head=$(cat "$tmpdir/HEAD") &&
72 case "$head" in
73 ref:' '*)
74 head=$(expr "z$head" : 'zref: \(.*\)') &&
75 head=$(cat "$tmpdir/$head") || exit
76 esac &&
77 echo "$head HEAD"
78 (cd $tmpdir && find refs -type f) |
79 while read path
81 cat "$tmpdir/$path" | tr -d '\012'
82 echo " $path"
83 done &&
84 rm -fr $tmpdir
87 * )
88 git-peek-remote $exec "$peek_repo" ||
89 echo "failed slurping"
91 esac |
92 sort -t ' ' -k 2 |
93 while read sha1 path
95 case "$sha1" in
96 failed)
97 exit 1 ;;
98 esac
99 case "$path" in
100 refs/heads/*)
101 group=heads ;;
102 refs/tags/*)
103 group=tags ;;
105 group=other ;;
106 esac
107 case ",$heads,$tags,$other," in
108 *,$group,*)
111 continue;;
112 esac
113 case "$#" in
115 match=yes ;;
117 match=no
118 for pat
120 case "/$path" in
121 */$pat )
122 match=yes
123 break ;;
124 esac
125 done
126 esac
127 case "$match" in
129 continue ;;
130 esac
131 echo "$sha1 $path"
132 done