git-remote-testgiton commit remote-testgit: cleanup tests (3808b85)
   1#!/usr/bin/env bash
   2# Copyright (c) 2012 Felipe Contreras
   3
   4alias=$1
   5url=$2
   6
   7dir="$GIT_DIR/testgit/$alias"
   8prefix="refs/testgit/$alias"
   9refspec="refs/heads/*:${prefix}/heads/*"
  10
  11gitmarks="$dir/git.marks"
  12testgitmarks="$dir/testgit.marks"
  13
  14export GIT_DIR="$url/.git"
  15
  16mkdir -p "$dir"
  17
  18test -e "$gitmarks" || > "$gitmarks"
  19test -e "$testgitmarks" || > "$testgitmarks"
  20
  21while read line
  22do
  23        case $line in
  24        capabilities)
  25                echo 'import'
  26                echo 'export'
  27                echo "refspec $refspec"
  28                echo "*import-marks $gitmarks"
  29                echo "*export-marks $gitmarks"
  30                echo
  31                ;;
  32        list)
  33                git for-each-ref --format='? %(refname)' 'refs/heads/'
  34                head=$(git symbolic-ref HEAD)
  35                echo "@$head HEAD"
  36                echo
  37                ;;
  38        import*)
  39                # read all import lines
  40                while true
  41                do
  42                        ref="${line#* }"
  43                        refs="$refs $ref"
  44                        read line
  45                        test "${line%% *}" != "import" && break
  46                done
  47
  48                echo "feature import-marks=$gitmarks"
  49                echo "feature export-marks=$gitmarks"
  50                git fast-export --use-done-feature --{import,export}-marks="$testgitmarks" $refs |
  51                sed -e "s#refs/heads/#${prefix}/heads/#g"
  52                ;;
  53        export)
  54                git fast-import --{import,export}-marks="$testgitmarks" --quiet
  55                echo
  56                ;;
  57        '')
  58                exit
  59                ;;
  60        esac
  61done