Merge branch 'sp/maint-no-thin' into maint
[git/git-p4.git] / git-ls-remote.sh
blobb7e5d0458470248e65da0893b8b9bb4ced9152da
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="--upload-pack=$1"
27 shift;;
28 -u=*|--u=*|--up=*|--upl=*|--uplo=*|--uploa=*|--upload=*|\
29 --upload-=*|--upload-p=*|--upload-pa=*|--upload-pac=*|--upload-pack=*)
30 exec=--upload-pack=$(expr "z$1" : 'z-[^=]*=\(.*\)')
31 shift;;
32 --)
33 shift; break ;;
34 -*)
35 usage ;;
37 break ;;
38 esac
39 done
41 case "$#" in 0) usage ;; esac
43 case ",$heads,$tags," in
44 ,,,) heads=heads tags=tags other=other ;;
45 esac
47 . git-parse-remote
48 peek_repo="$(get_remote_url "$@")"
49 shift
51 tmp=.ls-remote-$$
52 trap "rm -fr $tmp-*" 0 1 2 3 15
53 tmpdir=$tmp-d
55 case "$peek_repo" in
56 http://* | https://* | ftp://* )
57 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
58 curl_extra_args="-k"
60 if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
61 "`git config --bool http.noEPSV`" = true ]; then
62 curl_extra_args="${curl_extra_args} --disable-epsv"
64 curl -nsf $curl_extra_args --header "Pragma: no-cache" "$peek_repo/info/refs" ||
65 echo "failed slurping"
68 rsync://* )
69 mkdir $tmpdir &&
70 rsync -rlq "$peek_repo/HEAD" $tmpdir &&
71 rsync -rq "$peek_repo/refs" $tmpdir || {
72 echo "failed slurping"
73 exit
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"
82 (cd $tmpdir && find refs -type f) |
83 while read path
85 tr -d '\012' <"$tmpdir/$path"
86 echo " $path"
87 done &&
88 rm -fr $tmpdir
91 * )
92 if test -f "$peek_repo" ; then
93 git bundle list-heads "$peek_repo" ||
94 echo "failed slurping"
95 else
96 git-peek-remote $exec "$peek_repo" ||
97 echo "failed slurping"
100 esac |
101 sort -t ' ' -k 2 |
102 while read sha1 path
104 case "$sha1" in
105 failed)
106 exit 1 ;;
107 esac
108 case "$path" in
109 refs/heads/*)
110 group=heads ;;
111 refs/tags/*)
112 group=tags ;;
114 group=other ;;
115 esac
116 case ",$heads,$tags,$other," in
117 *,$group,*)
120 continue;;
121 esac
122 case "$#" in
124 match=yes ;;
126 match=no
127 for pat
129 case "/$path" in
130 */$pat )
131 match=yes
132 break ;;
133 esac
134 done
135 esac
136 case "$match" in
138 continue ;;
139 esac
140 echo "$sha1 $path"
141 done