Test commit
[cogito/jonas.git] / t / t9112-fetch-rsync.sh
blob714d95588f0f2b009a4548f73b2b8cf0e12427a0
1 #!/usr/bin/env bash
3 # Copyright (c) 2005 Petr Baudis
5 test_description="Tests cg-fetch over rsync
7 cg-fetch over rsync - if it works at all, and if it catches missing objects."
9 . ./test-lib.sh
11 # Trick to be able to use the rsync:// URLs locally. That's not something
12 # we want the regular user to do, but it's handy for testing, so our tool
13 # will just strip 'rsync://local/' from the URL start, leaving the rest
14 # as-is.
15 export RSYNC="$(pwd)/localrsync"
16 cat >localrsync <<EOF
17 #!/usr/bin/env bash
18 args=()
19 for arg in "\$@"; do
20 args[\${#args[@]}]="\$(echo "\$arg" | sed 's#rsync://local/#$(pwd | sed 's/#/\\#/g')/#')"
21 done
22 rsync "\${args[@]}"
23 EOF
24 chmod a+x localrsync
26 verify_repo2() {
27 test_expect_success 'verifying repo2' \
28 "(cmp repo2/.git/refs/heads/origin repo2/.git/refs/heads/master &&
29 cd repo2 && git-fsck-objects)"
32 mkdir repo1
33 echo stuff >repo1/file
34 test_expect_success 'initialize repo1' \
35 "(cd repo1 && cg-init -I && cg-add file && cg-commit -C -m\"Initial commit\")"
36 test_expect_success 'clone repo2' \
37 "(cg-clone rsync://local/repo1/.git repo2 &&
38 cmp repo2/.git/refs/heads/origin repo1/.git/refs/heads/master)"
39 verify_repo2
41 echo more stuff >>repo1/file
42 test_expect_success 'local commit in repo1' \
43 "(cd repo1 && git-update-index file && cg-commit -m\"Second commit\")"
44 test_expect_success 'updating repo2' \
45 "(cd repo2 && cg-update &&
46 cmp .git/refs/heads/origin ../repo1/.git/refs/heads/master)"
47 verify_repo2
49 echo more more stuff >>repo1/file
50 test_expect_success 'local commit in repo1' \
51 "(cd repo1 && git-update-index file && cg-commit -m\"Third commit\")"
52 test_expect_success 'rewriting HEAD of repo1 to symbolic' \
53 '(rm repo1/.git/HEAD && echo "ref: refs/heads/master" >repo1/.git/HEAD)'
54 test_expect_success 'updating repo2' \
55 "(cd repo2 && cg-update &&
56 cmp .git/refs/heads/origin ../repo1/.git/refs/heads/master)"
57 verify_repo2
59 echo even more stuff >>repo1/file
60 test_expect_success 'local commit in repo1' \
61 "(cd repo1 && git-update-index file && cg-commit -m\"Fourth commit\")"
62 obj="$(cd repo1 && cg-admin-ls file | cut -f 1 | cut -d ' ' -f 3)"
63 test_expect_success 'damaging repo1' \
64 "(cd repo1 && rm -f .git/objects/${obj:0:2}/${obj:2})"
65 test_expect_failure 'updating repo2' \
66 "(cd repo2 && cg-fetch)" # to prevent merge failing too late
67 verify_repo2
69 test_done