Code

Set permissions of each new file before "cvs add"ing it.
[git.git] / git-ls-remote.sh
1 #!/bin/sh
2 #
4 usage () {
5     echo >&2 "usage: $0 [--heads] [--tags] [-u|--upload-pack <upload-pack>]"
6     echo >&2 "          <repository> <refs>..."
7     exit 1;
8 }
10 die () {
11     echo >&2 "$*"
12     exit 1
13 }
15 exec=
16 while case "$#" in 0) break;; esac
17 do
18   case "$1" in
19   -h|--h|--he|--hea|--head|--heads)
20   heads=heads; shift ;;
21   -t|--t|--ta|--tag|--tags)
22   tags=tags; shift ;;
23   -u|--u|--up|--upl|--uploa|--upload|--upload-|--upload-p|--upload-pa|\
24   --upload-pac|--upload-pack)
25         shift
26         exec="--exec=$1"
27         shift;;
28   --)
29   shift; break ;;
30   -*)
31   usage ;;
32   *)
33   break ;;
34   esac
35 done
37 case "$#" in 0) usage ;; esac
39 case ",$heads,$tags," in
40 ,,,) heads=heads tags=tags other=other ;;
41 esac
43 . git-parse-remote
44 peek_repo="$(get_remote_url "$@")"
45 shift
47 tmp=.ls-remote-$$
48 trap "rm -fr $tmp-*" 0 1 2 3 15
49 tmpdir=$tmp-d
51 case "$peek_repo" in
52 http://* | https://* | ftp://* )
53         if [ -n "$GIT_SSL_NO_VERIFY" ]; then
54             curl_extra_args="-k"
55         fi
56         if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
57                 "`git-repo-config --bool http.noEPSV`" = true ]; then
58                 curl_extra_args="${curl_extra_args} --disable-epsv"
59         fi
60         curl -nsf $curl_extra_args --header "Pragma: no-cache" "$peek_repo/info/refs" ||
61                 echo "failed    slurping"
62         ;;
64 rsync://* )
65         mkdir $tmpdir &&
66         rsync -rlq "$peek_repo/HEAD" $tmpdir &&
67         rsync -rq "$peek_repo/refs" $tmpdir || {
68                 echo "failed    slurping"
69                 exit
70         }
71         head=$(cat "$tmpdir/HEAD") &&
72         case "$head" in
73         ref:' '*)
74                 head=$(expr "z$head" : 'zref: \(.*\)') &&
75                 head=$(cat "$tmpdir/$head") || exit
76         esac &&
77         echo "$head     HEAD"
78         (cd $tmpdir && find refs -type f) |
79         while read path
80         do
81                 cat "$tmpdir/$path" | tr -d '\012'
82                 echo "  $path"
83         done &&
84         rm -fr $tmpdir
85         ;;
87 * )
88         git-peek-remote $exec "$peek_repo" ||
89                 echo "failed    slurping"
90         ;;
91 esac |
92 sort -t '       ' -k 2 |
93 while read sha1 path
94 do
95         case "$sha1" in
96         failed)
97                 die "Failed to find remote refs"
98         esac
99         case "$path" in
100         refs/heads/*)
101                 group=heads ;;
102         refs/tags/*)
103                 group=tags ;;
104         *)
105                 group=other ;;
106         esac
107         case ",$heads,$tags,$other," in
108         *,$group,*)
109                 ;;
110         *)
111                 continue;;
112         esac
113         case "$#" in
114         0)
115                 match=yes ;;
116         *)
117                 match=no
118                 for pat
119                 do
120                         case "/$path" in
121                         */$pat )
122                                 match=yes
123                                 break ;;
124                         esac
125                 done
126         esac
127         case "$match" in
128         no)
129                 continue ;;
130         esac
131         echo "$sha1     $path"
132 done