t/am: use test_path_is_missing() where appropriate
[git/gitweb.git] / git-remote-testgit
blobe7ed3a33e6d7180e65f06a882342fa2d7efb4d03
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 test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
42 echo
44 list)
45 git for-each-ref --format='? %(refname)' 'refs/heads/'
46 head=$(git symbolic-ref HEAD)
47 echo "@$head HEAD"
48 echo
50 import*)
51 # read all import lines
52 while true
54 ref="${line#* }"
55 refs="$refs $ref"
56 read line
57 test "${line%% *}" != "import" && break
58 done
60 if test -n "$gitmarks"
61 then
62 echo "feature import-marks=$gitmarks"
63 echo "feature export-marks=$gitmarks"
65 echo "feature done"
66 git fast-export "${testgitmarks_args[@]}" $refs |
67 sed -e "s#refs/heads/#${prefix}/heads/#g"
68 echo "done"
70 export)
71 before=$(git for-each-ref --format='%(refname) %(objectname)')
73 git fast-import "${testgitmarks_args[@]}" --quiet
75 after=$(git for-each-ref --format='%(refname) %(objectname)')
77 # figure out which refs were updated
78 join -e 0 -o '0 1.2 2.2' -a 2 <(echo "$before") <(echo "$after") |
79 while read ref a b
81 test $a == $b && continue
82 echo "ok $ref"
83 done
85 echo
87 '')
88 exit
90 esac
91 done