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