gitback 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,21 +1,7 @@
1
- ## MAC OS
2
1
  .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
2
  *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
3
+ *.gem
4
+ .bundle
5
+ Gemfile.lock
6
+ pkg/*
7
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # dependencies are specified in gitback.gemspec
4
+ gemspec
data/README.md CHANGED
@@ -1,24 +1,26 @@
1
1
  Gitback
2
2
  ====
3
3
 
4
+ Do you have backups of your production web/mail/db configs? crontabs?
5
+
6
+ How fast could you configure a production machine if everything was lost?
7
+
4
8
  Gitback allows you to version arbitrary files and/or directories in a git
5
9
  repository. You just need to include the gem and write a brief ruby script
6
10
  that indicates the files/directories you'd like to backup. Then, run the
7
11
  script via cron. Gitback will take care of a adding/commiting/pushing whenever
8
12
  your files are modified.
9
13
 
10
- The typical usage for this is backing up config files.
11
-
12
14
 
13
15
  ## Requirements ###############################################################
14
16
 
15
- * git (http://git-scm.com) tested with 1.6.0.4
16
- * grit (http://github.com/mojombo/grit) 2.0.0 or higher
17
+ * git (http://git-scm.com) tested with 1.7.4
18
+ * grit (http://github.com/mojombo/grit) tested with 2.4.1
17
19
 
18
20
 
19
21
  ## Install ####################################################################
20
22
 
21
- $ gem install gitback -s http://gemcutter.org
23
+ $ gem install gitback
22
24
 
23
25
  ## Usage ######################################################################
24
26
 
@@ -29,32 +31,21 @@ Here's a basic example of a script using gitback:
29
31
 
30
32
  Gitback::Repository.new '/var/config-backup/' do |repo|
31
33
  repo.backup '/opt/nginx/conf/nginx.conf'
34
+ repo.backup '/etc/mysql/'
35
+ repo.backup '/etc/memcached.conf'
36
+ repo.backup '/etc/ssh/sshd_config'
37
+ repo.backup '/var/spool/cron/crontabs/'
32
38
  end
33
39
 
34
- This will check /opt/nginx/conf/nginx.conf for changes. If the file has
35
- changed, gitback will commit a new version.
40
+ This will check these files for additions/changes. If a file has been added or
41
+ changed, gitback will commit it.
36
42
 
37
- This nginx config file would be saved to the following location:
43
+ For example, the nginx config file would be saved to the following location:
38
44
 
39
45
  /var/config-backup/opt/nginx/conf/nginx.conf
40
46
 
41
- Everything starts with instantiating a new `Gitback::Repository` object. The
42
- first parameter is the path to the git repository you'd like to backup to. The
43
- second parameter is a block indicating the files/directories you'd like to
44
- backup.
45
-
46
-
47
- ### Directory support
48
-
49
- In addition to basic files, directory paths can also be backed up:
50
-
51
- Gitback::Repository.new '/var/config-backup/' do |repo|
52
- repo.backup '/opt/nginx/conf/nginx.conf'
53
- repo.backup '/etc/mysql/'
54
- end
55
-
56
- Notice that '/etc/mysql' is a directory. Gitback will copy everything within
57
- that directory into the git repository.
47
+ Notice that '/etc/mysql' is a directory. Gitback accepts directories and will
48
+ copy everything within that directory into the git repository.
58
49
 
59
50
 
60
51
  ### Namespaces
data/Rakefile CHANGED
@@ -1,46 +1,2 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "gitback"
8
- gem.summary = %Q{A simple ruby library for backing up files to git}
9
- gem.description = %Q{Provide a list of files and/or directories and gitback will copy them to your git repo, commit and push when there are changes.}
10
- gem.email = "brycethornton@gmail.com"
11
- gem.homepage = "http://github.com/brycethornton/gitback"
12
- gem.authors = ["Bryce Thornton"]
13
- gem.add_dependency "grit", ">= 2.0.0"
14
- gem.add_development_dependency "shoulda"
15
- end
16
- Jeweler::GemcutterTasks.new
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
- end
20
-
21
- begin
22
- require 'rcov/rcovtask'
23
- Rcov::RcovTask.new do |test|
24
- test.libs << 'test'
25
- test.pattern = 'test/**/test_*.rb'
26
- test.verbose = true
27
- end
28
- rescue LoadError
29
- task :rcov do
30
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
31
- end
32
- end
33
-
34
- task :test => :check_dependencies
35
-
36
- task :default => :test
37
-
38
- require 'rake/rdoctask'
39
- Rake::RDocTask.new do |rdoc|
40
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
-
42
- rdoc.rdoc_dir = 'rdoc'
43
- rdoc.title = "gitback #{version}"
44
- rdoc.rdoc_files.include('README*')
45
- rdoc.rdoc_files.include('lib/**/*.rb')
46
- end
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/gitback.gemspec CHANGED
@@ -1,67 +1,24 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "gitback/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{gitback}
8
- s.version = "0.1.1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Bryce Thornton"]
12
- s.date = %q{2010-05-20}
13
- s.description = %q{Provide a list of files and/or directories and gitback will copy them to your git repo, commit and push when there are changes.}
14
- s.email = %q{brycethornton@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.md"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.md",
24
- "Rakefile",
25
- "VERSION",
26
- "gitback.gemspec",
27
- "lib/gitback.rb",
28
- "lib/gitback/repository.rb",
29
- "test/data/another/file.txt",
30
- "test/data/another/test.txt",
31
- "test/data/some/deep/.bash_profile",
32
- "test/data/some/deep/directory/fstab",
33
- "test/data/some/deep/directory/test.conf",
34
- "test/data/some/deep/nginx.conf",
35
- "test/data/some/test_file.txt",
36
- "test/data/testing.txt",
37
- "test/helper.rb",
38
- "test/repos/.gitignore",
39
- "test/test_gitback.rb"
40
- ]
41
- s.homepage = %q{http://github.com/brycethornton/gitback}
42
- s.rdoc_options = ["--charset=UTF-8"]
43
- s.require_paths = ["lib"]
44
- s.rubygems_version = %q{1.3.7}
6
+ s.name = "gitback"
7
+ s.version = Gitback::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Bryce Thornton"]
10
+ s.email = ["brycethornton@gmail.com"]
11
+ s.homepage = "http://github.com/brycethornton/gitback"
45
12
  s.summary = %q{A simple ruby library for backing up files to git}
46
- s.test_files = [
47
- "test/helper.rb",
48
- "test/test_gitback.rb"
49
- ]
13
+ s.description = %q{Provide a list of files and/or directories and gitback will copy them to your git repo, commit and push when there are changes.}
14
+
15
+ s.add_dependency "grit", ">= 2.4.1"
50
16
 
51
- if s.respond_to? :specification_version then
52
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
- s.specification_version = 3
17
+ s.rubyforge_project = "gitback"
54
18
 
55
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
- s.add_runtime_dependency(%q<grit>, [">= 2.0.0"])
57
- s.add_development_dependency(%q<shoulda>, [">= 0"])
58
- else
59
- s.add_dependency(%q<grit>, [">= 2.0.0"])
60
- s.add_dependency(%q<shoulda>, [">= 0"])
61
- end
62
- else
63
- s.add_dependency(%q<grit>, [">= 2.0.0"])
64
- s.add_dependency(%q<shoulda>, [">= 0"])
65
- end
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
66
23
  end
67
24
 
@@ -95,7 +95,7 @@ module Gitback
95
95
  if commit_result !~ /working directory clean/
96
96
  if @remote
97
97
  puts "Pushing repository changes..."
98
- @repo.git.push({}, @remote, @branch)
98
+ @repo.git.native(:push, {}, @remote, @branch)
99
99
  end
100
100
  else
101
101
  puts "No changes committed."
@@ -0,0 +1,3 @@
1
+ module Gitback
2
+ VERSION = "0.1.2"
3
+ end
data/test/helper.rb CHANGED
@@ -1,10 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
- require 'shoulda'
4
3
 
5
4
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
6
  require 'gitback'
8
-
9
- class Test::Unit::TestCase
10
- end
data/test/test_gitback.rb CHANGED
@@ -1,114 +1,118 @@
1
1
  require "#{File.dirname(__FILE__)}/helper"
2
2
 
3
3
  class TestGitback < Test::Unit::TestCase
4
- context 'Gitback' do
5
- setup do
6
- @dirname = File.expand_path(File.dirname(__FILE__))
7
- @remote_path = File.expand_path(File.join(@dirname, *%w[repos remote_repo]))
8
- @local_path = File.expand_path(File.join(@dirname, *%w[repos local_repo]))
9
-
10
- # Cleanup the "remote" repo from previous tests
11
- if File.exists?(@remote_path)
12
- FileUtils.remove_dir(@remote_path)
13
- end
4
+ def setup
5
+ @dirname = File.expand_path(File.dirname(__FILE__))
6
+ @remote_path = File.expand_path(File.join(@dirname, *%w[repos remote_repo]))
7
+ @local_path = File.expand_path(File.join(@dirname, *%w[repos local_repo]))
14
8
 
15
- # Cleanup the "local" repo from previous tests
16
- if File.exists?(@local_path)
17
- FileUtils.remove_dir(@local_path)
18
- end
9
+ # Create the "remote" repo directory
10
+ FileUtils.mkdir_p(@remote_path)
19
11
 
20
- # Create the "remote" repo directory
21
- FileUtils.mkdir_p(@remote_path)
12
+ Dir.chdir(@remote_path) do
13
+ # Init the "remote" git repo and make first commit
14
+ `git init`
15
+ # By default, git won't let you push to a non-bare repo
16
+ # This config setting says to ignore that restriction
17
+ `git config receive.denyCurrentBranch ignore`
18
+ `touch README`
19
+
20
+ @remote_repo = Grit::Repo.new(@remote_path)
21
+ @remote_repo.add(@remote_path + '/*')
22
+ @remote_repo.commit_all("first commit")
23
+ end
22
24
 
23
- Dir.chdir(@remote_path) do
24
- # Init the "remote" git repo and make first commit
25
- `git init`
26
- `touch README`
25
+ # Clone the "remote" repo to a "local" repo
26
+ `git clone #{@remote_path} #{@local_path}`
27
+ end
27
28
 
28
- @remote_repo = Grit::Repo.new(@remote_path)
29
- @remote_repo.add(@remote_path + '/*')
30
- @remote_repo.commit_all("first commit")
31
- end
29
+ def teardown
30
+ # Cleanup the "remote" repo from previous tests
31
+ if File.exists?(@remote_path)
32
+ FileUtils.remove_dir(@remote_path)
33
+ end
32
34
 
33
- # Clone the "remote" repo to a "local" repo
34
- `git clone #{@remote_path} #{@local_path}`
35
+ # Cleanup the "local" repo from previous tests
36
+ if File.exists?(@local_path)
37
+ FileUtils.remove_dir(@local_path)
35
38
  end
39
+ end
36
40
 
37
- should "handle basic file backups" do
38
- files = []
39
- files << "#{@dirname}/data/testing.txt"
40
- files << "#{@dirname}/data/some/deep/nginx.conf"
41
+ def test_handle_basic_file_backups
42
+ files = []
43
+ files << "#{@dirname}/data/testing.txt"
44
+ files << "#{@dirname}/data/some/deep/nginx.conf"
41
45
 
42
- output = Gitback::Repository.new @local_path do |repo|
43
- files.each do |file|
44
- repo.backup file
45
- end
46
+ output = Gitback::Repository.new @local_path do |repo|
47
+ files.each do |file|
48
+ repo.backup file
46
49
  end
50
+ end
47
51
 
48
- assert_files(files)
52
+ assert_files(files)
53
+ end
54
+
55
+ def test_handle_directory_backups
56
+ output = Gitback::Repository.new @local_path do |repo|
57
+ repo.backup "#{@dirname}/data/another/"
58
+ repo.backup "#{@dirname}/data/some/deep/nginx.conf"
49
59
  end
50
60
 
51
- should "handle directory backups" do
52
- output = Gitback::Repository.new @local_path do |repo|
61
+ files = []
62
+ files << "#{@dirname}/data/another/file.txt"
63
+ files << "#{@dirname}/data/another/test.txt"
64
+ files << "#{@dirname}/data/some/deep/nginx.conf"
65
+
66
+ assert_files(files)
67
+ end
68
+
69
+ def test_use_namespaces
70
+ output = Gitback::Repository.new @local_path do |repo|
71
+ repo.namespace 'blah.domain.com' do
53
72
  repo.backup "#{@dirname}/data/another/"
54
73
  repo.backup "#{@dirname}/data/some/deep/nginx.conf"
55
74
  end
56
-
57
- files = []
58
- files << "#{@dirname}/data/another/file.txt"
59
- files << "#{@dirname}/data/another/test.txt"
60
- files << "#{@dirname}/data/some/deep/nginx.conf"
61
-
62
- assert_files(files)
63
75
  end
64
76
 
65
- should "use namespaces" do
66
- output = Gitback::Repository.new @local_path do |repo|
67
- repo.namespace 'blah.domain.com' do
68
- repo.backup "#{@dirname}/data/another/"
69
- repo.backup "#{@dirname}/data/some/deep/nginx.conf"
70
- end
71
- end
72
-
73
- # Make sure local repo has the files
74
- files = []
75
- files << "blah.domain.com/#{@dirname}/data/another/file.txt"
76
- files << "blah.domain.com/#{@dirname}/data/another/test.txt"
77
- files << "blah.domain.com/#{@dirname}/data/some/deep/nginx.conf"
77
+ # Make sure local repo has the files
78
+ files = []
79
+ files << "/blah.domain.com#{@dirname}/data/another/file.txt"
80
+ files << "/blah.domain.com#{@dirname}/data/another/test.txt"
81
+ files << "/blah.domain.com#{@dirname}/data/some/deep/nginx.conf"
78
82
 
79
- assert_files(files)
80
- end
83
+ assert_files(files)
84
+ end
81
85
 
82
- should "deal with symlinks" do
83
- # Create a symlink
84
- linked_file = "#{@dirname}/data/linked.txt"
85
- File.symlink("#{@dirname}/data/testing.txt", linked_file)
86
+ def test_deal_with_symlinks
87
+ # Create a symlink
88
+ linked_file = "#{@dirname}/data/linked.txt"
89
+ File.symlink("#{@dirname}/data/testing.txt", linked_file)
86
90
 
87
- Gitback::Repository.new @local_path do |repo|
88
- repo.backup linked_file
89
- end
91
+ Gitback::Repository.new @local_path do |repo|
92
+ repo.backup linked_file
93
+ end
90
94
 
91
- files = [linked_file]
95
+ files = [linked_file]
92
96
 
93
- assert_files(files)
97
+ assert_files(files)
94
98
 
95
- # Delete the link for future tests
96
- File.delete(linked_file)
97
- end
99
+ # Delete the link for future tests
100
+ File.delete(linked_file)
98
101
  end
99
102
 
100
103
  def assert_files(file_array)
101
104
  file_array.each do |file|
102
- assert File.exists? "#{@local_path}/#{file}"
105
+ assert File.exists?("#{@local_path}#{file}"), "Couldn't find #{@local_path}#{file}"
103
106
  end
104
107
 
105
- # Need to reset in order for the files to not be deleted
108
+ # Need to reset in order for the files to show up in the remote
109
+ # Normally we'd be pushing to a bare repo, but for testing we aren't
106
110
  Dir.chdir(@remote_path) do
107
111
  `git reset --hard`
108
112
  end
109
113
 
110
114
  file_array.each do |file|
111
- assert File.exists? "#{@remote_path}/#{file}"
115
+ assert File.exists?("#{@remote_path}#{file}"), "Couldn't find #{@remote_path}#{file}"
112
116
  end
113
117
  end
114
118
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitback
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
4
+ hash: 31
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bryce Thornton
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-20 00:00:00 -04:00
18
+ date: 2011-04-18 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,47 +26,33 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 15
29
+ hash: 29
30
30
  segments:
31
31
  - 2
32
- - 0
33
- - 0
34
- version: 2.0.0
32
+ - 4
33
+ - 1
34
+ version: 2.4.1
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: shoulda
39
- prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
49
- type: :development
50
- version_requirements: *id002
51
37
  description: Provide a list of files and/or directories and gitback will copy them to your git repo, commit and push when there are changes.
52
- email: brycethornton@gmail.com
38
+ email:
39
+ - brycethornton@gmail.com
53
40
  executables: []
54
41
 
55
42
  extensions: []
56
43
 
57
- extra_rdoc_files:
58
- - LICENSE
59
- - README.md
44
+ extra_rdoc_files: []
45
+
60
46
  files:
61
- - .document
62
47
  - .gitignore
48
+ - Gemfile
63
49
  - LICENSE
64
50
  - README.md
65
51
  - Rakefile
66
- - VERSION
67
52
  - gitback.gemspec
68
53
  - lib/gitback.rb
69
54
  - lib/gitback/repository.rb
55
+ - lib/gitback/version.rb
70
56
  - test/data/another/file.txt
71
57
  - test/data/another/test.txt
72
58
  - test/data/some/deep/.bash_profile
@@ -83,8 +69,8 @@ homepage: http://github.com/brycethornton/gitback
83
69
  licenses: []
84
70
 
85
71
  post_install_message:
86
- rdoc_options:
87
- - --charset=UTF-8
72
+ rdoc_options: []
73
+
88
74
  require_paths:
89
75
  - lib
90
76
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -107,11 +93,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
93
  version: "0"
108
94
  requirements: []
109
95
 
110
- rubyforge_project:
111
- rubygems_version: 1.3.7
96
+ rubyforge_project: gitback
97
+ rubygems_version: 1.6.2
112
98
  signing_key:
113
99
  specification_version: 3
114
100
  summary: A simple ruby library for backing up files to git
115
101
  test_files:
102
+ - test/data/another/file.txt
103
+ - test/data/another/test.txt
104
+ - test/data/some/deep/.bash_profile
105
+ - test/data/some/deep/directory/fstab
106
+ - test/data/some/deep/directory/test.conf
107
+ - test/data/some/deep/nginx.conf
108
+ - test/data/some/test_file.txt
109
+ - test/data/testing.txt
116
110
  - test/helper.rb
111
+ - test/repos/.gitignore
117
112
  - test/test_gitback.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.1