]> git.ipfire.org Git - thirdparty/git.git/blame - git-ls-remote.sh
Use symbolic name SHORT_NAME_AMBIGUOUS as error return value
[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
26 exec="--exec=$1"
27 shift;;
0fec0822
JH
28 --)
29 shift; break ;;
30 -*)
31 usage ;;
32 *)
33 break ;;
34 esac
35done
36
972b6fe7 37case "$#" in 0) usage ;; esac
0fec0822
JH
38
39case ",$heads,$tags," in
40,,,) heads=heads tags=tags other=other ;;
41esac
42
215a7ad1 43. git-parse-remote
e0bfc81e 44peek_repo="$(get_remote_url "$@")"
972b6fe7 45shift
0fec0822
JH
46
47tmp=.ls-remote-$$
48trap "rm -fr $tmp-*" 0 1 2 3 15
49tmpdir=$tmp-d
50
51case "$peek_repo" in
52http://* | https://* )
53 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
54 curl_extra_args="-k"
55 fi
a5cd85e0
JH
56 curl -nsf $curl_extra_args "$peek_repo/info/refs" ||
57 echo "failed slurping"
0fec0822
JH
58 ;;
59
60rsync://* )
61 mkdir $tmpdir
a5cd85e0
JH
62 rsync -rq "$peek_repo/refs" $tmpdir || {
63 echo "failed slurping"
64 exit
65 }
0fec0822
JH
66 (cd $tmpdir && find refs -type f) |
67 while read path
68 do
69 cat "$tmpdir/$path" | tr -d '\012'
70 echo " $path"
71 done &&
72 rm -fr $tmpdir
73 ;;
74
75* )
96b086d6 76 git-peek-remote $exec "$peek_repo" ||
a5cd85e0 77 echo "failed slurping"
0fec0822
JH
78 ;;
79esac |
972b6fe7 80sort -t ' ' -k 2 |
0fec0822
JH
81while read sha1 path
82do
a5cd85e0
JH
83 case "$sha1" in
84 failed)
85 die "Failed to find remote refs"
86 esac
0fec0822
JH
87 case "$path" in
88 refs/heads/*)
89 group=heads ;;
90 refs/tags/*)
91 group=tags ;;
92 *)
93 group=other ;;
94 esac
95 case ",$heads,$tags,$other," in
96 *,$group,*)
97 ;;
98 *)
99 continue;;
100 esac
972b6fe7
JH
101 case "$#" in
102 0)
103 match=yes ;;
104 *)
105 match=no
106 for pat
107 do
108 case "/$path" in
109 */$pat )
110 match=yes
111 break ;;
112 esac
113 done
0fec0822 114 esac
972b6fe7
JH
115 case "$match" in
116 no)
117 continue ;;
118 esac
119 echo "$sha1 $path"
0fec0822 120done