]> git.ipfire.org Git - thirdparty/git.git/blame - git-ls-remote.sh
Do git reset --hard HEAD when using git rebase --skip
[thirdparty/git.git] / git-ls-remote.sh
CommitLineData
0fec0822
JH
1#!/bin/sh
2#
0fec0822
JH
3
4usage () {
96b086d6
MO
5 echo >&2 "usage: $0 [--heads] [--tags] [-u|--upload-pack <upload-pack>]"
6 echo >&2 " <repository> <refs>..."
0fec0822
JH
7 exit 1;
8}
9
1abacf3b
JH
10die () {
11 echo >&2 "$*"
12 exit 1
13}
14
96b086d6 15exec=
822f7c73 16while test $# != 0
0fec0822
JH
17do
18 case "$1" in
19 -h|--h|--he|--hea|--head|--heads)
20 heads=heads; shift ;;
0fec0822
JH
21 -t|--t|--ta|--tag|--tags)
22 tags=tags; shift ;;
96b086d6
MO
23 -u|--u|--up|--upl|--uploa|--upload|--upload-|--upload-p|--upload-pa|\
24 --upload-pac|--upload-pack)
25 shift
ae1dffcb
JH
26 exec="--upload-pack=$1"
27 shift;;
28 -u=*|--u=*|--up=*|--upl=*|--uplo=*|--uploa=*|--upload=*|\
29 --upload-=*|--upload-p=*|--upload-pa=*|--upload-pac=*|--upload-pack=*)
4a91a1f3 30 exec=--upload-pack=$(expr "z$1" : 'z-[^=]*=\(.*\)')
96b086d6 31 shift;;
0fec0822
JH
32 --)
33 shift; break ;;
34 -*)
35 usage ;;
36 *)
37 break ;;
38 esac
39done
40
972b6fe7 41case "$#" in 0) usage ;; esac
0fec0822
JH
42
43case ",$heads,$tags," in
44,,,) heads=heads tags=tags other=other ;;
45esac
46
215a7ad1 47. git-parse-remote
e0bfc81e 48peek_repo="$(get_remote_url "$@")"
972b6fe7 49shift
0fec0822
JH
50
51tmp=.ls-remote-$$
52trap "rm -fr $tmp-*" 0 1 2 3 15
53tmpdir=$tmp-d
54
55case "$peek_repo" in
38529e28 56http://* | https://* | ftp://* )
1c1f79a1
AB
57 if [ -n "$GIT_SSL_NO_VERIFY" -o \
58 "`git config --bool http.sslVerify`" = false ]; then
59 curl_extra_args="-k"
60 fi
3ea099d4 61 if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
5be60078 62 "`git config --bool http.noEPSV`" = true ]; then
3ea099d4
SK
63 curl_extra_args="${curl_extra_args} --disable-epsv"
64 fi
7fa8ddd6 65 curl -nsf $curl_extra_args --header "Pragma: no-cache" "$peek_repo/info/refs" ||
a5cd85e0 66 echo "failed slurping"
0fec0822
JH
67 ;;
68
69rsync://* )
e686eba4
JH
70 mkdir $tmpdir &&
71 rsync -rlq "$peek_repo/HEAD" $tmpdir &&
a5cd85e0
JH
72 rsync -rq "$peek_repo/refs" $tmpdir || {
73 echo "failed slurping"
74 exit
75 }
e686eba4
JH
76 head=$(cat "$tmpdir/HEAD") &&
77 case "$head" in
78 ref:' '*)
79 head=$(expr "z$head" : 'zref: \(.*\)') &&
80 head=$(cat "$tmpdir/$head") || exit
81 esac &&
82 echo "$head HEAD"
0fec0822
JH
83 (cd $tmpdir && find refs -type f) |
84 while read path
85 do
9d6f220c 86 tr -d '\012' <"$tmpdir/$path"
0fec0822
JH
87 echo " $path"
88 done &&
89 rm -fr $tmpdir
90 ;;
91
92* )
2e0afafe
JS
93 if test -f "$peek_repo" ; then
94 git bundle list-heads "$peek_repo" ||
a5cd85e0 95 echo "failed slurping"
2e0afafe
JS
96 else
97 git-peek-remote $exec "$peek_repo" ||
98 echo "failed slurping"
99 fi
0fec0822
JH
100 ;;
101esac |
972b6fe7 102sort -t ' ' -k 2 |
0fec0822
JH
103while read sha1 path
104do
a5cd85e0
JH
105 case "$sha1" in
106 failed)
b3d98993 107 exit 1 ;;
a5cd85e0 108 esac
0fec0822
JH
109 case "$path" in
110 refs/heads/*)
111 group=heads ;;
112 refs/tags/*)
113 group=tags ;;
114 *)
115 group=other ;;
116 esac
117 case ",$heads,$tags,$other," in
118 *,$group,*)
119 ;;
120 *)
121 continue;;
122 esac
972b6fe7
JH
123 case "$#" in
124 0)
125 match=yes ;;
126 *)
127 match=no
128 for pat
129 do
130 case "/$path" in
131 */$pat )
132 match=yes
133 break ;;
134 esac
135 done
0fec0822 136 esac
972b6fe7
JH
137 case "$match" in
138 no)
139 continue ;;
140 esac
141 echo "$sha1 $path"
0fec0822 142done