update_repo 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/README.md +12 -2
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/bin/update_repo +6 -6
- data/exe/update_repo +5 -17
- data/lib/update_repo/version.rb +2 -1
- data/lib/update_repo.rb +123 -52
- data/update_repo.gemspec +11 -10
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c8f69a7896ee9033c3795a0f5fb64bdc4ad203b
|
4
|
+
data.tar.gz: 5e2d5e0e24ce6832a86c86aff898207dff696f46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eef4c5f91858e5122667332b6bde79ee23565fd93231c4e6af0ba7d9beba7b8fc28b8c229f4ad3a695f90b4456517909c94707b5174a6a9dcd4fcea3b6c56dd4
|
7
|
+
data.tar.gz: 3edc6e7429277294ddc163a541aa7ca9c85f606e15a78a5813e3ea49cf82bf40713c7f1e7e687bfbf6654a982659c41b840d5379648f10577e654fc5fed86be0
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
# update_repo
|
1
|
+
# update_repo [![Gem Version](https://badge.fury.io/rb/update_repo.svg)](https://badge.fury.io/rb/update_repo) [![Build Status](https://travis-ci.org/seapagan/update_repo.svg?branch=master)](https://travis-ci.org/seapagan/update_repo)
|
2
|
+
|
3
|
+
[![Dependency Status](https://gemnasium.com/seapagan/update_repo.svg)](https://gemnasium.com/seapagan/update_repo)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/seapagan/update_repo/badge.svg?branch=master&service=github)](https://coveralls.io/github/seapagan/update_repo?branch=master)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/seapagan/update_repo/badges/gpa.svg)](https://codeclimate.com/github/seapagan/update_repo)
|
6
|
+
[![Inline docs](http://inch-ci.org/github/seapagan/update_repo.svg?branch=master)](http://inch-ci.org/github/seapagan/update_repo)
|
7
|
+
[![PullReview stats](https://www.pullreview.com/github/seapagan/update_repo/badges/master.svg?)](https://www.pullreview.com/github/seapagan/update_repo/reviews/master)
|
2
8
|
|
3
9
|
A Simple Gem to keep multiple cloned Git Repositories up to date.
|
4
10
|
|
@@ -8,9 +14,10 @@ This is the conversion to a Gem of one of my standalone Ruby scripts. Still very
|
|
8
14
|
|
9
15
|
#### Pre-requirements
|
10
16
|
|
11
|
-
It goes without saying that at the very least a working copy of [Git][git]
|
17
|
+
It goes without saying that at the very least a working copy of both [`Git`][git] and [`Ruby`][ruby] need to be installed on your machine. Also, the script has only been tested under Linux, not windows.
|
12
18
|
|
13
19
|
[git]: http://git-scm.com
|
20
|
+
[ruby]: http://www.ruby-lang.org
|
14
21
|
|
15
22
|
#### Quick start
|
16
23
|
Create a [YAML](http://yaml.org/)-formatted configuration file `.updatereporc` **in your home directory** that contains at least a 'location' tag pointing to the directory containing the git repositories you wish to have updated :
|
@@ -40,6 +47,8 @@ To be added.
|
|
40
47
|
Not in any specific order :
|
41
48
|
|
42
49
|
- Improve error-checking and recovery while parsing the configuration file (convert to using my '[Confoog][confoog]' gem for example)
|
50
|
+
* Ignore and report invalid or missing directories
|
51
|
+
* Expand eg '~/' to full valid path.
|
43
52
|
- Either add an option 'variants' or similar to allow non-standard git pull commands (eg Ubuntu kernel), or update the 'exceptions' option to do same.
|
44
53
|
- Error checking and reporting for the git processes - retry for connection issues etc (config setting).
|
45
54
|
- Add extra (optional) stats / info at end-of-job :
|
@@ -55,6 +64,7 @@ Not in any specific order :
|
|
55
64
|
- Add flag for 'default' repo directory (or another specific directory - if it does not already exist it will be created and added to the standard list) which will be used for new additions.
|
56
65
|
- Option to save log file for each run.
|
57
66
|
- Add option to only display a (text) tree of the discovered git repositories, not updating them; Similar option to just dump a list of the remote git locations.
|
67
|
+
- Add ability to export a text dump of each repo location and then re-import this on a different machine or after reinstall
|
58
68
|
- Document configuration file format and options.
|
59
69
|
- Add testing!
|
60
70
|
|
data/Rakefile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
3
|
require 'rubocop/rake_task'
|
4
4
|
require 'inch/rake'
|
5
5
|
|
@@ -28,4 +28,4 @@ else
|
|
28
28
|
end
|
29
29
|
|
30
30
|
# task default: [:rubocop, :inch, :reek, :spec, :build]
|
31
|
-
task default: [ :spec, :build] # leave the others off
|
31
|
+
task default: [:rubocop, :inch, :spec, :build] # leave the others off for now.
|
data/bin/console
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'update_repo'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
9
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
require
|
10
|
+
require 'pry'
|
11
11
|
Pry.start
|
12
12
|
|
13
13
|
# require "irb"
|
data/bin/update_repo
CHANGED
@@ -6,11 +6,11 @@
|
|
6
6
|
# this file is here to facilitate running it.
|
7
7
|
#
|
8
8
|
|
9
|
-
require
|
10
|
-
ENV[
|
11
|
-
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
|
11
|
+
Pathname.new(__FILE__).realpath)
|
12
12
|
|
13
|
-
require
|
14
|
-
require
|
13
|
+
require 'rubygems'
|
14
|
+
require 'bundler/setup'
|
15
15
|
|
16
|
-
load Gem.bin_path(
|
16
|
+
load Gem.bin_path('update_repo', 'update_repo')
|
data/exe/update_repo
CHANGED
@@ -1,20 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
include UpdateRepo
|
3
|
+
require 'update_repo'
|
5
4
|
|
6
|
-
#
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
# save the current time
|
12
|
-
start_time = Time.now
|
13
|
-
configs['location'].each do |loc|
|
14
|
-
recurse_dir(loc, configs['exceptions'])
|
15
|
-
end
|
16
|
-
|
17
|
-
# get duration since we saved the time
|
18
|
-
duration = Time.now - start_time
|
19
|
-
|
20
|
-
puts "\nUpdates completed - #{$counter} repositories processed in #{Time.at(duration).utc.strftime("%H:%M:%S")}\n".underline
|
5
|
+
# create a new instance of the class...
|
6
|
+
walk_repo = UpdateRepo::WalkRepo.new
|
7
|
+
# then start the process...
|
8
|
+
walk_repo.start
|
data/lib/update_repo/version.rb
CHANGED
data/lib/update_repo.rb
CHANGED
@@ -1,73 +1,144 @@
|
|
1
|
-
require
|
1
|
+
require 'update_repo/version'
|
2
2
|
require 'yaml'
|
3
3
|
require 'colorize'
|
4
|
+
require 'update_repo/version'
|
4
5
|
|
6
|
+
# Overall module with classes performing the functionality
|
7
|
+
# Contains Class UpdateRepo::WalkRepo
|
5
8
|
module UpdateRepo
|
9
|
+
# This constant holds the name to the config file, located in ~/
|
10
|
+
CONFIG_FILE = '.updatereporc'.freeze
|
6
11
|
|
7
|
-
|
8
|
-
|
12
|
+
# An encapsulated class to walk the repo directories and update all Git
|
13
|
+
# repositories found therein.
|
14
|
+
class WalkRepo
|
15
|
+
# Read-only attribute holding the total number of traversed repositories
|
16
|
+
# @attr_reader :counter [fixnum] total number of traversed repositories
|
17
|
+
attr_reader :counter
|
9
18
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
# Class constructor. No parameters required.
|
20
|
+
# @return [void]
|
21
|
+
def initialize
|
22
|
+
@counter = 0
|
23
|
+
@start_time = 0
|
24
|
+
end
|
25
|
+
|
26
|
+
# This function will perform the required actions to traverse the Repo.
|
27
|
+
# @example
|
28
|
+
# walk_repo = UpdateRepo::WalkRepo.new
|
29
|
+
# walk_repo.start
|
30
|
+
def start
|
31
|
+
configs, location = check_config
|
32
|
+
show_header(configs, location)
|
33
|
+
configs['location'].each do |loc|
|
34
|
+
recurse_dir(loc, configs['exceptions'])
|
35
|
+
end
|
36
|
+
# print out an informative footer...
|
37
|
+
footer
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
# take each directory contained in the Repo directory, and if it is detected
|
43
|
+
# as a Git repository then update it.
|
44
|
+
# @param dirname [string] Contains the directory to search for Git repos.
|
45
|
+
# @param exceptions [array] Each repo matching one of these will be ignored.
|
46
|
+
def recurse_dir(dirname, exceptions)
|
47
|
+
Dir.foreach(dirname) do |dir|
|
48
|
+
dirpath = dirname + '/' + dir
|
49
|
+
next unless File.directory?(dirpath) && notdot?(dir)
|
50
|
+
if gitdir?(dirpath)
|
51
|
+
dir.chomp!
|
52
|
+
!exceptions.include?(dir) ? update_repo(dirpath) : skip_dir(dirpath)
|
25
53
|
else
|
26
54
|
recurse_dir(dirpath, exceptions)
|
27
55
|
end
|
28
56
|
end
|
29
57
|
end
|
30
|
-
end
|
31
58
|
|
32
|
-
|
33
|
-
#
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
59
|
+
# locate the configuration file and return this data.
|
60
|
+
# Note that this will be re-written later to use my 'confoog' gem.
|
61
|
+
# @return [hash] Hash containing all the configuration parameters.
|
62
|
+
# @return [string] Location of the configuration file.
|
63
|
+
def check_config
|
64
|
+
# locate the configuration file.
|
65
|
+
# first we check in this script location and if present then we ignore any
|
66
|
+
# further files.
|
67
|
+
dev_config = File.join '.', CONFIG_FILE
|
68
|
+
user_config = File.join Gem.user_home, CONFIG_FILE
|
69
|
+
|
70
|
+
if File.exist? dev_config
|
71
|
+
# configuration exists in script directory so we ignore any others.
|
72
|
+
return YAML.load_file(dev_config), File.expand_path(dev_config)
|
73
|
+
elsif File.exist? user_config
|
74
|
+
# configuration exists in user home directory so we use that.
|
75
|
+
return YAML.load_file(user_config), File.expand_path(user_config)
|
76
|
+
end
|
77
|
+
# otherwise return error
|
78
|
+
print 'Error : Cannot find configuration file'.red, user_config.red,
|
79
|
+
'aborting'.red
|
80
|
+
exit 1
|
39
81
|
end
|
40
|
-
|
41
|
-
|
82
|
+
|
83
|
+
# Display a simple header to the console
|
84
|
+
# @param configs [hash] Configuration hash, used here to list exceptions.
|
85
|
+
# @param location [string] location of config file.
|
86
|
+
# @example
|
87
|
+
# show_header
|
88
|
+
# @return []
|
89
|
+
def show_header(configs, location)
|
90
|
+
# print an informative header before starting
|
91
|
+
print "\nGit Repo update utility (v", VERSION, ')',
|
92
|
+
" \u00A9 Grant Ramsay <seapagan@gmail.com>\n"
|
93
|
+
print "Using Configuration from #{location}\n"
|
94
|
+
list_locations(configs)
|
95
|
+
if configs['exceptions']
|
96
|
+
print "\nExclusions:".underline, ' ',
|
97
|
+
configs['exceptions'].join(', ').yellow, "\n"
|
98
|
+
end
|
99
|
+
# save the start time for later display in the footer...
|
100
|
+
@start_time = Time.now
|
101
|
+
print "\n" # blank line before processing starts
|
42
102
|
end
|
43
|
-
puts # blank line before processing starts
|
44
|
-
end
|
45
103
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
print "
|
51
|
-
|
104
|
+
# print out a brief footer. This will be expanded later.
|
105
|
+
# @return [void]
|
106
|
+
def footer
|
107
|
+
duration = Time.now - @start_time
|
108
|
+
print "\nUpdates completed - #{@counter} repositories processed in ",
|
109
|
+
"#{Time.at(duration).utc.strftime('%H:%M:%S')}\n\n".cyan
|
110
|
+
end
|
111
|
+
|
112
|
+
def list_locations(configs)
|
113
|
+
print "\nRepo location(s):\n".underline
|
114
|
+
configs['location'].each do |loc|
|
115
|
+
print '-> ', loc.cyan, "\n"
|
116
|
+
end
|
52
117
|
end
|
53
|
-
end
|
54
118
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
119
|
+
def skip_dir(dirpath)
|
120
|
+
Dir.chdir(dirpath) do
|
121
|
+
repo_url = `git config remote.origin.url`.chomp
|
122
|
+
print "* Skipping #{dirpath}".yellow, " (#{repo_url})\n"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def update_repo(dirname)
|
127
|
+
Dir.chdir(dirname) do
|
128
|
+
repo_url = `git config remote.origin.url`.chomp
|
129
|
+
print '* ', 'Checking ', dirname.green, " (#{repo_url})\n", ' -> '
|
130
|
+
system 'git pull'
|
131
|
+
@counter += 1
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def gitdir?(dirpath)
|
136
|
+
gitpath = dirpath + '/.git'
|
137
|
+
File.exist?(gitpath) && File.directory?(gitpath)
|
138
|
+
end
|
61
139
|
|
62
|
-
|
63
|
-
|
64
|
-
return YAML.load_file(dev_config), File.expand_path(dev_config)
|
65
|
-
elsif File.exist? user_config
|
66
|
-
# configuration exists in user home directory so we use that.
|
67
|
-
return YAML.load_file(user_config), File.expand_path(user_config)
|
140
|
+
def notdot?(dir)
|
141
|
+
(dir != '.' && dir != '..')
|
68
142
|
end
|
69
|
-
# otherwise return error
|
70
|
-
puts "Error : Cannot find configuration file '#{user_config}', aborting".red
|
71
|
-
exit 1
|
72
143
|
end
|
73
144
|
end
|
data/update_repo.gemspec
CHANGED
@@ -5,24 +5,24 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
require 'update_repo/version'
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name =
|
8
|
+
spec.name = 'update_repo'
|
9
9
|
spec.version = UpdateRepo::VERSION
|
10
10
|
spec.required_ruby_version = '>= 1.9.3'
|
11
|
-
spec.authors = [
|
12
|
-
spec.email = [
|
11
|
+
spec.authors = ['Grant Ramsay']
|
12
|
+
spec.email = ['seapagan@gmail.com']
|
13
13
|
|
14
14
|
spec.summary = 'A Simple Gem to keep multiple cloned Git Repositories up to date'
|
15
|
-
spec.homepage =
|
16
|
-
spec.license =
|
15
|
+
spec.homepage = 'http://opensource.seapagan.net'
|
16
|
+
spec.license = 'MIT'
|
17
17
|
|
18
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
-
spec.bindir =
|
19
|
+
spec.bindir = 'exe'
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
-
spec.require_paths = [
|
21
|
+
spec.require_paths = ['lib']
|
22
22
|
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
26
|
spec.add_development_dependency 'pry'
|
27
27
|
spec.add_development_dependency 'fakefs'
|
28
28
|
spec.add_development_dependency 'coveralls'
|
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency 'simplecov', '~> 0.10'
|
32
32
|
spec.add_development_dependency 'pullreview-coverage'
|
33
33
|
spec.add_development_dependency 'should_not'
|
34
|
+
spec.add_development_dependency 'wwtd'
|
34
35
|
|
35
36
|
spec.add_dependency 'colorize'
|
36
37
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: update_repo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grant Ramsay
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: wwtd
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
167
181
|
- !ruby/object:Gem::Dependency
|
168
182
|
name: colorize
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|