gistore 1.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +30 -0
  3. data/COPYING +340 -0
  4. data/README.md +98 -0
  5. data/exe/gistore +15 -0
  6. data/lib/gistore.rb +20 -0
  7. data/lib/gistore/cmd/add.rb +15 -0
  8. data/lib/gistore/cmd/checkout.rb +49 -0
  9. data/lib/gistore/cmd/commit.rb +171 -0
  10. data/lib/gistore/cmd/config.rb +23 -0
  11. data/lib/gistore/cmd/export-to-backups.rb +79 -0
  12. data/lib/gistore/cmd/gc.rb +15 -0
  13. data/lib/gistore/cmd/git-version.rb +14 -0
  14. data/lib/gistore/cmd/init.rb +36 -0
  15. data/lib/gistore/cmd/restore-from-backups.rb +91 -0
  16. data/lib/gistore/cmd/rm.rb +15 -0
  17. data/lib/gistore/cmd/safe-commands.rb +53 -0
  18. data/lib/gistore/cmd/status.rb +40 -0
  19. data/lib/gistore/cmd/task.rb +85 -0
  20. data/lib/gistore/cmd/version.rb +27 -0
  21. data/lib/gistore/config.rb +13 -0
  22. data/lib/gistore/config/gistore.yml +1 -0
  23. data/lib/gistore/error.rb +6 -0
  24. data/lib/gistore/repo.rb +683 -0
  25. data/lib/gistore/runner.rb +43 -0
  26. data/lib/gistore/templates/description +1 -0
  27. data/lib/gistore/templates/hooks/applypatch-msg.sample +15 -0
  28. data/lib/gistore/templates/hooks/commit-msg.sample +24 -0
  29. data/lib/gistore/templates/hooks/post-update.sample +8 -0
  30. data/lib/gistore/templates/hooks/pre-applypatch.sample +14 -0
  31. data/lib/gistore/templates/hooks/pre-commit.sample +49 -0
  32. data/lib/gistore/templates/hooks/pre-push.sample +54 -0
  33. data/lib/gistore/templates/hooks/pre-rebase.sample +169 -0
  34. data/lib/gistore/templates/hooks/prepare-commit-msg.sample +36 -0
  35. data/lib/gistore/templates/hooks/update.sample +128 -0
  36. data/lib/gistore/templates/info/exclude +6 -0
  37. data/lib/gistore/utils.rb +382 -0
  38. data/lib/gistore/version.rb +4 -0
  39. data/t/Makefile +80 -0
  40. data/t/README +745 -0
  41. data/t/aggregate-results.sh +46 -0
  42. data/t/lib-worktree.sh +76 -0
  43. data/t/t0000-init.sh +75 -0
  44. data/t/t0010-config.sh +75 -0
  45. data/t/t0020-version.sh +32 -0
  46. data/t/t1000-add-remove.sh +89 -0
  47. data/t/t1010-status.sh +87 -0
  48. data/t/t1020-commit.sh +134 -0
  49. data/t/t1030-commit-and-rotate.sh +266 -0
  50. data/t/t2000-task-and-commit-all.sh +132 -0
  51. data/t/t3000-checkout.sh +115 -0
  52. data/t/t3010-export-and-restore.sh +141 -0
  53. data/t/test-binary-1.png +0 -0
  54. data/t/test-binary-2.png +0 -0
  55. data/t/test-lib-functions.sh +722 -0
  56. data/t/test-lib.sh +684 -0
  57. metadata +161 -0
