Merge branch 'jk/fast-import-fixes'
[alt-git.git] / git-remote-testgit.sh
bloba9c75a2360fec7a9ce5f22877a471f70bc405ff1
1 #!/bin/sh
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 GIT_DIR="$url/.git"
17 export GIT_DIR
19 force=
21 mkdir -p "$dir"
23 if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
24 then
25 gitmarks="$dir/git.marks"
26 testgitmarks="$dir/testgit.marks"
27 test -e "$gitmarks" || >"$gitmarks"
28 test -e "$testgitmarks" || >"$testgitmarks"
31 while read line
33 case $line in
34 capabilities)
35 echo 'import'
36 echo 'export'
37 test -n "$refspec" && echo "refspec $refspec"
38 if test -n "$gitmarks"
39 then
40 echo "*import-marks $gitmarks"
41 echo "*export-marks $gitmarks"
43 test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
44 test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
45 echo 'option'
46 echo
48 list)
49 git for-each-ref --format='? %(refname)' 'refs/heads/'
50 head=$(git symbolic-ref HEAD)
51 echo "@$head HEAD"
52 echo
54 import*)
55 # read all import lines
56 while true
58 ref="${line#* }"
59 refs="$refs $ref"
60 read line
61 test "${line%% *}" != "import" && break
62 done
64 if test -n "$gitmarks"
65 then
66 echo "feature import-marks=$gitmarks"
67 echo "feature export-marks=$gitmarks"
70 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
71 then
72 echo "feature done"
73 exit 1
76 echo "feature done"
77 git fast-export \
78 ${testgitmarks:+"--import-marks=$testgitmarks"} \
79 ${testgitmarks:+"--export-marks=$testgitmarks"} \
80 $refs |
81 sed -e "s#refs/heads/#${prefix}/heads/#g"
82 echo "done"
84 export)
85 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
86 then
87 # consume input so fast-export doesn't get SIGPIPE;
88 # git would also notice that case, but we want
89 # to make sure we are exercising the later
90 # error checks
91 while read line; do
92 test "done" = "$line" && break
93 done
94 exit 1
97 before=$(git for-each-ref --format=' %(refname) %(objectname) ')
99 git fast-import \
100 ${force:+--force} \
101 ${testgitmarks:+"--import-marks=$testgitmarks"} \
102 ${testgitmarks:+"--export-marks=$testgitmarks"} \
103 --quiet
105 # figure out which refs were updated
106 git for-each-ref --format='%(refname) %(objectname)' |
107 while read ref a
109 case "$before" in
110 *" $ref $a "*)
111 continue ;; # unchanged
112 esac
113 if test -z "$GIT_REMOTE_TESTGIT_PUSH_ERROR"
114 then
115 echo "ok $ref"
116 else
117 echo "error $ref $GIT_REMOTE_TESTGIT_PUSH_ERROR"
119 done
121 echo
123 option\ *)
124 read cmd opt val <<-EOF
125 $line
127 case $opt in
128 force)
129 test $val = "true" && force="true" || force=
130 echo "ok"
133 echo "unsupported"
135 esac
138 exit
140 esac
141 done