remote-testgit: exercise more features
[git/mingw.git] / git-remote-testgit
blobefda74bee33dbf346de5af79a2bcc45003f6fd5b
1 #!/usr/bin/env bash
2 # Copyright (c) 2012 Felipe Contreras
4 alias=$1
5 url=$2
7 dir="$GIT_DIR/testgit/$alias"
8 prefix="refs/testgit/$alias"
10 default_refspec="refs/heads/*:${prefix}/heads/*"
12 refspec="${GIT_REMOTE_TESTGIT_REFSPEC-$default_refspec}"
14 test -z "$refspec" && prefix="refs"
16 export GIT_DIR="$url/.git"
18 mkdir -p "$dir"
20 if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
21 then
22 gitmarks="$dir/git.marks"
23 testgitmarks="$dir/testgit.marks"
24 test -e "$gitmarks" || >"$gitmarks"
25 test -e "$testgitmarks" || >"$testgitmarks"
26 testgitmarks_args=( "--"{import,export}"-marks=$testgitmarks" )
29 while read line
31 case $line in
32 capabilities)
33 echo 'import'
34 echo 'export'
35 test -n "$refspec" && echo "refspec $refspec"
36 if test -n "$gitmarks"
37 then
38 echo "*import-marks $gitmarks"
39 echo "*export-marks $gitmarks"
41 echo
43 list)
44 git for-each-ref --format='? %(refname)' 'refs/heads/'
45 head=$(git symbolic-ref HEAD)
46 echo "@$head HEAD"
47 echo
49 import*)
50 # read all import lines
51 while true
53 ref="${line#* }"
54 refs="$refs $ref"
55 read line
56 test "${line%% *}" != "import" && break
57 done
59 if test -n "$gitmarks"
60 then
61 echo "feature import-marks=$gitmarks"
62 echo "feature export-marks=$gitmarks"
64 git fast-export --use-done-feature "${testgitmarks_args[@]}" $refs |
65 sed -e "s#refs/heads/#${prefix}/heads/#g"
67 export)
68 git fast-import "${testgitmarks_args[@]}" --quiet
69 echo
71 '')
72 exit
74 esac
75 done