@@ -0,0 +1,46 @@
1
+ #!/bin/sh
2
+
3
+ failed_tests=
4
+ fixed=0
5
+ success=0
6
+ failed=0
7
+ broken=0
8
+ total=0
9
+
10
+ while read file
11
+ do
12
+ while read type value
13
+ do
14
+ case $type in
15
+ '')
16
+ continue ;;
17
+ fixed)
18
+ fixed=$(($fixed + $value)) ;;
19
+ success)
20
+ success=$(($success + $value)) ;;
21
+ failed)
22
+ failed=$(($failed + $value))
23
+ if test $value != 0
24
+ then
25
+ testnum=$(expr "$file" : 'test-results/\(t[0-9]*\)-')
26
+ failed_tests="$failed_tests $testnum"
27
+ fi
28
+ ;;
29
+ broken)
30
+ broken=$(($broken + $value)) ;;
31
+ total)
32
+ total=$(($total + $value)) ;;
33
+ esac
34
+ done <"$file"
35
+ done
36
+
37
+ if test -n "$failed_tests"
38
+ then
39
+ printf "\nfailed test(s):$failed_tests\n\n"
40
+ fi
41
+
42
+ printf "%-8s%d\n" fixed $fixed
43
+ printf "%-8s%d\n" success $success
44
+ printf "%-8s%d\n" failed $failed
45
+ printf "%-8s%d\n" broken $broken
46
+ printf "%-8s%d\n" total $total
data/t/lib-worktree.sh ADDED
@@ -0,0 +1,76 @@
1
+ #!/bin/sh
2
+ #
3
+ # Copyright (c) 2013 Jiang Xin
4
+ #
5
+
6
+ prepare_work_tree()
7
+ {
8
+ mkdir -p root/src/lib/a
9
+ mkdir -p root/src/lib/b
10
+ mkdir -p root/src/lib/empty
11
+ mkdir -p root/src/images
12
+ mkdir -p root/doc/
13
+ echo "readme" > root/src/README.txt
14
+ echo "foo" > root/src/lib/a/foo.c
15
+ echo "bar" > root/src/lib/b/bar.o
16
+ echo "baz" > root/src/lib/b/baz.a
17
+ cp ${TEST_DIRECTORY}/test-binary-1.png root/src/images
18
+ cp ${TEST_DIRECTORY}/test-binary-2.png root/src/images
19
+ echo "copyright" > root/doc/COPYRIGHT
20
+ touch root/.hidden
21
+
22
+ mkdir -p root/mod1/
23
+ (
24
+ cd root/mod1
25
+ echo "readme" > README.txt
26
+ mkdir lib
27
+ cd lib
28
+ git init
29
+ mkdir src doc
30
+ echo "foo" > src/foo.c
31
+ echo "bar" > doc/bar.txt
32
+ git add -A .
33
+ git commit -m 'initial submodule mod1'
34
+ )
35
+ mkdir -p root/mod2/
36
+ (
37
+ cd root/mod2
38
+ git init
39
+ echo "readme" > README.txt
40
+ mkdir src doc
41
+ echo "foo" > src/foo.c
42
+ echo "bar" > doc/bar.txt
43
+ git add -A .
44
+ git commit -m 'initial submodule mod2'
45
+ mkdir lib
46
+ cd lib
47
+ git init
48
+ echo "hello" > hello.txt
49
+ git add -A .
50
+ git commit -m 'initial lib under mod2'
51
+ )
52
+ }
53
+
54
+ count_git_commits()
55
+ {
56
+ repo=$1
57
+ git --git-dir "$repo" rev-list HEAD 2>/dev/null | wc -l | sed -e 's/ //g'
58
+ }
59
+
60
+ count_git_objects()
61
+ {
62
+ repo=$1
63
+ num=0
64
+ git --git-dir "$repo" count-objects -v | sort | \
65
+ while read line; do
66
+ case $line in
67
+ count:*)
68
+ num=$((num + ${line#count:}))
69
+ ;;
70
+ in-pack:*)
71
+ num=$((num + ${line#in-pack:}))
72
+ echo $num
73
+ ;;
74
+ esac
75
+ done
76
+ }
data/t/t0000-init.sh ADDED
@@ -0,0 +1,75 @@
1
+ #!/bin/sh
2
+ #
3
+ # Copyright (c) 2013 Jiang Xin
4
+ #
5
+
6
+ test_description='Test gistore init'
7
+
8
+ TEST_NO_CREATE_REPO=NoThanks
9
+ . ./test-lib.sh
10
+
11
+ test_expect_success 'init with default normal plan' '
12
+ (
13
+ mkdir default &&
14
+ cd default &&
15
+ gistore init &&
16
+ test "$(gistore config plan)" = "normal"
17
+ )
18
+ '
19
+
20
+ cat >expect <<EOF
21
+ Repository format 1
22
+ EOF
23
+
24
+ test_expect_success 'check repo format version' '
25
+ gistore --version --repo default | tail -1 > actual &&
26
+ test_cmp expect actual
27
+ '
28
+
29
+ cat >expect <<EOF
30
+ Error: Non-empty directory 'default' is already exist.
31
+ EOF
32
+
33
+ test_expect_success 'can not init on a no-empty directory' '
34
+ test_must_fail gistore init --repo default &&
35
+ (gistore init --repo default 2>actual || true ) &&
36
+ test_cmp expect actual
37
+ '
38
+
39
+ test_expect_success 'check default gistore/git configurations' '
40
+ (
41
+ cd default &&
42
+ test "$(gistore config full_backup_number)" = "12" &&
43
+ test "$(gistore config increment_backup_number)" = "30" &&
44
+ test -z "$(gistore config gc.auto)" &&
45
+ test -z "$(gistore config core.compression)" &&
46
+ test -z "$(gistore config core.loosecompression)" &&
47
+ test "$(gistore config --bool core.quotepath)" = "false" &&
48
+ test "$(gistore config --bool core.autocrlf)" = "false" &&
49
+ test "$(gistore config --bool core.logAllRefUpdates)" = "true" &&
50
+ test "$(gistore config core.sharedRepository)" = "group" &&
51
+ test "$(gistore config core.bigFileThreshold)" = "2m"
52
+ )
53
+ '
54
+
55
+ test_expect_success 'init with --no-compress plan' '
56
+ (
57
+ gistore init --repo notz --plan no-compress &&
58
+ test "$(gistore config --repo notz plan)" = "no-compress" &&
59
+ test -z "$(gistore config --repo notz gc.auto)" &&
60
+ test "$(gistore config --repo notz core.compression)" = "0" &&
61
+ test "$(gistore config --repo notz core.loosecompression)" = "0"
62
+ )
63
+ '
64
+
65
+ test_expect_success 'init with --no-gc plan' '
66
+ (
67
+ gistore init --repo notgc --plan no-gc &&
68
+ test "$(gistore config --repo notgc plan)" = "no-gc" &&
69
+ test "$(gistore config --repo notgc gc.auto)" = "0" &&
70
+ test "$(gistore config --repo notgc core.compression)" = "0" &&
71
+ test "$(gistore config --repo notgc core.loosecompression)" = "0"
72
+ )
73
+ '
74
+
75
+ test_done
data/t/t0010-config.sh ADDED
@@ -0,0 +1,75 @@
1
+ #!/bin/sh
2
+ #
3
+ # Copyright (c) 2013 Jiang Xin
4
+ #
5
+
6
+ test_description='Test gistore config'
7
+
8
+ TEST_NO_CREATE_REPO=
9
+ . ./test-lib.sh
10
+
11
+ test_expect_success 'default is normal plan' '
12
+ test "$(gistore config plan)" = "normal"
13
+ '
14
+
15
+ test_expect_success 'check default gistore configurations' '
16
+ test "$(gistore config full_backup_number)" = "12" &&
17
+ test "$(gistore config increment_backup_number)" = "30" &&
18
+ test -z "$(gistore config gc.auto)" &&
19
+ test -z "$(gistore config core.compression)" &&
20
+ test -z "$(gistore config core.loosecompression)" &&
21
+ test "$(gistore config --bool core.quotepath)" = "false" &&
22
+ test "$(gistore config --bool core.autocrlf)" = "false" &&
23
+ test "$(gistore config --bool core.logAllRefUpdates)" = "true" &&
24
+ test "$(gistore config core.sharedRepository)" = "group" &&
25
+ test "$(gistore config core.bigFileThreshold)" = "2m"
26
+ '
27
+
28
+ test_expect_success 'change plan from normal to no-gc' '
29
+ test "$(gistore config plan)" = "normal" &&
30
+ gistore config --plan no-gc &&
31
+ test "$(gistore config plan)" = "no-gc" &&
32
+ test "$(gistore config gc.auto)" = "0" &&
33
+ test "$(gistore config core.compression)" = "0" &&
34
+ test "$(gistore config core.loosecompression)" = "0"
35
+ '
36
+
37
+ test_expect_success 'change plan from no-gc to no-compress' '
38
+ test "$(gistore config plan)" = "no-gc" &&
39
+ gistore config --plan no-compress &&
40
+ test "$(gistore config plan)" = "no-compress" &&
41
+ test -z "$(gistore config gc.auto)" &&
42
+ test "$(gistore config core.compression)" = "0" &&
43
+ test "$(gistore config core.loosecompression)" = "0"
44
+ '
45
+
46
+ test_expect_success 'change plan without --plan option' '
47
+ test "$(gistore config plan)" = "no-compress" &&
48
+ gistore config plan no-gc &&
49
+ gistore config plan normal &&
50
+ test "$(gistore config plan)" = "normal" &&
51
+ test -z "$(gistore config gc.auto)" &&
52
+ test -z "$(gistore config core.compression)" &&
53
+ test -z "$(gistore config core.loosecompression)"
54
+ '
55
+
56
+ test_expect_success 'read/write gistore configurations' '
57
+ test "$(gistore config full_backup_number)" = "12" &&
58
+ test "$(gistore config increment_backup_number)" = "30" &&
59
+ gistore config full_backup_number 5 &&
60
+ gistore config increment_backup_number 9 &&
61
+ test "$(gistore config full_backup_number)" = "5" &&
62
+ test "$(gistore config increment_backup_number)" = "9" &&
63
+ test_must_fail gistore config non_exist_config value &&
64
+ test_must_fail gistore config --unset non.exist.config
65
+ '
66
+
67
+ test_expect_success 'read/write git configurations' '
68
+ gistore config x.y.z foobar &&
69
+ test "$(gistore config x.y.z)" = "foobar" &&
70
+ test "$(git config x.y.z)" = "foobar" &&
71
+ git config x.y.z baz &&
72
+ test "$(gistore config x.y.z)" = "baz"
73
+ '
74
+
75
+ test_done
@@ -0,0 +1,32 @@
1
+ #!/bin/sh
2
+ #
3
+ # Copyright (c) 2013 Jiang Xin
4
+ #
5
+
6
+ test_description='Test git version compare'
7
+
8
+ TEST_NO_CREATE_REPO=NoThanks
9
+ . ./test-lib.sh
10
+
11
+ test_expect_success 'gistore version' '
12
+ gistore --version | grep -q "Gistore version [0-9]\+" &&
13
+ test "$(gistore -v)" = "$(gistore --version)" &&
14
+ test "$(gistore version)" = "$(gistore --version)"
15
+ '
16
+
17
+ test_expect_success 'compare two versions' '
18
+ test $(gistore check-git-version 1.8.5 1.8.5) -eq 0 &&
19
+ test $(gistore check-git-version 1.8.4 1.8.4.1) -eq -1 &&
20
+ test $(gistore check-git-version 1.7.5 1.7.11) -eq -1 &&
21
+ test $(gistore check-git-version 1.7.11 1.7.5) -eq 1 &&
22
+ test $(gistore check-git-version 1.7.11 1.7.5) -eq 1 &&
23
+ test $(gistore check-git-version 1.7.11 2.0) -eq -1 &&
24
+ test $(gistore check-git-version 2.0 1.8.5) -eq 1
25
+ '
26
+
27
+ test_expect_success 'compare with current version' '
28
+ test $(gistore check-git-version 0.99.1) -eq 1 &&
29
+ test $(gistore check-git-version 0.99.1.2) -eq 1
30
+ '
31
+
32
+ test_done
@@ -0,0 +1,89 @@
1
+ #!/bin/sh
2
+ #
3
+ # Copyright (c) 2013 Jiang Xin
4
+ #
5
+
6
+ test_description='Test gistore add and rm'
7
+
8
+ TEST_NO_CREATE_REPO=NoThanks
9
+ . ./lib-worktree.sh
10
+ . ./test-lib.sh
11
+
12
+ cwd=$(pwd -P)
13
+
14
+ cat >expect << EOF
15
+ $cwd/root/doc
16
+ $cwd/root/src
17
+ EOF
18
+
19
+ test_expect_success 'repo initial with blank backup list' '
20
+ gistore init --repo repo.git &&
21
+ gistore status --repo repo.git --backup | sed -e /^$/d | > actual &&
22
+ test ! -s actual
23
+ '
24
+
25
+ test_expect_success 'add root/src and root/doc' '
26
+ gistore add --repo repo.git root/src &&
27
+ gistore add --repo repo.git root/doc &&
28
+ gistore status --repo repo.git --backup >actual &&
29
+ test_cmp expect actual
30
+ '
31
+
32
+ cat >expect << EOF
33
+ $cwd/root/src
34
+ EOF
35
+
36
+ test_expect_success 'remove root/doc' '
37
+ (
38
+ cd repo.git &&
39
+ gistore rm ../root/doc &&
40
+ gistore status --backup >../actual
41
+ ) && test_cmp expect actual
42
+ '
43
+
44
+ cat >expect << EOF
45
+ $cwd/root
46
+ EOF
47
+
48
+ test_expect_success 'root override root/src and root/doc' '
49
+ gistore add --repo repo.git root/src &&
50
+ gistore add --repo repo.git root &&
51
+ gistore add --repo repo.git root/doc &&
52
+ gistore status --repo repo.git --backup > actual &&
53
+ test_cmp expect actual
54
+ '
55
+
56
+ test_expect_success 'not add parent of repo' '
57
+ gistore add --repo repo.git .. &&
58
+ gistore add --repo repo.git . &&
59
+ gistore status --repo repo.git --backup > actual &&
60
+ test_cmp expect actual
61
+ '
62
+
63
+ test_expect_success 'not add subdir of repo' '
64
+ gistore add --repo repo.git repo.git &&
65
+ gistore add --repo repo.git repo.git/objects &&
66
+ gistore add --repo repo.git repo.git/refs &&
67
+ gistore status --repo repo.git --backup > actual &&
68
+ test_cmp expect actual
69
+ '
70
+
71
+ cat >expect <<EOF
72
+ Error: Can not find repo at "non-exist-repo.git"
73
+ EOF
74
+
75
+ test_expect_success 'fail to add/remove on non-exist repo' '
76
+ test_must_fail gistore add --repo non-exist-repo.git root/src &&
77
+ (gistore add --repo non-exist-repo.git 2>actual || true) &&
78
+ test_cmp expect actual &&
79
+ test_must_fail gistore rm --repo non-exist-repo.git root/src &&
80
+ (gistore add --repo non-exist-repo.git 2>actual || true) &&
81
+ test_cmp expect actual
82
+ '
83
+
84
+ test_expect_success 'fail if no argument for add/remove' '
85
+ test_must_fail gistore add --repo repo.git &&
86
+ test_must_fail gistore rm --repo repo.git
87
+ '
88
+
89
+ test_done
data/t/t1010-status.sh ADDED
@@ -0,0 +1,87 @@
1
+ #!/bin/sh
2
+ #
3
+ # Copyright (c) 2013 Jiang Xin
4
+ #
5
+
6
+ test_description='Test gistore status'
7
+
8
+ TEST_NO_CREATE_REPO=NoThanks
9
+ . ./lib-worktree.sh
10
+ . ./test-lib.sh
11
+
12
+ cwd=$(pwd -P)
13
+
14
+ cat >expect << EOF
15
+ root/doc
16
+ root/src
17
+ EOF
18
+
19
+ # Parent .gitignore ignore all this directory, and new file
20
+ # will not show in git-status.
21
+ test_expect_success 'remove to avoid .gitignore side-effect' '
22
+ if [ -f "$TEST_DIRECTORY/.gitignore" ]; then
23
+ mv "$TEST_DIRECTORY/.gitignore" "$TEST_DIRECTORY/.gitignore.save"
24
+ fi
25
+ '
26
+
27
+ test_expect_success 'status show backup list' '
28
+ prepare_work_tree &&
29
+ gistore init --repo repo.git &&
30
+ gistore add --repo repo.git root/src &&
31
+ gistore add --repo repo.git root/doc &&
32
+ gistore status --repo repo.git --backup \
33
+ | sed -e "s#^${cwd}/##g" > actual &&
34
+ test_cmp expect actual
35
+ '
36
+
37
+ # Before git v1.7.4, filenames in git-status are NOT quoted.
38
+ # So strip double quote before compare with this.
39
+ cat >expect << EOF
40
+ M root/doc/COPYRIGHT
41
+ M root/src/README.txt
42
+ D root/src/images/test-binary-1.png
43
+ D root/src/lib/b/baz.a
44
+ ?? root/src/lib/a/foo.h
45
+ EOF
46
+
47
+ test_expect_success GIT_CAP_WILDMATCH 'status --git (1)' '
48
+ gistore commit --repo repo.git && \
49
+ echo "hack" >> root/doc/COPYRIGHT && \
50
+ echo "hack" >> root/src/README.txt && \
51
+ touch root/src/lib/a/foo.h && \
52
+ rm root/src/images/test-binary-1.png && \
53
+ rm root/src/lib/b/baz.a && \
54
+ gistore status --repo repo.git --git -s \
55
+ | sed -e "s#${cwd#/}/##g" | sed -e "s/\"//g" > actual &&
56
+ test_cmp expect actual
57
+ '
58
+
59
+ # Rstore parent .gitignore file
60
+ test_expect_success 'restore .gitignore' '
61
+ if [ -f "$TEST_DIRECTORY/.gitignore.save" ]; then
62
+ mv "$TEST_DIRECTORY/.gitignore.save" "$TEST_DIRECTORY/.gitignore"
63
+ fi
64
+ '
65
+
66
+ cat >expect <<EOF
67
+ Error: Can not find repo at "non-exist-repo.git"
68
+ EOF
69
+
70
+ test_expect_success 'fail for non-exist gitstore repo' '
71
+ test_must_fail gistore status --repo non-exist-repo.git &&
72
+ (gistore add --repo non-exist-repo.git 2>actual || true) &&
73
+ test_cmp expect actual
74
+ '
75
+
76
+ cat >expect <<EOF
77
+ Error: Failure while executing: git status --bad-git-status-option
78
+ EOF
79
+
80
+ test_expect_success 'fail for bad git status options' '
81
+ test_must_fail gistore status --repo repo.git --bad-git-status-option &&
82
+ (gistore status --repo repo.git --bad-git-status-option 2>&1 | grep "^Error" |
83
+ sed -e "s/ [^ ]*\/git/ git/" > actual || true) &&
84
+ test_cmp expect actual
85
+ '
86
+
87
+ test_done