]> git.ipfire.org Git - thirdparty/git.git/blame - git-remote-testgit.sh
git-remote-mediawiki: add test and check Makefile targets
[thirdparty/git.git] / git-remote-testgit.sh
CommitLineData
85d501ce 1#!/bin/sh
fc407f98
FC
2# Copyright (c) 2012 Felipe Contreras
3
4alias=$1
5url=$2
6
fc407f98
FC
7dir="$GIT_DIR/testgit/$alias"
8prefix="refs/testgit/$alias"
fc407f98 9
ee10fbf9
FC
10default_refspec="refs/heads/*:${prefix}/heads/*"
11
12refspec="${GIT_REMOTE_TESTGIT_REFSPEC-$default_refspec}"
13
14test -z "$refspec" && prefix="refs"
fc407f98
FC
15
16export GIT_DIR="$url/.git"
17
18mkdir -p "$dir"
19
ee10fbf9
FC
20if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
21then
22 gitmarks="$dir/git.marks"
23 testgitmarks="$dir/testgit.marks"
24 test -e "$gitmarks" || >"$gitmarks"
25 test -e "$testgitmarks" || >"$testgitmarks"
ee10fbf9 26fi
fc407f98
FC
27
28while read line
29do
30 case $line in
31 capabilities)
32 echo 'import'
33 echo 'export'
ee10fbf9
FC
34 test -n "$refspec" && echo "refspec $refspec"
35 if test -n "$gitmarks"
36 then
37 echo "*import-marks $gitmarks"
38 echo "*export-marks $gitmarks"
39 fi
0d957a4d 40 test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
fc407f98
FC
41 echo
42 ;;
43 list)
44 git for-each-ref --format='? %(refname)' 'refs/heads/'
45 head=$(git symbolic-ref HEAD)
46 echo "@$head HEAD"
47 echo
48 ;;
49 import*)
50 # read all import lines
51 while true
52 do
53 ref="${line#* }"
54 refs="$refs $ref"
55 read line
56 test "${line%% *}" != "import" && break
57 done
58
ee10fbf9
FC
59 if test -n "$gitmarks"
60 then
61 echo "feature import-marks=$gitmarks"
62 echo "feature export-marks=$gitmarks"
63 fi
81d340d4
FC
64
65 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
66 then
67 echo "feature done"
68 exit 1
69 fi
70
1d3f9a30 71 echo "feature done"
85d501ce
JS
72 git fast-export \
73 ${testgitmarks:+"--import-marks=$testgitmarks"} \
74 ${testgitmarks:+"--export-marks=$testgitmarks"} \
75 $refs |
fc407f98 76 sed -e "s#refs/heads/#${prefix}/heads/#g"
1d3f9a30 77 echo "done"
fc407f98
FC
78 ;;
79 export)
81d340d4
FC
80 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
81 then
82 # consume input so fast-export doesn't get SIGPIPE;
83 # git would also notice that case, but we want
84 # to make sure we are exercising the later
85 # error checks
86 while read line; do
87 test "done" = "$line" && break
88 done
89 exit 1
90 fi
91
752db425 92 before=$(git for-each-ref --format=' %(refname) %(objectname) ')
93b5cf9c 93
85d501ce
JS
94 git fast-import \
95 ${testgitmarks:+"--import-marks=$testgitmarks"} \
96 ${testgitmarks:+"--export-marks=$testgitmarks"} \
97 --quiet
93b5cf9c
FC
98
99 # figure out which refs were updated
752db425
JS
100 git for-each-ref --format='%(refname) %(objectname)' |
101 while read ref a
93b5cf9c 102 do
752db425
JS
103 case "$before" in
104 *" $ref $a "*)
105 continue ;; # unchanged
106 esac
126aac5c
FC
107 if test -z "$GIT_REMOTE_TESTGIT_PUSH_ERROR"
108 then
109 echo "ok $ref"
110 else
111 echo "error $ref $GIT_REMOTE_TESTGIT_PUSH_ERROR"
112 fi
93b5cf9c
FC
113 done
114
fc407f98
FC
115 echo
116 ;;
117 '')
118 exit
119 ;;
120 esac
121done