r-git 1.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 05cbfe0454fe867f20f6416f11c9cea9513ac5e2
4
+ data.tar.gz: f8f7a31c05cd135b171bf4b2bfec17072a41b234
5
+ SHA512:
6
+ metadata.gz: 4dd8d49b6d9c1bdb4c00f2a283be89782acc578d3ddf7cc82d64a92142bb473a7c0034c8bfc0ea7663d792cf3329af38e3c094e0a3dc327e00fcca63ec24be9d
7
+ data.tar.gz: bbffe7fffe3af9dca193c7a27e3d8e5b898c730fa3f005b71c862ade457fe62abeb2bb58fdd1e19b250c8e485ed9f5d8d1dcaeabb6536b19a7491770fe5ddcaf
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ Documentation:
2
+ Enabled: false
3
+ Metrics/LineLength:
4
+ Max: 120
5
+ Metrics/MethodLength:
6
+ Max: 40
7
+ Metrics/AbcSize:
8
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rgit-git.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # r-git
2
+
3
+ r-git is an executable gem that assists with managing multiple git repositories. The current functionality allows you to perform the following actions on multiple repositories at once:
4
+ * Pull
5
+ * Checkout
6
+ * Fetch
7
+ * View the status
8
+
9
+ Imagine the scenario where you have several git projects under some parent:
10
+
11
+ └── personal-projects
12
+ ├── arbitary-sub-folder
13
+ │ ├── projectX (git repo)
14
+ │ ├── projectY (git repo)
15
+ └── r-git (git repo)
16
+ └── work-projects
17
+ ├── repo-one (git repo)
18
+ └── repo-two (git repo)
19
+
20
+
21
+ r-git has the concepts of 'roots' in our scenario `personal-projects` and `work-projects` are our roots. I register these by running the following from within each folder:
22
+
23
+ $ rgit --add-root
24
+
25
+ Running any of the following commands will result in that command being executed across all projects within the root:
26
+
27
+ * `rgit -s`
28
+ Status of all repositories
29
+ * `rgit -p`
30
+ Execute git pull on all repositories
31
+ * `rgit -f`
32
+ Execute git fetch on all repositories
33
+ * `rgit -c development`
34
+ Execute `git checkout development` on all repositories
35
+
36
+ For example: executing `rgit -f` from within any folder in `personal-projects` will run git fetch on all repositories in that folder/root.
37
+
38
+ It's that simple!
39
+
40
+ ## Installation
41
+ Install it yourself as:
42
+
43
+ $ gem install r-git
44
+
45
+ ## Usage
46
+ r-git is an executable gem with the following CLI options.
47
+
48
+ Usage: rgit [options]
49
+ --add-root [PATH] Add a root directory (defaults to pwd).
50
+ --remove-root [PATH] Remove a root directory (defaults to pwd).
51
+ --show-roots Show roots.
52
+ -p, --pull Git pull
53
+ -f, --fetch Git fetch
54
+ -c, --checkout BRANCH Git checkout
55
+ -s, --status Git status
56
+ -h, --help Show this message
57
+ --version Show version
58
+
59
+ See the main description for examples of how to use r-git
60
+
61
+ ## Development
62
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. `rubocop` can be run to inspec code style.
63
+
64
+ To install this gem onto your local machine, run `bundle exec rake install`.
65
+
66
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
67
+
68
+ ## Contributing
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jamesridgway/r-git.
70
+
71
+
72
+ ## License
73
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
74
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rgit'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/rgit ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rgit/rgit'
4
+ Rgit::Cli.parse(ARGV)
data/lib/rgit/cli.rb ADDED
@@ -0,0 +1,37 @@
1
+ module Rgit
2
+ class Cli
3
+ include Rgit
4
+ def self.parse(args, rgit = Rgit.new(Configuration.exist? ? Configuration.load : Configuration.create))
5
+ OptionParser.new do |opts|
6
+ opts.banner = 'Usage: rgit [options]'
7
+ opts.on('--add-root [PATH]', 'Add a root directory (defaults to pwd).') do |root_path|
8
+ rgit.add_root(root_path.nil? ? Dir.pwd : root_path)
9
+ end
10
+ opts.on('--remove-root [PATH]', 'Remove a root directory (defaults to pwd).') do |root_path|
11
+ rgit.remove_root(root_path.nil? ? Dir.pwd : root_path)
12
+ end
13
+ opts.on('--show-roots', 'Show roots.') do |root_path|
14
+ rgit.print_roots
15
+ end
16
+ opts.on('-p', '--pull', 'Git pull') do
17
+ rgit.pull
18
+ end
19
+ opts.on('-f', '--fetch', 'Git fetch') do
20
+ rgit.fetch
21
+ end
22
+ opts.on('-c', '--checkout BRANCH', 'Git checkout') do |branch|
23
+ rgit.checkout branch
24
+ end
25
+ opts.on('-s', '--status', 'Git status') do
26
+ rgit.status
27
+ end
28
+ opts.on_tail('-h', '--help', 'Show this message') do
29
+ puts opts
30
+ end
31
+ opts.on_tail('--version', 'Show version') do
32
+ puts VERSION
33
+ end
34
+ end.parse!(args)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,66 @@
1
+ require 'yaml'
2
+ require 'fileutils'
3
+
4
+ module Rgit
5
+ class Configuration
6
+ attr_reader :filename
7
+
8
+ def self.exist?(filename = File.join(Dir.home, '.rgit.yml'))
9
+ File.exist?(filename)
10
+ end
11
+
12
+ def self.create(filename = File.join(Dir.home, '.rgit.yml'))
13
+ FileUtils.touch(filename)
14
+ config = Configuration.new(filename)
15
+ config.save
16
+ config
17
+ end
18
+
19
+ def self.load(filename = File.join(Dir.home, '.rgit.yml'))
20
+ Configuration.new(filename)
21
+ end
22
+
23
+ def roots
24
+ @roots
25
+ end
26
+
27
+ def add_root(path)
28
+ raise '"/" path unsupported!' if path == '/'
29
+ @roots << path unless @roots.include? path
30
+ end
31
+
32
+ def remove_root(path)
33
+ @roots.delete path
34
+ end
35
+
36
+ def save
37
+ config = {
38
+ 'roots' => @roots
39
+ }
40
+ File.open(@filename, 'w') do |f|
41
+ f.write config.to_yaml
42
+ end
43
+ end
44
+
45
+ def find_root(path)
46
+ until @roots.include?(path)
47
+ path = File.expand_path('..', path)
48
+ raise 'Not in a root directory' if path == '/'
49
+ end
50
+ path
51
+ end
52
+
53
+ private
54
+
55
+ def initialize(filename)
56
+ @filename = filename
57
+ @roots = []
58
+
59
+ return if File.size(filename) == 0
60
+
61
+ yaml = YAML.load_file(filename)
62
+ @roots = yaml['roots']
63
+ end
64
+
65
+ end
66
+ end
data/lib/rgit/rgit.rb ADDED
@@ -0,0 +1,112 @@
1
+ require 'rgit/version'
2
+ require 'rgit/configuration'
3
+ require 'rgit/cli'
4
+ require 'optparse'
5
+ require 'git'
6
+ require 'colorize'
7
+ module Rgit
8
+ class Rgit
9
+
10
+ def initialize(config)
11
+ @config = config
12
+ end
13
+
14
+ def add_root(path)
15
+ raise "Not a directory: #{path}" unless File.directory?(path)
16
+ puts "Adding root: #{path}"
17
+ @config.add_root path
18
+ @config.save
19
+ end
20
+
21
+ def remove_root(path)
22
+ raise "Not a directory: #{path}" unless File.directory?(path)
23
+ puts "Removing root: #{path}"
24
+ @config.remove_root path
25
+ @config.save
26
+ end
27
+
28
+ def pull(path = Dir.pwd)
29
+ recursive_cmd(path) do |git|
30
+ git.remotes.each do | remote|
31
+ puts " Pulling remote: #{remote.name}".colorize(:light_cyan)
32
+ results = git.pull(remote.name, git.current_branch)
33
+ puts results.split("\n").map {|l| " #{l}"}.join("\n")
34
+ end
35
+ end
36
+ end
37
+
38
+ def fetch(path = Dir.pwd)
39
+ recursive_cmd(path) do |git|
40
+ git.remotes.each do | remote|
41
+ puts " Fetching remote: #{remote.name}".colorize(:light_cyan)
42
+ results = git.fetch(remote.name, all: true)
43
+ puts results.split("\n").map {|l| " #{l}"}.join("\n")
44
+ end
45
+ end
46
+ end
47
+
48
+ def checkout(branch, path = Dir.pwd)
49
+ recursive_cmd(path) do |git|
50
+ puts " Checkout branch: #{branch}".colorize(:light_cyan)
51
+ git.checkout branch
52
+ end
53
+ end
54
+
55
+ def status(path = Dir.pwd)
56
+ recursive_cmd(path) do |git|
57
+ unless git.status.untracked.empty?
58
+ puts " Untracked changes (#{git.current_branch}):".colorize(:light_red)
59
+ git.status.untracked.keys.each {|filename| puts " - #{filename}" }
60
+ end
61
+ unless git.status.changed.empty?
62
+ puts " Uncommitted changes (#{git.current_branch}):".colorize(:light_magenta)
63
+ git.status.changed.keys.each {|filename| puts " - #{filename}" }
64
+ end
65
+ if git.status.untracked.empty? && git.status.changed.empty?
66
+ puts " On branch: #{git.current_branch}".colorize(:green)
67
+ end
68
+ end
69
+ end
70
+
71
+ def print_roots
72
+ if @config.roots.empty?
73
+ puts "No roots have been configured. Run 'rgit --add-root' to add the current directory as a root"
74
+ else
75
+ puts 'Roots:'
76
+ @config.roots.each do |root|
77
+ puts " - #{root}"
78
+ end
79
+ end
80
+ end
81
+
82
+ private
83
+
84
+ def recursive_cmd(path, &block)
85
+ parent_path = @config.find_root(path)
86
+ repositories(parent_path).each do |git|
87
+ repo_name = git.dir.path.gsub("#{path}/", '')
88
+ puts "#{'Repository:'.colorize(:light_blue)} #{repo_name}"
89
+ begin
90
+ yield git
91
+ rescue Git::GitExecuteError => e
92
+ puts " Failed:".colorize(:red)
93
+ puts e.message.split("\n").map {|l| " #{l}"}.join("\n").colorize(:red)
94
+ end
95
+ end
96
+ end
97
+
98
+ def repositories(path)
99
+ git_repos = []
100
+ dirs = Dir.entries(path).select{ |entry| File.directory?(File.join(path, entry)) && !(entry == '.' || entry == '..') }.sort
101
+ dirs.each do |dir|
102
+ dir_path = File.join(path, dir)
103
+ if File.exist?(File.join(dir_path, '.git', 'config'))
104
+ git_repos << Git.open(dir_path)
105
+ else
106
+ git_repos.concat repositories(dir_path)
107
+ end
108
+ end
109
+ git_repos
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,3 @@
1
+ module Rgit
2
+ VERSION = '1.0.0'.freeze
3
+ end
data/r-git.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rgit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'r-git'
8
+ spec.version = Rgit::VERSION
9
+ spec.authors = ['James Ridgway']
10
+ spec.email = ['myself@james-ridgway.co.uk']
11
+
12
+ spec.summary = 'Executable gem for managing multiple git repositories in a top level directory.'
13
+ spec.description = 'Executable gem for managing multiple git repositories in a top level directory. rgit-git allow
14
+ you to easily fetch, pull, change branch, etc. across multiple git repositories with a single
15
+ command.'
16
+ spec.homepage = 'http://www.james-ridgway.co.uk'
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.11'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'rubocop', '~> 0.37'
28
+ spec.add_development_dependency 'simplecov', '~> 0.11'
29
+ spec.add_dependency 'git', '~> 1.2.9'
30
+ spec.add_dependency 'colorize', '~> 0.7.7'
31
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: r-git
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - James Ridgway
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.37'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.37'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.11'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.11'
83
+ - !ruby/object:Gem::Dependency
84
+ name: git
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.2.9
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.2.9
97
+ - !ruby/object:Gem::Dependency
98
+ name: colorize
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.7.7
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.7.7
111
+ description: |-
112
+ Executable gem for managing multiple git repositories in a top level directory. rgit-git allow
113
+ you to easily fetch, pull, change branch, etc. across multiple git repositories with a single
114
+ command.
115
+ email:
116
+ - myself@james-ridgway.co.uk
117
+ executables:
118
+ - rgit
119
+ extensions: []
120
+ extra_rdoc_files: []
121
+ files:
122
+ - ".gitignore"
123
+ - ".rspec"
124
+ - ".rubocop.yml"
125
+ - ".travis.yml"
126
+ - Gemfile
127
+ - LICENSE.txt
128
+ - README.md
129
+ - Rakefile
130
+ - bin/console
131
+ - bin/setup
132
+ - exe/rgit
133
+ - lib/rgit/cli.rb
134
+ - lib/rgit/configuration.rb
135
+ - lib/rgit/rgit.rb
136
+ - lib/rgit/version.rb
137
+ - r-git.gemspec
138
+ homepage: http://www.james-ridgway.co.uk
139
+ licenses:
140
+ - MIT
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.4.8
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: Executable gem for managing multiple git repositories in a top level directory.
162
+ test_files: []