]> git.ipfire.org Git - thirdparty/git.git/blob - git-ls-remote.sh
Merge http://www.kernel.org/pub/scm/gitk/gitk
[thirdparty/git.git] / git-ls-remote.sh
1 #!/bin/sh
2 #
3
4 usage () {
5 echo >&2 "usage: $0 [--heads] [--tags] <repository> <refs>..."
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 ;;
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
25 case "$#" in 0) usage ;; esac
26
27 case ",$heads,$tags," in
28 ,,,) heads=heads tags=tags other=other ;;
29 esac
30
31 . git-parse-remote
32 peek_repo="$(get_remote_url "$@")"
33 shift
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
44 curl -nsf $curl_extra_args "$peek_repo/info/refs" ||
45 echo "failed slurping"
46 ;;
47
48 rsync://* )
49 mkdir $tmpdir
50 rsync -rq "$peek_repo/refs" $tmpdir || {
51 echo "failed slurping"
52 exit
53 }
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 * )
64 git-peek-remote "$peek_repo" ||
65 echo "failed slurping"
66 ;;
67 esac |
68 sort -t ' ' -k 2 |
69 while read sha1 path
70 do
71 case "$sha1" in
72 failed)
73 die "Failed to find remote refs"
74 esac
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
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
102 esac
103 case "$match" in
104 no)
105 continue ;;
106 esac
107 echo "$sha1 $path"
108 done