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