git-ls-remote.shon commit documentation: git-tag (56b5e94)
   1#!/bin/sh
   2#
   3
   4usage () {
   5    echo >&2 "usage: $0 [--heads] [--tags] <repository> <refs>..."
   6    exit 1;
   7}
   8
   9die () {
  10    echo >&2 "$*"
  11    exit 1
  12}
  13
  14while case "$#" in 0) break;; esac
  15do
  16  case "$1" in
  17  -h|--h|--he|--hea|--head|--heads)
  18  heads=heads; shift ;;
  19  -t|--t|--ta|--tag|--tags)
  20  tags=tags; shift ;;
  21  --)
  22  shift; break ;;
  23  -*)
  24  usage ;;
  25  *)
  26  break ;;
  27  esac
  28done
  29
  30case "$#" in 0) usage ;; esac
  31
  32case ",$heads,$tags," in
  33,,,) heads=heads tags=tags other=other ;;
  34esac
  35
  36. git-parse-remote
  37peek_repo="$(get_remote_url "$@")"
  38shift
  39
  40tmp=.ls-remote-$$
  41trap "rm -fr $tmp-*" 0 1 2 3 15
  42tmpdir=$tmp-d
  43
  44case "$peek_repo" in
  45http://* | https://* )
  46        if [ -n "$GIT_SSL_NO_VERIFY" ]; then
  47            curl_extra_args="-k"
  48        fi
  49        curl -nsf $curl_extra_args "$peek_repo/info/refs" ||
  50                echo "failed    slurping"
  51        ;;
  52
  53rsync://* )
  54        mkdir $tmpdir
  55        rsync -rq "$peek_repo/refs" $tmpdir || {
  56                echo "failed    slurping"
  57                exit
  58        }
  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* )
  69        git-peek-remote "$peek_repo" ||
  70                echo "failed    slurping"
  71        ;;
  72esac |
  73sort -t '       ' -k 2 |
  74while read sha1 path
  75do
  76        case "$sha1" in
  77        failed)
  78                die "Failed to find remote refs"
  79        esac
  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
  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
 107        esac
 108        case "$match" in
 109        no)
 110                continue ;;
 111        esac
 112        echo "$sha1     $path"
 113done