contrib / examples / git-ls-remote.shon commit log-tree: respect diffopt's configured output file stream (4d7b0ef)
   1#!/bin/sh
   2#
   3
   4usage () {
   5    echo >&2 "usage: $0 [--heads] [--tags] [-u|--upload-pack <upload-pack>]"
   6    echo >&2 "          <repository> <refs>..."
   7    exit 1;
   8}
   9
  10die () {
  11    echo >&2 "$*"
  12    exit 1
  13}
  14
  15exec=
  16while test $# != 0
  17do
  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="--upload-pack=$1"
  27        shift;;
  28  -u=*|--u=*|--up=*|--upl=*|--uplo=*|--uploa=*|--upload=*|\
  29  --upload-=*|--upload-p=*|--upload-pa=*|--upload-pac=*|--upload-pack=*)
  30        exec=--upload-pack=$(expr "z$1" : 'z-[^=]*=\(.*\)')
  31        shift;;
  32  --)
  33  shift; break ;;
  34  -*)
  35  usage ;;
  36  *)
  37  break ;;
  38  esac
  39done
  40
  41case "$#" in 0) usage ;; esac
  42
  43case ",$heads,$tags," in
  44,,,) heads=heads tags=tags other=other ;;
  45esac
  46
  47. git-parse-remote
  48peek_repo="$(get_remote_url "$@")"
  49shift
  50
  51tmp=.ls-remote-$$
  52trap "rm -fr $tmp-*" 0 1 2 3 15
  53tmpdir=$tmp-d
  54
  55case "$peek_repo" in
  56http://* | https://* | ftp://* )
  57        if [ -n "$GIT_SSL_NO_VERIFY" -o \
  58                "$(git config --bool http.sslVerify)" = false ]; then
  59                curl_extra_args="-k"
  60        fi
  61        if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
  62                "$(git config --bool http.noEPSV)" = true ]; then
  63                curl_extra_args="${curl_extra_args} --disable-epsv"
  64        fi
  65        curl -nsf $curl_extra_args --header "Pragma: no-cache" "$peek_repo/info/refs" ||
  66                echo "failed    slurping"
  67        ;;
  68
  69rsync://* )
  70        mkdir $tmpdir &&
  71        rsync -rlq "$peek_repo/HEAD" $tmpdir &&
  72        rsync -rq "$peek_repo/refs" $tmpdir || {
  73                echo "failed    slurping"
  74                exit
  75        }
  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"
  83        (cd $tmpdir && find refs -type f) |
  84        while read path
  85        do
  86                tr -d '\012' <"$tmpdir/$path"
  87                echo "  $path"
  88        done &&
  89        rm -fr $tmpdir
  90        ;;
  91
  92* )
  93        if test -f "$peek_repo" ; then
  94                git bundle list-heads "$peek_repo" ||
  95                echo "failed    slurping"
  96        else
  97                git-peek-remote $exec "$peek_repo" ||
  98                echo "failed    slurping"
  99        fi
 100        ;;
 101esac |
 102sort -t '       ' -k 2 |
 103while read sha1 path
 104do
 105        case "$sha1" in
 106        failed)
 107                exit 1 ;;
 108        esac
 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
 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
 136        esac
 137        case "$match" in
 138        no)
 139                continue ;;
 140        esac
 141        echo "$sha1     $path"
 142done