git p4: Use git diff-tree instead of format-patch
[git.git] / git-remote-testgit.sh
blob2109070d00411dbd9f1ba70e55587091d50a8a08
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 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"
28 while read line
30 case $line in
31 capabilities)
32 echo 'import'
33 echo 'export'
34 test -n "$refspec" && echo "refspec $refspec"
35 if test -n "$gitmarks"
36 then
37 echo "*import-marks $gitmarks"
38 echo "*export-marks $gitmarks"
40 test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
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"
65 if test -n "$GIT_REMOTE_TESTGIT_FAILURE"
66 then
67 echo "feature done"
68 exit 1
71 echo "feature done"
72 git fast-export \
73 ${testgitmarks:+"--import-marks=$testgitmarks"} \
74 ${testgitmarks:+"--export-marks=$testgitmarks"} \
75 $refs |
76 sed -e "s#refs/heads/#${prefix}/heads/#g"
77 echo "done"
79 export)
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
92 before=$(git for-each-ref --format=' %(refname) %(objectname) ')
94 git fast-import \
95 ${testgitmarks:+"--import-marks=$testgitmarks"} \
96 ${testgitmarks:+"--export-marks=$testgitmarks"} \
97 --quiet
99 # figure out which refs were updated
100 git for-each-ref --format='%(refname) %(objectname)' |
101 while read ref a
103 case "$before" in
104 *" $ref $a "*)
105 continue ;; # unchanged
106 esac
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"
113 done
115 echo
118 exit
120 esac
121 done