Merge refs/heads/master from .
[git.git] / git-ls-remote-script
1 #!/bin/sh
2 #
3 . git-sh-setup-script || die "Not a git archive"
4
5 usage () {
6     echo >&2 "usage: $0 [--heads] [--tags] <repository> <refs>..."
7     exit 1;
8 }
9
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
25
26 case "$#" in 0) usage ;; esac
27
28 case ",$heads,$tags," in
29 ,,,) heads=heads tags=tags other=other ;;
30 esac
31
32 . git-parse-remote-script
33 peek_repo="$(get_remote_url "$@")"
34 shift
35
36 tmp=.ls-remote-$$
37 trap "rm -fr $tmp-*" 0 1 2 3 15
38 tmpdir=$tmp-d
39
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" || exit 1
46         ;;
47
48 rsync://* )
49         mkdir $tmpdir
50         rsync -rq "$peek_repo/refs" $tmpdir || exit 1
51         (cd $tmpdir && find refs -type f) |
52         while read path
53         do
54                 cat "$tmpdir/$path" | tr -d '\012'
55                 echo "  $path"
56         done &&
57         rm -fr $tmpdir
58         ;;
59
60 * )
61         git-peek-remote "$peek_repo"
62         ;;
63 esac |
64 sort -t '       ' -k 2 |
65 while read sha1 path
66 do
67         case "$path" in
68         refs/heads/*)
69                 group=heads ;;
70         refs/tags/*)
71                 group=tags ;;
72         *)
73                 group=other ;;
74         esac
75         case ",$heads,$tags,$other," in
76         *,$group,*)
77                 ;;
78         *)
79                 continue;;
80         esac
81         case "$#" in
82         0)
83                 match=yes ;;
84         *)
85                 match=no
86                 for pat
87                 do
88                         case "/$path" in
89                         */$pat )
90                                 match=yes
91                                 break ;;
92                         esac
93                 done
94         esac
95         case "$match" in
96         no)
97                 continue ;;
98         esac
99         echo "$sha1     $path"
100 done