git-confident 0.0.6 → 0.0.7
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/README.rdoc +17 -0
- data/lib/git/confident.rb +17 -12
- data/lib/git/elements.rb +69 -0
- data/spec/git_spec.rb +70 -11
- metadata +6 -4
data/README.rdoc
CHANGED
@@ -41,6 +41,23 @@ If that is the case, just create the branch locally and check it out.
|
|
41
41
|
$ crontab -e
|
42
42
|
13 23 * * * cd ~/my_backup && git-confident
|
43
43
|
|
44
|
+
= Advanced Use
|
45
|
+
|
46
|
+
== Ignore files and folders
|
47
|
+
You can store extra files in your backup repository (like text notes) adding them to a .gcignore file:
|
48
|
+
$ echo SETUP_NOTES >> .gcignore
|
49
|
+
$ git add .gcignore
|
50
|
+
so git-confident won't restore them. Similarly to .gitignore behaviour, you can ignore an entire folder
|
51
|
+
by adding a .gcignore file inside it.
|
52
|
+
|
53
|
+
|
54
|
+
== Folder scan
|
55
|
+
git-confident keeps a copy of each file added to git. This is not very useful when you have
|
56
|
+
an entire folder to backup. You can track a whole folder using a .gcrecusrive file (acts like .gitignore):
|
57
|
+
$ touch etc/apache2/.gcrecusive
|
58
|
+
$ git add etc/apache2/.gcrecusive
|
59
|
+
|
60
|
+
|
44
61
|
= Online
|
45
62
|
|
46
63
|
* {Source code}[http://github.com/joeyates/git-confident]
|
data/lib/git/confident.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rubygems' if RUBY_VERSION < '1.9'
|
2
2
|
require 'git'
|
3
|
+
require 'git/elements'
|
3
4
|
|
4
5
|
module Git
|
5
6
|
|
@@ -8,11 +9,13 @@ module Git
|
|
8
9
|
module VERSION #:nodoc:
|
9
10
|
MAJOR = 0
|
10
11
|
MINOR = 0
|
11
|
-
TINY =
|
12
|
+
TINY = 7
|
12
13
|
|
13
14
|
STRING = [ MAJOR, MINOR, TINY ].join( '.' )
|
14
15
|
end
|
15
16
|
|
17
|
+
attr_reader :elements
|
18
|
+
|
16
19
|
def initialize( options )
|
17
20
|
@path = options[ :path ].clone
|
18
21
|
@no_commit = options[ :no_commit ] ? true : false
|
@@ -20,21 +23,23 @@ module Git
|
|
20
23
|
raise "Git repository not found at '#{ @path }'" if ! File.directory?( "#{ @path }/.git" )
|
21
24
|
|
22
25
|
super( { :working_directory => @path } )
|
26
|
+
@elements = Git::Elements.new( @path )
|
23
27
|
|
24
28
|
case options[ :action ]
|
25
29
|
when :backup
|
26
30
|
backup
|
27
31
|
when :list
|
28
|
-
puts
|
32
|
+
puts "Files:"
|
33
|
+
puts @elements.files
|
34
|
+
puts "Folders:"
|
35
|
+
puts @elements.folders
|
36
|
+
puts "Ignored:"
|
37
|
+
puts @elements.ignored
|
29
38
|
when :restore
|
30
39
|
restore
|
31
40
|
end
|
32
41
|
end
|
33
42
|
|
34
|
-
def files
|
35
|
-
ls_files.keys.sort
|
36
|
-
end
|
37
|
-
|
38
43
|
private
|
39
44
|
|
40
45
|
def backup
|
@@ -45,22 +50,22 @@ module Git
|
|
45
50
|
end
|
46
51
|
|
47
52
|
def restore
|
48
|
-
IO.popen( "rsync --no-perms --executability --keep-dirlinks --files-from=- #{ @path }/ /", "w+" ) do | pipe |
|
49
|
-
files.each { | pathname | pipe.puts pathname }
|
53
|
+
IO.popen( "rsync --no-perms --executability --keep-dirlinks --delete --files-from=- #{ @path }/ /", "w+" ) do | pipe |
|
54
|
+
(@elements.files + @elements.folders).each { | pathname | pipe.puts pathname }
|
50
55
|
end
|
51
56
|
end
|
52
57
|
|
53
58
|
def local_backup
|
54
|
-
IO.popen( "rsync -
|
55
|
-
files.each { | pathname | pipe.puts pathname }
|
59
|
+
IO.popen( "rsync -a --recursive --delete --files-from=- / #{ @path }/", "w+" ) do | pipe |
|
60
|
+
(@elements.files + @elements.folders).each { | pathname | pipe.puts pathname }
|
56
61
|
end
|
57
62
|
end
|
58
63
|
|
59
64
|
def commit
|
60
|
-
needs_commit = status.changed.size > 0
|
65
|
+
needs_commit = (status.changed.size + status.untracked.size) > 0
|
61
66
|
return if ! needs_commit
|
62
67
|
add
|
63
|
-
super( "Automatic commit at #{ Time.now }" )
|
68
|
+
super( "Automatic commit at #{ Time.now }", {:add_all => true} )
|
64
69
|
end
|
65
70
|
|
66
71
|
def push
|
data/lib/git/elements.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'rubygems' if RUBY_VERSION < '1.9'
|
2
|
+
require 'git'
|
3
|
+
|
4
|
+
module Git
|
5
|
+
|
6
|
+
class Elements < Git::Base
|
7
|
+
IGNORE = 'gcignore'
|
8
|
+
RECURSIVE = 'gcrecursive'
|
9
|
+
|
10
|
+
def initialize( path )
|
11
|
+
@path = path.clone
|
12
|
+
super( { :working_directory => @path } )
|
13
|
+
@gcfiles, @gitfiles = elements_scan
|
14
|
+
end
|
15
|
+
|
16
|
+
def ignored
|
17
|
+
return @ignored if @ignored
|
18
|
+
ignores = @gcfiles.select do | f |
|
19
|
+
File.basename( f ) =~ /^\.#{IGNORE}$/i
|
20
|
+
end
|
21
|
+
@ignored = gcfiles_scan( ignores )
|
22
|
+
end
|
23
|
+
|
24
|
+
def folders
|
25
|
+
return @folders if @folders
|
26
|
+
recursives = @gcfiles.select do | f |
|
27
|
+
File.basename( f ) =~ /^\.#{RECURSIVE}$/i
|
28
|
+
end
|
29
|
+
@folders = gcfiles_scan( recursives ).collect { |f| File.join f, '/' }
|
30
|
+
end
|
31
|
+
|
32
|
+
def files
|
33
|
+
return @files if @files
|
34
|
+
@files = @gitfiles.reject do | f |
|
35
|
+
(ignored + folders).find { |i| f =~ /^#{i}/ }
|
36
|
+
end.sort
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
# result[0] = git-confident special files
|
43
|
+
# result[1] = other git tracked files
|
44
|
+
def elements_scan
|
45
|
+
result = ls_files.keys.sort.partition do | f |
|
46
|
+
name = File.basename( f )
|
47
|
+
name =~ /^\.#{IGNORE}$/i or name =~ /^\.#{RECURSIVE}$/i or name =~ /^\.gitignore$/i
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def gcfiles_scan( files )
|
52
|
+
files.collect do | file |
|
53
|
+
full_path = File.expand_path( file, @path )
|
54
|
+
relative_path = File.dirname( file )
|
55
|
+
|
56
|
+
next [relative_path] if File.zero?( full_path )
|
57
|
+
|
58
|
+
File.open( full_path ).collect do | line |
|
59
|
+
line.chomp!
|
60
|
+
next if line.empty?
|
61
|
+
next line if relative_path == '.'
|
62
|
+
File.join( relative_path, line )
|
63
|
+
end.compact
|
64
|
+
end.flatten.sort
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
data/spec/git_spec.rb
CHANGED
@@ -6,24 +6,83 @@ SPEC_PATH = File.expand_path( File.dirname( __FILE__ ) )
|
|
6
6
|
ROOT_PATH = File.dirname( SPEC_PATH )
|
7
7
|
require File.join( ROOT_PATH, 'lib', 'git', 'confident' )
|
8
8
|
|
9
|
+
Joiner = lambda do |base|
|
10
|
+
lambda do |*others|
|
11
|
+
File.join(base, *others)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
9
15
|
describe 'when handling the repository' do
|
10
16
|
|
11
|
-
before( :
|
12
|
-
@
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
before( :all ) do
|
18
|
+
@backup_path = Joiner[ SPEC_PATH ][ 'gcbkp' ]
|
19
|
+
@source_path = Joiner[ 'tmp' ][ 'gcsrc' ]
|
20
|
+
@backup_join = Joiner[ @backup_path ]
|
21
|
+
@source_join = Joiner[ @source_path ]
|
22
|
+
repo = Git::Base.init( @backup_path )
|
23
|
+
|
24
|
+
test_files = [ 'file',
|
25
|
+
'folder/file2',
|
26
|
+
'folder/file3',
|
27
|
+
'folder/folder2/file4',
|
28
|
+
'folder/folder2/file5',
|
29
|
+
'folder/folder3/file6',
|
30
|
+
'folder/folder3/file7',
|
31
|
+
'ignore_me' ]
|
32
|
+
FileUtils.mkdir_p( @backup_join[ @source_path, 'folder/folder2' ] )
|
33
|
+
FileUtils.mkdir_p( @backup_join[ @source_path, 'folder/folder3' ] )
|
34
|
+
test_files.each { |tf| File.open( @backup_join[ @source_path, tf ], 'w' ) }
|
35
|
+
File.open( @backup_join[ @source_path, 'folder/folder3/.gcignore' ], 'w' ) { |file| file.write 'file7' }
|
36
|
+
File.open( @backup_join[ '.gcignore' ], 'w' ) { |file| file.write <<ASD
|
37
|
+
#{@source_join[ 'ignore_me' ]}
|
38
|
+
#{@source_join[ 'wrong_file' ]}
|
39
|
+
ASD
|
40
|
+
}
|
41
|
+
File.open( @backup_join[ '.gcrecursive' ], 'w' ) { |file| file.write @source_join[ 'folder/folder2' ] }
|
42
|
+
repo.add '*'
|
18
43
|
end
|
19
44
|
|
20
|
-
after( :
|
21
|
-
`rm -rf '#{ @
|
45
|
+
after( :all ) do
|
46
|
+
`rm -rf '#{ @backup_path }'`
|
47
|
+
`rm -rf '/#{ @source_path }'`
|
22
48
|
end
|
23
49
|
|
24
50
|
it 'lists files' do
|
25
|
-
conf = Git::Confident.new( @
|
26
|
-
|
51
|
+
conf = Git::Confident.new( :path => @backup_path )
|
52
|
+
expected = [ 'file',
|
53
|
+
'folder/file2',
|
54
|
+
'folder/file3',
|
55
|
+
'folder/folder3/file6' ]
|
56
|
+
conf.elements.files.should == expected.collect { |e| @source_join[ e ] }
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'lists ignored files' do
|
60
|
+
conf = Git::Confident.new( :path => @backup_path )
|
61
|
+
expected = [ 'folder/folder3/file7',
|
62
|
+
'ignore_me',
|
63
|
+
'wrong_file' ]
|
64
|
+
conf.elements.ignored.should == expected.collect { |e| @source_join[ e ] }
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'lists recursive folders' do
|
68
|
+
conf = Git::Confident.new( :path => @backup_path )
|
69
|
+
conf.elements.folders.should == [ @source_join[ 'folder/folder2/' ] ]
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'restores backup' do
|
73
|
+
conf = Git::Confident.new( :path => @backup_path, :action => :restore )
|
74
|
+
source_abs_join = Joiner[ '/' + @source_path ]
|
75
|
+
restored = Dir.glob( source_abs_join[ '**/*' ] )
|
76
|
+
expected = [ 'file',
|
77
|
+
'folder',
|
78
|
+
'folder/file2',
|
79
|
+
'folder/file3',
|
80
|
+
'folder/folder2',
|
81
|
+
'folder/folder2/file4',
|
82
|
+
'folder/folder2/file5',
|
83
|
+
'folder/folder3',
|
84
|
+
'folder/folder3/file6' ]
|
85
|
+
restored.sort.should == expected.collect { |e| source_abs_join[ e ] }.sort
|
27
86
|
end
|
28
87
|
|
29
88
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git-confident
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joe Yates
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-18 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -60,11 +60,13 @@ extra_rdoc_files:
|
|
60
60
|
- README.rdoc
|
61
61
|
- bin/git-confident
|
62
62
|
- lib/git/confident.rb
|
63
|
+
- lib/git/elements.rb
|
63
64
|
files:
|
64
65
|
- Rakefile
|
65
66
|
- README.rdoc
|
66
67
|
- bin/git-confident
|
67
68
|
- lib/git/confident.rb
|
69
|
+
- lib/git/elements.rb
|
68
70
|
- spec/git_spec.rb
|
69
71
|
has_rdoc: true
|
70
72
|
homepage: http://github.com/joeyates/git-confident
|