]> git.ipfire.org Git - thirdparty/git.git/blame - git-ls-remote.sh
make patch_delta() error cases a bit more verbose
[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
38529e28 52http://* | https://* | ftp://* )
0fec0822
JH
53 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
54 curl_extra_args="-k"
55 fi
3ea099d4
SK
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"
59 fi
7fa8ddd6 60 curl -nsf $curl_extra_args --header "Pragma: no-cache" "$peek_repo/info/refs" ||
a5cd85e0 61 echo "failed slurping"
0fec0822
JH
62 ;;
63
64rsync://* )
e686eba4
JH
65 mkdir $tmpdir &&
66 rsync -rlq "$peek_repo/HEAD" $tmpdir &&
a5cd85e0
JH
67 rsync -rq "$peek_repo/refs" $tmpdir || {
68 echo "failed slurping"
69 exit
70 }
e686eba4
JH
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"
0fec0822
JH
78 (cd $tmpdir && find refs -type f) |
79 while read path
80 do
81 cat "$tmpdir/$path" | tr -d '\012'
82 echo " $path"
83 done &&
84 rm -fr $tmpdir
85 ;;
86
87* )
96b086d6 88 git-peek-remote $exec "$peek_repo" ||
a5cd85e0 89 echo "failed slurping"
0fec0822
JH
90 ;;
91esac |
972b6fe7 92sort -t ' ' -k 2 |
0fec0822
JH
93while read sha1 path
94do
a5cd85e0
JH
95 case "$sha1" in
96 failed)
97 die "Failed to find remote refs"
98 esac
0fec0822
JH
99 case "$path" in
100 refs/heads/*)
101 group=heads ;;
102 refs/tags/*)
103 group=tags ;;
104 *)
105 group=other ;;
106 esac
107 case ",$heads,$tags,$other," in
108 *,$group,*)
109 ;;
110 *)
111 continue;;
112 esac
972b6fe7
JH
113 case "$#" in
114 0)
115 match=yes ;;
116 *)
117 match=no
118 for pat
119 do
120 case "/$path" in
121 */$pat )
122 match=yes
123 break ;;
124 esac
125 done
0fec0822 126 esac
972b6fe7
JH
127 case "$match" in
128 no)
129 continue ;;
130 esac
131 echo "$sha1 $path"
0fec0822 132done