silo 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -0
- data/lib/grit/index.rb +32 -0
- data/lib/silo/cli.rb +3 -3
- data/lib/silo/repository.rb +6 -13
- data/lib/silo/version.rb +2 -2
- data/test/test_repository.rb +37 -0
- metadata +6 -5
data/Rakefile
CHANGED
data/lib/grit/index.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# This code is free software; you can redistribute it and/or modify it under
|
2
|
+
# the terms of the new BSD License.
|
3
|
+
#
|
4
|
+
# Copyright (c) 2011, Sebastian Staudt
|
5
|
+
|
6
|
+
# Monkey patches an issue in Grit::Index which prevents directories from being
|
7
|
+
# cleanly removed from the index and the repository
|
8
|
+
class Grit::Index
|
9
|
+
|
10
|
+
# Add (or remove) a file to the index
|
11
|
+
#
|
12
|
+
# @param [String] path The path to the file
|
13
|
+
# @param [String] data The contents of the file
|
14
|
+
def add(path, data)
|
15
|
+
is_dir = path[-1] == 47
|
16
|
+
path = path.split('/')
|
17
|
+
filename = path.pop
|
18
|
+
filename += '/' if is_dir
|
19
|
+
|
20
|
+
current = self.tree
|
21
|
+
p current
|
22
|
+
|
23
|
+
path.each do |dir|
|
24
|
+
current[dir] ||= {}
|
25
|
+
node = current[dir]
|
26
|
+
current = node
|
27
|
+
end
|
28
|
+
|
29
|
+
current[filename] = data
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/lib/silo/cli.rb
CHANGED
@@ -76,9 +76,9 @@ module Silo
|
|
76
76
|
end
|
77
77
|
|
78
78
|
command :init, 'Initialize a Silo repository', :path => :optional do
|
79
|
-
|
80
|
-
puts "Initializing Silo repository in #{
|
81
|
-
Repository.new
|
79
|
+
repo_path = File.expand_path(args[:path] || '.')
|
80
|
+
puts "Initializing Silo repository in #{repo_path}..."
|
81
|
+
Repository.new repo_path
|
82
82
|
end
|
83
83
|
|
84
84
|
flag :l, 'List each object in a separate line'
|
data/lib/silo/repository.rb
CHANGED
@@ -8,6 +8,8 @@ require 'tmpdir'
|
|
8
8
|
require 'rubygems'
|
9
9
|
require 'grit'
|
10
10
|
|
11
|
+
require File.dirname(__FILE__) + '/../grit/index'
|
12
|
+
|
11
13
|
module Silo
|
12
14
|
|
13
15
|
# Represents a Silo repository
|
@@ -305,21 +307,12 @@ module Silo
|
|
305
307
|
# @param [String] path The path of the file or directory to remove from the
|
306
308
|
# repository
|
307
309
|
def remove(path)
|
310
|
+
object = object! path
|
311
|
+
path += '/' if object.is_a?(Grit::Tree) && path[-1] != 47
|
308
312
|
index = @git.index
|
309
313
|
index.read_tree 'HEAD'
|
310
|
-
|
311
|
-
|
312
|
-
if dir
|
313
|
-
Dir.entries(f)[2..-1].each do |child|
|
314
|
-
remove.call File.join(f, child)
|
315
|
-
end
|
316
|
-
else
|
317
|
-
index.delete f
|
318
|
-
end
|
319
|
-
dir
|
320
|
-
end
|
321
|
-
dir = remove.call path
|
322
|
-
type = dir ? 'directory' : 'file'
|
314
|
+
index.delete path
|
315
|
+
type = object.is_a?(Grit::Tree) ? 'directory' : 'file'
|
323
316
|
commit_msg = "Removed #{type} #{path}"
|
324
317
|
index.commit commit_msg, @git.head.commit.sha
|
325
318
|
end
|
data/lib/silo/version.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# This code is free software; you can redistribute it and/or modify it under
|
2
2
|
# the terms of the new BSD License.
|
3
3
|
#
|
4
|
-
# Copyright (c) 2010, Sebastian Staudt
|
4
|
+
# Copyright (c) 2010-2011, Sebastian Staudt
|
5
5
|
|
6
6
|
module Silo
|
7
7
|
|
8
8
|
# The current version of the Silo gem
|
9
|
-
VERSION = '0.1.
|
9
|
+
VERSION = '0.1.1'
|
10
10
|
|
11
11
|
end
|
data/test/test_repository.rb
CHANGED
@@ -105,6 +105,11 @@ class TestRepository < Test::Unit::TestCase
|
|
105
105
|
assert (@repo.git.tree/('file2')).is_a? Grit::Blob
|
106
106
|
assert_equal "Added file #{@data_dir + 'file1'} into '/'", @repo.git.commits[1].message
|
107
107
|
assert_equal "Added file #{@data_dir + 'file2'} into '/'", @repo.git.commits[2].message
|
108
|
+
assert_equal %w{.silo file1 file2}, @repo.contents
|
109
|
+
|
110
|
+
assert_raise FileNotFoundError do
|
111
|
+
@repo.restore 'file3'
|
112
|
+
end
|
108
113
|
end
|
109
114
|
|
110
115
|
should 'save directory trees correctly' do
|
@@ -118,6 +123,13 @@ class TestRepository < Test::Unit::TestCase
|
|
118
123
|
assert (@repo.git.tree/('data/subdir1/file1')).is_a? Grit::Blob
|
119
124
|
assert (@repo.git.tree/('data/subdir2')).is_a? Grit::Tree
|
120
125
|
assert (@repo.git.tree/('data/subdir2/file2')).is_a? Grit::Blob
|
126
|
+
assert_equal %w{data data/file1 data/file2 data/subdir1 data/subdir1/file1 data/subdir2 data/subdir2/file2}, @repo.contents('data')
|
127
|
+
assert_equal %w{data/subdir1 data/subdir1/file1}, @repo.contents('data/subdir1')
|
128
|
+
assert_equal %w{data/subdir2 data/subdir2/file2}, @repo.contents('data/subdir2')
|
129
|
+
|
130
|
+
assert_raise FileNotFoundError do
|
131
|
+
@repo.restore 'file1'
|
132
|
+
end
|
121
133
|
end
|
122
134
|
|
123
135
|
should 'save single files correctly into a prefix directory' do
|
@@ -129,6 +141,10 @@ class TestRepository < Test::Unit::TestCase
|
|
129
141
|
assert (@repo.git.tree/('prefix/file2')).is_a? Grit::Blob
|
130
142
|
assert_equal "Added file #{@data_dir + 'file1'} into 'prefix'", @repo.git.commits[1].message
|
131
143
|
assert_equal "Added file #{@data_dir + 'file2'} into 'prefix'", @repo.git.commits[2].message
|
144
|
+
|
145
|
+
assert_raise FileNotFoundError do
|
146
|
+
@repo.restore 'file1'
|
147
|
+
end
|
132
148
|
end
|
133
149
|
|
134
150
|
should 'save directory trees correctly into a prefix directory' do
|
@@ -142,6 +158,10 @@ class TestRepository < Test::Unit::TestCase
|
|
142
158
|
assert (@repo.git.tree/('prefix/data/subdir1/file1')).is_a? Grit::Blob
|
143
159
|
assert (@repo.git.tree/('prefix/data/subdir2')).is_a? Grit::Tree
|
144
160
|
assert (@repo.git.tree/('prefix/data/subdir2/file2')).is_a? Grit::Blob
|
161
|
+
|
162
|
+
assert_raise FileNotFoundError do
|
163
|
+
@repo.restore 'prefix/file1'
|
164
|
+
end
|
145
165
|
end
|
146
166
|
|
147
167
|
should 'restore single files correctly' do
|
@@ -168,6 +188,23 @@ class TestRepository < Test::Unit::TestCase
|
|
168
188
|
assert File.exist? @target_dir/'subdir1/file1'
|
169
189
|
end
|
170
190
|
|
191
|
+
should 'remove files and directories correctly' do
|
192
|
+
@repo.add @data_dir
|
193
|
+
@repo.add @data_dir/'file1'
|
194
|
+
|
195
|
+
@repo.remove 'data/file1'
|
196
|
+
assert_equal 4, @repo.git.commits.size
|
197
|
+
assert (@repo.git.tree/'data/file1').nil?
|
198
|
+
|
199
|
+
@repo.remove 'data'
|
200
|
+
assert_equal 5, @repo.git.commits.size
|
201
|
+
assert (@repo.git.tree/'data').nil?
|
202
|
+
|
203
|
+
@repo.remove 'file1'
|
204
|
+
assert_equal 6, @repo.git.commits.size
|
205
|
+
assert (@repo.git.tree/'file1').nil?
|
206
|
+
end
|
207
|
+
|
171
208
|
should 'purge files and directories correctly' do
|
172
209
|
@repo.add @data_dir
|
173
210
|
@repo.add @data_dir/'file1'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: silo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sebastian Staudt
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-02-02 00:00:00 +01:00
|
19
19
|
default_executable: silo
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- test/data/subdir2/file2
|
121
121
|
- test/data/subdir1/file1
|
122
122
|
- lib/silo/version.rb
|
123
|
+
- lib/grit/index.rb
|
123
124
|
- Rakefile
|
124
125
|
- README.md
|
125
126
|
- test/test_repository.rb
|
@@ -159,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
160
|
requirements:
|
160
161
|
- git >= 1.6
|
161
162
|
rubyforge_project: silo
|
162
|
-
rubygems_version: 1.
|
163
|
+
rubygems_version: 1.5.0
|
163
164
|
signing_key:
|
164
165
|
specification_version: 3
|
165
166
|
summary: A command-line utility and API for Git-based backups
|