]> git.ipfire.org Git - thirdparty/git.git/blame - git-ls-remote.sh
GIT-VERSION-FILE: check ./version first.
[thirdparty/git.git] / git-ls-remote.sh
CommitLineData
0fec0822
JH
1#!/bin/sh
2#
0fec0822
JH
3
4usage () {
96b086d6
MO
5 echo >&2 "usage: $0 [--heads] [--tags] [-u|--upload-pack <upload-pack>]"
6 echo >&2 " <repository> <refs>..."
0fec0822
JH
7 exit 1;
8}
9
1abacf3b
JH
10die () {
11 echo >&2 "$*"
12 exit 1
13}
14
96b086d6 15exec=
0fec0822
JH
16while case "$#" in 0) break;; esac
17do
18 case "$1" in
19 -h|--h|--he|--hea|--head|--heads)
20 heads=heads; shift ;;
0fec0822
JH
21 -t|--t|--ta|--tag|--tags)
22 tags=tags; shift ;;
96b086d6
MO
23 -u|--u|--up|--upl|--uploa|--upload|--upload-|--upload-p|--upload-pa|\
24 --upload-pac|--upload-pack)
25 shift
ae1dffcb
JH
26 exec="--upload-pack=$1"
27 shift;;
28 -u=*|--u=*|--up=*|--upl=*|--uplo=*|--uploa=*|--upload=*|\
29 --upload-=*|--upload-p=*|--upload-pa=*|--upload-pac=*|--upload-pack=*)
4a91a1f3 30 exec=--upload-pack=$(expr "z$1" : 'z-[^=]*=\(.*\)')
96b086d6 31 shift;;
0fec0822
JH
32 --)
33 shift; break ;;
34 -*)
35 usage ;;
36 *)
37 break ;;
38 esac
39done
40
972b6fe7 41case "$#" in 0) usage ;; esac
0fec0822
JH
42
43case ",$heads,$tags," in
44,,,) heads=heads tags=tags other=other ;;
45esac
46
215a7ad1 47. git-parse-remote
e0bfc81e 48peek_repo="$(get_remote_url "$@")"
972b6fe7 49shift
0fec0822
JH
50
51tmp=.ls-remote-$$
52trap "rm -fr $tmp-*" 0 1 2 3 15
53tmpdir=$tmp-d
54
55case "$peek_repo" in
38529e28 56http://* | https://* | ftp://* )
0fec0822
JH
57 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
58 curl_extra_args="-k"
59 fi
3ea099d4 60 if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
e0d10e1c 61 "`git-config --bool http.noEPSV`" = true ]; then
3ea099d4
SK
62 curl_extra_args="${curl_extra_args} --disable-epsv"
63 fi
7fa8ddd6 64 curl -nsf $curl_extra_args --header "Pragma: no-cache" "$peek_repo/info/refs" ||
a5cd85e0 65 echo "failed slurping"
0fec0822
JH
66 ;;
67
68rsync://* )
e686eba4
JH
69 mkdir $tmpdir &&
70 rsync -rlq "$peek_repo/HEAD" $tmpdir &&
a5cd85e0
JH
71 rsync -rq "$peek_repo/refs" $tmpdir || {
72 echo "failed slurping"
73 exit
74 }
e686eba4
JH
75 head=$(cat "$tmpdir/HEAD") &&
76 case "$head" in
77 ref:' '*)
78 head=$(expr "z$head" : 'zref: \(.*\)') &&
79 head=$(cat "$tmpdir/$head") || exit
80 esac &&
81 echo "$head HEAD"
0fec0822
JH
82 (cd $tmpdir && find refs -type f) |
83 while read path
84 do
85 cat "$tmpdir/$path" | tr -d '\012'
86 echo " $path"
87 done &&
88 rm -fr $tmpdir
89 ;;
90
91* )
96b086d6 92 git-peek-remote $exec "$peek_repo" ||
a5cd85e0 93 echo "failed slurping"
0fec0822
JH
94 ;;
95esac |
972b6fe7 96sort -t ' ' -k 2 |
0fec0822
JH
97while read sha1 path
98do
a5cd85e0
JH
99 case "$sha1" in
100 failed)
b3d98993 101 exit 1 ;;
a5cd85e0 102 esac
0fec0822
JH
103 case "$path" in
104 refs/heads/*)
105 group=heads ;;
106 refs/tags/*)
107 group=tags ;;
108 *)
109 group=other ;;
110 esac
111 case ",$heads,$tags,$other," in
112 *,$group,*)
113 ;;
114 *)
115 continue;;
116 esac
972b6fe7
JH
117 case "$#" in
118 0)
119 match=yes ;;
120 *)
121 match=no
122 for pat
123 do
124 case "/$path" in
125 */$pat )
126 match=yes
127 break ;;
128 esac
129 done
0fec0822 130 esac
972b6fe7
JH
131 case "$match" in
132 no)
133 continue ;;
134 esac
135 echo "$sha1 $path"
0fec0822 136done