Code

GIT 0.99.8c
[git.git] / git-ls-remote.sh
1 #!/bin/sh
2 #
3 . git-sh-setup || die "Not a git archive"
5 usage () {
6     echo >&2 "usage: $0 [--heads] [--tags] <repository> <refs>..."
7     exit 1;
8 }
10 while case "$#" in 0) break;; esac
11 do
12   case "$1" in
13   -h|--h|--he|--hea|--head|--heads)
14   heads=heads; shift ;;
15   -t|--t|--ta|--tag|--tags)
16   tags=tags; shift ;;
17   --)
18   shift; break ;;
19   -*)
20   usage ;;
21   *)
22   break ;;
23   esac
24 done
26 case "$#" in 0) usage ;; esac
28 case ",$heads,$tags," in
29 ,,,) heads=heads tags=tags other=other ;;
30 esac
32 . git-parse-remote
33 peek_repo="$(get_remote_url "$@")"
34 shift
36 tmp=.ls-remote-$$
37 trap "rm -fr $tmp-*" 0 1 2 3 15
38 tmpdir=$tmp-d
40 case "$peek_repo" in
41 http://* | https://* )
42         if [ -n "$GIT_SSL_NO_VERIFY" ]; then
43             curl_extra_args="-k"
44         fi
45         curl -nsf $curl_extra_args "$peek_repo/info/refs" ||
46                 echo "failed    slurping"
47         ;;
49 rsync://* )
50         mkdir $tmpdir
51         rsync -rq "$peek_repo/refs" $tmpdir || {
52                 echo "failed    slurping"
53                 exit
54         }
55         (cd $tmpdir && find refs -type f) |
56         while read path
57         do
58                 cat "$tmpdir/$path" | tr -d '\012'
59                 echo "  $path"
60         done &&
61         rm -fr $tmpdir
62         ;;
64 * )
65         git-peek-remote "$peek_repo" ||
66                 echo "failed    slurping"
67         ;;
68 esac |
69 sort -t '       ' -k 2 |
70 while read sha1 path
71 do
72         case "$sha1" in
73         failed)
74                 die "Failed to find remote refs"
75         esac
76         case "$path" in
77         refs/heads/*)
78                 group=heads ;;
79         refs/tags/*)
80                 group=tags ;;
81         *)
82                 group=other ;;
83         esac
84         case ",$heads,$tags,$other," in
85         *,$group,*)
86                 ;;
87         *)
88                 continue;;
89         esac
90         case "$#" in
91         0)
92                 match=yes ;;
93         *)
94                 match=no
95                 for pat
96                 do
97                         case "/$path" in
98                         */$pat )
99                                 match=yes
100                                 break ;;
101                         esac
102                 done
103         esac
104         case "$match" in
105         no)
106                 continue ;;
107         esac
108         echo "$sha1     $path"
109 done