scripts: more "export VAR=VALUE" fixes
[git/git-svn.git] / git-remote-testgit.sh
blobcbf470f64f0b93c520ce55d1b93c866b669bfbaa
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 mkdir -p "$dir"
21 if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
22 then
23 gitmarks="$dir/git.marks"
24 testgitmarks="$dir/testgit.marks"
25 test -e "$gitmarks" || >"$gitmarks"
26 test -e "$testgitmarks" || >"$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 test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
42 test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
43 echo
45 list)
46 git for-each-ref --format='? %(refname)' 'refs/heads/'
47 head=$(git symbolic-ref HEAD)
48 echo "@$head HEAD"
49 echo
51 import*)
52 # read all import lines
53 while true
55 ref="${line#* }"
56 refs="$refs $ref"
57 read line
58 test "${line%% *}" != "import" && break
59 done
61 if test -n "$gitmarks"
62 then
63 echo "feature import-marks=$gitmarks"
64 echo "feature export-marks=$gitmarks"
67 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
68 then
69 echo "feature done"
70 exit 1
73 echo "feature done"
74 git fast-export \
75 ${testgitmarks:+"--import-marks=$testgitmarks"} \
76 ${testgitmarks:+"--export-marks=$testgitmarks"} \
77 $refs |
78 sed -e "s#refs/heads/#${prefix}/heads/#g"
79 echo "done"
81 export)
82 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
83 then
84 # consume input so fast-export doesn't get SIGPIPE;
85 # git would also notice that case, but we want
86 # to make sure we are exercising the later
87 # error checks
88 while read line; do
89 test "done" = "$line" && break
90 done
91 exit 1
94 before=$(git for-each-ref --format=' %(refname) %(objectname) ')
96 git fast-import \
97 ${testgitmarks:+"--import-marks=$testgitmarks"} \
98 ${testgitmarks:+"--export-marks=$testgitmarks"} \
99 --quiet
101 # figure out which refs were updated
102 git for-each-ref --format='%(refname) %(objectname)' |
103 while read ref a
105 case "$before" in
106 *" $ref $a "*)
107 continue ;; # unchanged
108 esac
109 if test -z "$GIT_REMOTE_TESTGIT_PUSH_ERROR"
110 then
111 echo "ok $ref"
112 else
113 echo "error $ref $GIT_REMOTE_TESTGIT_PUSH_ERROR"
115 done
117 echo
120 exit
122 esac
123 done