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