Add new simplified git-remote-testgit

Exercising the python remote helper framework is for another tool and another test. This is about testing the remote-helper interface. It's way simpler, it exercises the same features of remote helpers, it's easy to read and understand, and it doesn't depend on python. For now let's just copy the old remote-helpers test script, although some of those tests don't make sense. In addition, this script would be able to test other features not currently being tested. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed Nov 28, 2012 at 23:11 UTC fc407f9821840041757975045c4a1ca01effa27a
3 files changed +204 -1
Documentation/git-remote-testgit.txt
+1 -1
@@ -19,7 +19,7 @@ testcase for the remote-helper functionality, and as an example to
19 show remote-helper authors one possible implementation.
20
21 The best way to learn more is to read the comments and source code in
22 -'git-remote-testgit.py'.
22 +'git-remote-testgit'.
23
24 SEE ALSO
25 --------
git-remote-testgit new
+64
@@ -0,0 +1,64 @@
1 +#!/usr/bin/env bash
2 +# Copyright (c) 2012 Felipe Contreras
3 +
4 +alias=$1
5 +url=$2
6 +
7 +# huh?
8 +url="${url#file://}"
9 +
10 +dir="$GIT_DIR/testgit/$alias"
11 +prefix="refs/testgit/$alias"
12 +refspec="refs/heads/*:${prefix}/heads/*"
13 +
14 +gitmarks="$dir/git.marks"
15 +testgitmarks="$dir/testgit.marks"
16 +
17 +export GIT_DIR="$url/.git"
18 +
19 +mkdir -p "$dir"
20 +
21 +test -e "$gitmarks" || > "$gitmarks"
22 +test -e "$testgitmarks" || > "$testgitmarks"
23 +
24 +while read line
25 +do
26 + case $line in
27 + capabilities)
28 + echo 'import'
29 + echo 'export'
30 + echo "refspec $refspec"
31 + echo "*import-marks $gitmarks"
32 + echo "*export-marks $gitmarks"
33 + echo
34 + ;;
35 + list)
36 + git for-each-ref --format='? %(refname)' 'refs/heads/'
37 + head=$(git symbolic-ref HEAD)
38 + echo "@$head HEAD"
39 + echo
40 + ;;
41 + import*)
42 + # read all import lines
43 + while true
44 + do
45 + ref="${line#* }"
46 + refs="$refs $ref"
47 + read line
48 + test "${line%% *}" != "import" && break
49 + done
50 +
51 + echo "feature import-marks=$gitmarks"
52 + echo "feature export-marks=$gitmarks"
53 + git fast-export --use-done-feature --{import,export}-marks="$testgitmarks" $refs |
54 + sed -e "s#refs/heads/#${prefix}/heads/#g"
55 + ;;
56 + export)
57 + git fast-import --{import,export}-marks="$testgitmarks" --quiet
58 + echo
59 + ;;
60 + '')
61 + exit
62 + ;;
63 + esac
64 +done
t/t5801-remote-helpers.sh new
+139
@@ -0,0 +1,139 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2010 Sverre Rabbelier
4 +#
5 +
6 +test_description='Test remote-helper import and export commands'
7 +
8 +. ./test-lib.sh
9 +
10 +if ! type "${BASH-bash}" >/dev/null 2>&1; then
11 + skip_all='skipping remote-testgit tests, bash not available'
12 + test_done
13 +fi
14 +
15 +compare_refs() {
16 + git --git-dir="$1/.git" rev-parse --verify $2 >expect &&
17 + git --git-dir="$3/.git" rev-parse --verify $4 >actual &&
18 + test_cmp expect actual
19 +}
20 +
21 +test_expect_success 'setup repository' '
22 + git init --bare server/.git &&
23 + git clone server public &&
24 + (cd public &&
25 + echo content >file &&
26 + git add file &&
27 + git commit -m one &&
28 + git push origin master)
29 +'
30 +
31 +test_expect_success 'cloning from local repo' '
32 + git clone "testgit::${PWD}/server" localclone &&
33 + test_cmp public/file localclone/file
34 +'
35 +
36 +test_expect_success 'cloning from remote repo' '
37 + git clone "testgit::file://${PWD}/server" clone &&
38 + test_cmp public/file clone/file
39 +'
40 +
41 +test_expect_success 'create new commit on remote' '
42 + (cd public &&
43 + echo content >>file &&
44 + git commit -a -m two &&
45 + git push)
46 +'
47 +
48 +test_expect_success 'pulling from local repo' '
49 + (cd localclone && git pull) &&
50 + test_cmp public/file localclone/file
51 +'
52 +
53 +test_expect_success 'pulling from remote remote' '
54 + (cd clone && git pull) &&
55 + test_cmp public/file clone/file
56 +'
57 +
58 +test_expect_success 'pushing to local repo' '
59 + (cd localclone &&
60 + echo content >>file &&
61 + git commit -a -m three &&
62 + git push) &&
63 + compare_refs localclone HEAD server HEAD
64 +'
65 +
66 +# Generally, skip this test. It demonstrates a now-fixed race in
67 +# git-remote-testgit, but is too slow to leave in for general use.
68 +: test_expect_success 'racily pushing to local repo' '
69 + test_when_finished "rm -rf server2 localclone2" &&
70 + cp -R server server2 &&
71 + git clone "testgit::${PWD}/server2" localclone2 &&
72 + (cd localclone2 &&
73 + echo content >>file &&
74 + git commit -a -m three &&
75 + GIT_REMOTE_TESTGIT_SLEEPY=2 git push) &&
76 + compare_refs localclone2 HEAD server2 HEAD
77 +'
78 +
79 +test_expect_success 'synch with changes from localclone' '
80 + (cd clone &&
81 + git pull)
82 +'
83 +
84 +test_expect_success 'pushing remote local repo' '
85 + (cd clone &&
86 + echo content >>file &&
87 + git commit -a -m four &&
88 + git push) &&
89 + compare_refs clone HEAD server HEAD
90 +'
91 +
92 +test_expect_success 'fetch new branch' '
93 + (cd public &&
94 + git checkout -b new &&
95 + echo content >>file &&
96 + git commit -a -m five &&
97 + git push origin new
98 + ) &&
99 + (cd localclone &&
100 + git fetch origin new
101 + ) &&
102 + compare_refs public HEAD localclone FETCH_HEAD
103 +'
104 +
105 +test_expect_success 'fetch multiple branches' '
106 + (cd localclone &&
107 + git fetch
108 + ) &&
109 + compare_refs server master localclone refs/remotes/origin/master &&
110 + compare_refs server new localclone refs/remotes/origin/new
111 +'
112 +
113 +test_expect_success 'push when remote has extra refs' '
114 + (cd clone &&
115 + echo content >>file &&
116 + git commit -a -m six &&
117 + git push
118 + ) &&
119 + compare_refs clone master server master
120 +'
121 +
122 +test_expect_success 'push new branch by name' '
123 + (cd clone &&
124 + git checkout -b new-name &&
125 + echo content >>file &&
126 + git commit -a -m seven &&
127 + git push origin new-name
128 + ) &&
129 + compare_refs clone HEAD server refs/heads/new-name
130 +'
131 +
132 +test_expect_failure 'push new branch with old:new refspec' '
133 + (cd clone &&
134 + git push origin new-name:new-refspec
135 + ) &&
136 + compare_refs clone HEAD server refs/heads/new-refspec
137 +'
138 +
139 +test_done