git-confident 0.0.4 → 0.0.5

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.
Files changed (3) hide show
  1. data/bin/git-confident +10 -11
  2. data/lib/git/confident.rb +31 -4
  3. metadata +3 -3
data/bin/git-confident CHANGED
@@ -8,16 +8,19 @@ $:.unshift( LIB_PATH )
8
8
  require 'git/confident'
9
9
 
10
10
  options = {
11
- :restore => false,
12
- :commit => true,
13
- :path => File.expand_path( Dir::pwd ) # Default to current directory
11
+ :action => :backup,
12
+ :path => File.expand_path( Dir::pwd ) # Default to current directory
14
13
  }
15
14
 
16
15
  OptionParser.new do | opts |
17
- opts.banner = "Usage: $0 [options]"
16
+ opts.banner = "Usage: #{ $0 } [options]"
18
17
 
19
18
  opts.on("-C", "--no-commit", "Only copy files, do not do a git commit") do
20
- options[:commit] = false
19
+ options[ :no_commit ] = true
20
+ end
21
+
22
+ opts.on("-l", "--list", "List all files in the repository") do
23
+ options[ :action ] = :list
21
24
  end
22
25
 
23
26
  opts.on("-p", "--path PATH", "The path to the local copy of the repository. Defaults to current directory") do | path |
@@ -25,12 +28,8 @@ OptionParser.new do | opts |
25
28
  end
26
29
 
27
30
  opts.on("-r", "--restore", "Restore system files from the repository") do
28
- options[ :restore ] = true
31
+ options[ :action ] = :restore
29
32
  end
30
33
  end.parse!
31
34
 
32
- conf = Git::Confident.new( options[ :path ] )
33
- conf.local_backup
34
- exit unless options[:commit]
35
- conf.commit
36
- conf.push
35
+ Git::Confident.new( options )
data/lib/git/confident.rb CHANGED
@@ -8,21 +8,48 @@ module Git
8
8
  module VERSION #:nodoc:
9
9
  MAJOR = 0
10
10
  MINOR = 0
11
- TINY = 4
11
+ TINY = 5
12
12
 
13
13
  STRING = [ MAJOR, MINOR, TINY ].join( '.' )
14
14
  end
15
15
 
16
- def initialize( path )
17
- raise "Git repository not found at '#{ path }'" if ! File.directory?( "#{ path }/.git" )
18
- @path = path.clone
16
+ def initialize( options )
17
+ @path = options[ :path ].clone
18
+ @no_commit = options[ :no_commit ] ? true : false
19
+
20
+ raise "Git repository not found at '#{ @path }'" if ! File.directory?( "#{ @path }/.git" )
21
+
19
22
  super( { :working_directory => @path } )
23
+
24
+ case options[ :action ]
25
+ when :backup
26
+ backup
27
+ when :list
28
+ puts files
29
+ when :restore
30
+ restore
31
+ end
20
32
  end
21
33
 
22
34
  def files
23
35
  ls_files.keys.sort
24
36
  end
25
37
 
38
+ private
39
+
40
+ def backup
41
+ local_backup
42
+ return if @no_commit
43
+ commit
44
+ push
45
+ end
46
+
47
+ def restore
48
+ IO.popen( "rsync --no-perms --executability --files-from=- #{ @path }/ /", "w+" ) do | pipe |
49
+ files.each { | pathname | pipe.puts pathname }
50
+ end
51
+ end
52
+
26
53
  def local_backup
27
54
  IO.popen( "rsync -av --files-from=- / #{ @path }/", "w+" ) do | pipe |
28
55
  files.each { | pathname | pipe.puts pathname }
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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joe Yates