ls-tree: work from subdirectory.
[git/dscho.git] / git-ls-remote.sh
blobdc6a775a9be83cfd349773b07051cd256d5ea114
1 #!/bin/sh
4 usage () {
5 echo >&2 "usage: $0 [--heads] [--tags] <repository> <refs>..."
6 exit 1;
9 while case "$#" in 0) break;; esac
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 ;;
21 break ;;
22 esac
23 done
25 case "$#" in 0) usage ;; esac
27 case ",$heads,$tags," in
28 ,,,) heads=heads tags=tags other=other ;;
29 esac
31 . git-parse-remote
32 peek_repo="$(get_remote_url "$@")"
33 shift
35 tmp=.ls-remote-$$
36 trap "rm -fr $tmp-*" 0 1 2 3 15
37 tmpdir=$tmp-d
39 case "$peek_repo" in
40 http://* | https://* )
41 if [ -n "$GIT_SSL_NO_VERIFY" ]; then
42 curl_extra_args="-k"
44 curl -nsf $curl_extra_args "$peek_repo/info/refs" ||
45 echo "failed slurping"
48 rsync://* )
49 mkdir $tmpdir
50 rsync -rq "$peek_repo/refs" $tmpdir || {
51 echo "failed slurping"
52 exit
54 (cd $tmpdir && find refs -type f) |
55 while read path
57 cat "$tmpdir/$path" | tr -d '\012'
58 echo " $path"
59 done &&
60 rm -fr $tmpdir
63 * )
64 git-peek-remote "$peek_repo" ||
65 echo "failed slurping"
67 esac |
68 sort -t ' ' -k 2 |
69 while read sha1 path
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 ;;
81 group=other ;;
82 esac
83 case ",$heads,$tags,$other," in
84 *,$group,*)
87 continue;;
88 esac
89 case "$#" in
91 match=yes ;;
93 match=no
94 for pat
96 case "/$path" in
97 */$pat )
98 match=yes
99 break ;;
100 esac
101 done
102 esac
103 case "$match" in
105 continue ;;
106 esac
107 echo "$sha1 $path"
108 done