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
data/t/t1020-commit.sh ADDED
@@ -0,0 +1,134 @@
1
+ #!/bin/sh
2
+ #
3
+ # Copyright (c) 2013 Jiang Xin
4
+ #
5
+
6
+ test_description='Test gistore commit'
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/COPYRIGHT
16
+ root/src/README.txt
17
+ root/src/images/test-binary-1.png
18
+ root/src/images/test-binary-2.png
19
+ root/src/lib/a/foo.c
20
+ root/src/lib/b/bar.o
21
+ root/src/lib/b/baz.a
22
+ EOF
23
+
24
+ test_expect_success 'initialize for commit' '
25
+ prepare_work_tree &&
26
+ gistore init --repo repo.git &&
27
+ gistore add --repo repo.git root/src &&
28
+ gistore add --repo repo.git root/doc &&
29
+ gistore commit --repo repo.git &&
30
+ test "$(count_git_commits repo.git)" = "1" &&
31
+ gistore repo repo.git ls-tree --name-only \
32
+ -r HEAD | sed -e "s#^${cwd#/}/##g" > actual &&
33
+ test_cmp expect actual
34
+ '
35
+
36
+ test_expect_success 'nothing changed, no commit' '
37
+ gistore commit --repo repo.git &&
38
+ touch root/src/README.txt &&
39
+ gistore commit --repo repo.git &&
40
+ test "$(count_git_commits repo.git)" = "1"
41
+ '
42
+
43
+ test_expect_success 'commit if something changed' '
44
+ echo "more" >> root/src/README.txt &&
45
+ gistore commit --repo repo.git &&
46
+ test "$(count_git_commits repo.git)" = "2"
47
+ '
48
+
49
+ cat >expect << EOF
50
+ root/doc/COPYRIGHT
51
+ root/src/README.txt
52
+ root/src/images/test-binary-1.png
53
+ root/src/images/test-binary-2.png
54
+ root/src/lib/a/foo.c
55
+ root/src/lib/b/bar.o
56
+ EOF
57
+
58
+ test_expect_success 'commit if something removed' '
59
+ rm root/src/lib/b/baz.a &&
60
+ gistore commit --repo repo.git &&
61
+ test "$(count_git_commits repo.git)" = "3" &&
62
+ gistore repo repo.git ls-tree --name-only \
63
+ -r HEAD | sed -e "s#^${cwd#/}/##g" > actual &&
64
+ test_cmp expect actual
65
+ '
66
+
67
+ cat >expect << EOF
68
+ root/doc/COPYRIGHT
69
+ root/new_src/README.txt
70
+ root/new_src/images/test-binary-1.png
71
+ root/new_src/images/test-binary-2.png
72
+ root/new_src/lib/a/foo.c
73
+ root/new_src/lib/b/bar.o
74
+ root/src
75
+ EOF
76
+
77
+ test_expect_success 'commit even for symlink' '
78
+ mv root/src root/new_src &&
79
+ ln -s new_src root/src &&
80
+ gistore commit --repo repo.git &&
81
+ test "$(count_git_commits repo.git)" = "4" &&
82
+ gistore repo repo.git ls-tree --name-only \
83
+ -r HEAD | sed -e "s#^${cwd#/}/##g" > actual &&
84
+ test_cmp expect actual
85
+ '
86
+
87
+ cat >expect << EOF
88
+ root/doc/COPYRIGHT
89
+ EOF
90
+
91
+ test_expect_success 'not backup root/src any more' '
92
+ gistore rm --repo repo.git root/src &&
93
+ gistore commit --repo repo.git &&
94
+ test -L root/src &&
95
+ test -f root/new_src/README.txt &&
96
+ test -f root/new_src/images/test-binary-1.png &&
97
+ test -f root/new_src/lib/a/foo.c &&
98
+ test -f root/new_src/lib/b/bar.o &&
99
+ gistore repo repo.git ls-tree --name-only \
100
+ -r HEAD | sed -e "s#^${cwd#/}/##g" > actual &&
101
+ test_cmp expect actual
102
+ '
103
+
104
+ cat >expect << EOF
105
+ root/doc/COPYRIGHT
106
+ root/mod1/README.txt
107
+ root/mod1/lib/doc/bar.txt
108
+ root/mod1/lib/src/foo.c
109
+ root/mod2/README.txt
110
+ root/mod2/doc/bar.txt
111
+ root/mod2/lib/hello.txt
112
+ root/mod2/src/foo.c
113
+ EOF
114
+
115
+ test_expect_success 'add real files instead of submodule' '
116
+ gistore add --repo repo.git root/mod1 &&
117
+ gistore add --repo repo.git root/mod2 &&
118
+ gistore commit --repo repo.git &&
119
+ gistore repo repo.git ls-tree --name-only \
120
+ -r HEAD | sed -e "s#^${cwd#/}/##g" > actual &&
121
+ test_cmp expect actual
122
+ '
123
+
124
+ cat >expect <<EOF
125
+ Error: Can not find repo at "non-exist-repo.git"
126
+ EOF
127
+
128
+ test_expect_success 'fail if commit on non-exist repo' '
129
+ test_must_fail gistore commit --repo non-exist-repo.git &&
130
+ (gistore commit --repo non-exist-repo.git 2>actual || true) &&
131
+ test_cmp expect actual
132
+ '
133
+
134
+ test_done
@@ -0,0 +1,266 @@
1
+ #!/bin/sh
2
+ #
3
+ # Copyright (c) 2013 Jiang Xin
4
+ #
5
+
6
+ test_description='Test gistore commit'
7
+
8
+ TEST_NO_CREATE_REPO=NoThanks
9
+ . ./lib-worktree.sh
10
+ . ./test-lib.sh
11
+
12
+ do_hack()
13
+ {
14
+ echo "hack $*" >> root/src/README.txt
15
+ echo "hack $*" >> root/doc/COPYRIGHT
16
+ }
17
+
18
+ cwd=$(pwd -P)
19
+ n=0
20
+
21
+ test_expect_success 'initialize for commit' '
22
+ n=$((n+1)) &&
23
+ prepare_work_tree &&
24
+ gistore init --repo repo.git &&
25
+ gistore config --repo repo.git full_backup_number 3 &&
26
+ gistore config --repo repo.git increment_backup_number 5 &&
27
+ gistore add --repo repo.git root/src &&
28
+ gistore add --repo repo.git root/doc &&
29
+ gistore commit --repo repo.git -m "Backup No. $n" &&
30
+ test "$(count_git_commits repo.git)" = "$n"
31
+ '
32
+
33
+ cat >expect << EOF
34
+ Backup No. 6
35
+ Backup No. 5
36
+ Backup No. 4
37
+ Backup No. 3
38
+ Backup No. 2
39
+ Backup No. 1
40
+ EOF
41
+
42
+ test_expect_success 'no rotate when commit 5 times' '
43
+ i=0 &&
44
+ while test $i -lt 5; do
45
+ i=$((i+1));
46
+ n=$((n+1));
47
+ do_hack $n;
48
+ gistore commit --repo repo.git -m "Backup No. $n";
49
+ done &&
50
+ git_log_only_subject repo.git > actual &&
51
+ test_cmp expect actual &&
52
+ echo "* master" > expect &&
53
+ gistore repo repo.git branch > actual &&
54
+ test_cmp expect actual
55
+ '
56
+
57
+ cat >expect <<EOF
58
+ gistore/1
59
+ * master
60
+ EOF
61
+
62
+ test_expect_success 'rotate with additional commit' '
63
+ n=$((n+1)) && do_hack $n &&
64
+ gistore commit --repo repo.git -m "Backup No. $n" &&
65
+ gistore repo repo.git branch > actual &&
66
+ test_cmp expect actual
67
+ '
68
+
69
+ cat >expect << EOF
70
+ Backup No. 7
71
+ Full backup of repo.git
72
+ Backup No. 5
73
+ Backup No. 4
74
+ Backup No. 3
75
+ Backup No. 2
76
+ Backup No. 1
77
+ EOF
78
+
79
+ test_expect_success 'graft test' '
80
+ git_log_only_subject repo.git > actual &&
81
+ test_cmp expect actual &&
82
+ head -2 expect > expect2 &&
83
+ git_log_only_subject repo.git --without_grafts > actual &&
84
+ test_cmp expect2 actual &&
85
+ echo "Backup No. 6" > expect3 &&
86
+ tail -5 expect >> expect3 &&
87
+ git_log_only_subject repo.git --without_grafts gistore/1 > actual &&
88
+ test_cmp expect3 actual
89
+ '
90
+
91
+ cat >expect << EOF
92
+ Backup No. 12
93
+ Full backup of repo.git
94
+ Backup No. 10
95
+ Backup No. 9
96
+ Backup No. 8
97
+ Backup No. 7
98
+ Full backup of repo.git
99
+ Backup No. 5
100
+ Backup No. 4
101
+ Backup No. 3
102
+ Backup No. 2
103
+ Backup No. 1
104
+ EOF
105
+
106
+ test_expect_success 'rotate after commit another 5 times' '
107
+ i=0 &&
108
+ while test $i -lt 5; do
109
+ i=$((i+1));
110
+ n=$((n+1));
111
+ do_hack $n;
112
+ gistore commit --repo repo.git -m "Backup No. $n";
113
+ done &&
114
+ git_log_only_subject repo.git > actual &&
115
+ test_cmp expect actual &&
116
+ echo " gistore/1" > expect &&
117
+ echo " gistore/2" >> expect &&
118
+ echo "* master" >> expect &&
119
+ gistore repo repo.git branch > actual &&
120
+ test_cmp expect actual
121
+ '
122
+
123
+ cat >expect << EOF
124
+ Backup No. 12
125
+ Full backup of repo.git
126
+ EOF
127
+
128
+ test_expect_success 'commit log of master (no grafts)' '
129
+ git_log_only_subject repo.git --without_grafts > actual &&
130
+ test_cmp expect actual
131
+ '
132
+
133
+ cat >expect << EOF
134
+ Backup No. 11
135
+ Backup No. 10
136
+ Backup No. 9
137
+ Backup No. 8
138
+ Backup No. 7
139
+ Full backup of repo.git
140
+ EOF
141
+
142
+ test_expect_success 'commit log of gistore/1 (no grafts)' '
143
+ git_log_only_subject repo.git --without_grafts gistore/1 > actual &&
144
+ test_cmp expect actual
145
+ '
146
+
147
+ cat >expect << EOF
148
+ Backup No. 6
149
+ Backup No. 5
150
+ Backup No. 4
151
+ Backup No. 3
152
+ Backup No. 2
153
+ Backup No. 1
154
+ EOF
155
+
156
+ test_expect_success 'commit log of gistore/2 (no grafts)' '
157
+ git_log_only_subject repo.git --without_grafts gistore/2 > actual &&
158
+ test_cmp expect actual
159
+ '
160
+
161
+ cat >expect << EOF
162
+ gistore/1
163
+ gistore/2
164
+ gistore/3
165
+ * master
166
+ EOF
167
+
168
+ test_expect_success 'after 20 commits' '
169
+ i=0 &&
170
+ while test $i -lt 20; do
171
+ i=$((i+1));
172
+ n=$((n+1));
173
+ do_hack $n;
174
+ gistore commit --repo repo.git -m "Backup No. $n";
175
+ done &&
176
+ gistore repo repo.git branch > actual &&
177
+ test_cmp expect actual
178
+ '
179
+
180
+ cat >expect << EOF
181
+ Backup No. 21
182
+ Backup No. 20
183
+ Backup No. 19
184
+ Backup No. 18
185
+ Backup No. 17
186
+ Full backup of repo.git
187
+ EOF
188
+
189
+ test_expect_success 'commit log of gistore/3 (no grafts)' '
190
+ git_log_only_subject repo.git --without_grafts gistore/3 > actual &&
191
+ test_cmp expect actual
192
+ '
193
+
194
+ cat >expect << EOF
195
+ Backup No. 26
196
+ Backup No. 25
197
+ Backup No. 24
198
+ Backup No. 23
199
+ Backup No. 22
200
+ Full backup of repo.git
201
+ EOF
202
+
203
+ test_expect_success 'commit log of gistore/2 (no grafts)' '
204
+ git_log_only_subject repo.git --without_grafts gistore/2 > actual &&
205
+ test_cmp expect actual
206
+ '
207
+
208
+ cat >expect << EOF
209
+ Backup No. 31
210
+ Backup No. 30
211
+ Backup No. 29
212
+ Backup No. 28
213
+ Backup No. 27
214
+ Full backup of repo.git
215
+ EOF
216
+
217
+ test_expect_success 'commit log of gistore/1 (no grafts)' '
218
+ git_log_only_subject repo.git --without_grafts gistore/1 > actual &&
219
+ test_cmp expect actual
220
+ '
221
+
222
+ cat >expect << EOF
223
+ Backup No. 32
224
+ Full backup of repo.git
225
+ EOF
226
+
227
+ test_expect_success 'commit log of master (no grafts)' '
228
+ git_log_only_subject repo.git --without_grafts > actual &&
229
+ test_cmp expect actual
230
+ '
231
+
232
+ cat >expect << EOF
233
+ Backup No. 32
234
+ Full backup of repo.git
235
+ Backup No. 30
236
+ Backup No. 29
237
+ Backup No. 28
238
+ Backup No. 27
239
+ Full backup of repo.git
240
+ Backup No. 25
241
+ Backup No. 24
242
+ Backup No. 23
243
+ Backup No. 22
244
+ Full backup of repo.git
245
+ Backup No. 20
246
+ Backup No. 19
247
+ Backup No. 18
248
+ Backup No. 17
249
+ Full backup of repo.git
250
+ EOF
251
+
252
+ test_expect_success 'commit log of master (with grafts)' '
253
+ git_log_only_subject repo.git > actual &&
254
+ test_cmp expect actual
255
+ '
256
+
257
+ test_expect_success 'purge history using gc' '
258
+ count=$(count_git_objects repo.git) &&
259
+ gistore repo repo.git prune --expire=now &&
260
+ gistore repo repo.git gc &&
261
+ test $(count_git_objects repo.git) -eq $count &&
262
+ gistore gc --repo repo.git --force &&
263
+ test $(count_git_objects repo.git) -lt $count
264
+ '
265
+
266
+ test_done
@@ -0,0 +1,132 @@
1
+ #!/bin/sh
2
+ #
3
+ # Copyright (c) 2013 Jiang Xin
4
+ #
5
+
6
+ test_description='Test gistore task'
7
+
8
+ TEST_NO_CREATE_REPO=NoThanks
9
+ . ./lib-worktree.sh
10
+ . ./test-lib.sh
11
+
12
+ do_hack()
13
+ {
14
+ echo "hack $*" >> root/src/README.txt
15
+ echo "hack $*" >> root/doc/COPYRIGHT
16
+ }
17
+
18
+ cwd=$(pwd -P)
19
+
20
+ HOME=$cwd
21
+ unset XDG_CONFIG_HOME
22
+ GISTORE_TEST_GIT_CONFIG=Yes
23
+ export HOME XDG_CONFIG_HOME GISTORE_TEST_GIT_CONFIG
24
+
25
+ touch config_file
26
+ GIT_CONFIG=$cwd/config_file
27
+ export GIT_CONFIG
28
+
29
+ cat >expect << EOF
30
+ System level Tasks
31
+ User level Tasks
32
+ EOF
33
+
34
+ test_expect_success 'initial config' '
35
+ prepare_work_tree &&
36
+ gistore init --repo repo1.git &&
37
+ gistore init --repo repo2.git &&
38
+ gistore add --repo repo1.git root/src root/doc &&
39
+ gistore add --repo repo2.git root/src root/doc &&
40
+ gistore task list |sed -e "/^$/d" > actual &&
41
+ test_cmp expect actual
42
+ '
43
+
44
+ # Ruby hash to yaml may have different order, so sort before compare.
45
+ cat >expect << EOF
46
+ hello => repo1.git
47
+ world => repo2.git
48
+ EOF
49
+
50
+ test_expect_success 'task add and task list' '
51
+ gistore task add hello repo1.git &&
52
+ gistore task add world repo2.git &&
53
+ gistore task list | grep -q "$cwd" &&
54
+ gistore task list | sed -e "/^$/d" | \
55
+ sed -e "s#${cwd}/##g" | grep "^ " | sort -u > actual &&
56
+ test_cmp expect actual
57
+ '
58
+
59
+ test_expect_success 'commit specific task' '
60
+ test "$(count_git_commits repo1.git)" = "0" &&
61
+ test "$(count_git_commits repo2.git)" = "0" &&
62
+ gistore commit --repo hello -m "task hello, commit no.1" &&
63
+ test "$(count_git_commits repo1.git)" = "1" &&
64
+ test "$(count_git_commits repo2.git)" = "0" &&
65
+ gistore ci --repo world -m "for world, commit no.1" &&
66
+ test "$(count_git_commits repo1.git)" = "1" &&
67
+ test "$(count_git_commits repo2.git)" = "1" &&
68
+ test "$(git_log_only_subject repo1.git -1)" = \
69
+ "task hello, commit no.1" &&
70
+ test "$(git_log_only_subject repo2.git -1)" = \
71
+ "for world, commit no.1"
72
+ '
73
+
74
+ test_expect_success 'commit all task' '
75
+ do_hack &&
76
+ gistore commit-all &&
77
+ test "$(count_git_commits repo1.git)" = "2" &&
78
+ test "$(count_git_commits repo2.git)" = "2" &&
79
+ do_hack &&
80
+ gistore ci-all -m "commit invoke by ci-all" &&
81
+ test "$(count_git_commits repo1.git)" = "3" &&
82
+ test "$(count_git_commits repo2.git)" = "3" &&
83
+ test "$(git_log_only_subject repo1.git -1)" = \
84
+ "commit invoke by ci-all" &&
85
+ test "$(git_log_only_subject repo2.git -1)" = \
86
+ "commit invoke by ci-all"
87
+ '
88
+
89
+ cat >expect << EOF
90
+ System level Tasks
91
+ hello => repo1.git
92
+ User level Tasks
93
+ hello => repo1.git
94
+ EOF
95
+
96
+ test_expect_success 'task remove' '
97
+ do_hack &&
98
+ gistore task rm world &&
99
+ gistore task list |sed -e "/^$/d" | sed -e "s#${cwd}/##g" > actual &&
100
+ test_cmp expect actual &&
101
+ gistore commit-all &&
102
+ test "$(count_git_commits repo1.git)" = "4" &&
103
+ test "$(count_git_commits repo2.git)" = "3"
104
+ '
105
+
106
+ cat >expect << EOF
107
+ hello => repo1.git
108
+ world => repo2.git
109
+ EOF
110
+
111
+ test_expect_success 'commit-all while missing task repo' '
112
+ gistore task add hello repo1.git &&
113
+ gistore task add world repo2.git &&
114
+ gistore task list | grep -q "$cwd" &&
115
+ gistore task list | sed -e "/^$/d" | \
116
+ sed -e "s#${cwd}/##g" | grep "^ " | sort -u > actual &&
117
+ test_cmp expect actual &&
118
+ do_hack &&
119
+ gistore commit-all &&
120
+ test "$(count_git_commits repo1.git)" = "5" &&
121
+ test "$(count_git_commits repo2.git)" = "4" &&
122
+ mv repo1.git repo1.git.moved &&
123
+ do_hack &&
124
+ test_must_fail gistore commit-all &&
125
+ test "$(count_git_commits repo2.git)" = "5" &&
126
+ mv repo1.git.moved repo1.git &&
127
+ mv repo2.git repo2.git.moved &&
128
+ test_must_fail gistore commit-all &&
129
+ test "$(count_git_commits repo1.git)" = "6"
130
+ '
131
+
132
+ test_done