r-git 1.0.2 → 1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d592d0c13788f1e5ff4d480b64f43999ca745780
4
- data.tar.gz: 1c7fd8337e4a1fcd5e7dd9b5810b85bf61e2f75b
3
+ metadata.gz: 9b9b8b71821185add335a94f2b6cb8b36a54b769
4
+ data.tar.gz: 0fedb11778194aebeb7ea22d62aad4e04975f848
5
5
  SHA512:
6
- metadata.gz: 2ae58d99104c230e97b8899fd87e479b18a7cddb0af55eeada000b24e84004267ea671a97b929ec3a78f5031e56c6dd087a808d476dfebd656dca02ad1f0c048
7
- data.tar.gz: 68ad0f950a3644e208fc4d55d8497a26c152da42cfa958f7777dc0ebf790c606dc0c30aeda379951f194528798de58c9002d21f104210c4dfe3f3ee081189c11
6
+ metadata.gz: a39436aa0aa0c0d786ddc8955c53e884cc489360b79d5248dac56195382c9a520fde0bde227f6ccd0008736decf0fede53a15eb290ad85184fb7e30a5fd9ab3e
7
+ data.tar.gz: 620463392c4514f91755e129271aa92cadfc5b4a0c540077f12fe377521b143c5187f1c6d6c21f338da51a94ec8bb82c3350ec60b724328a72932a1274665532
data/.codeclimate.yml ADDED
@@ -0,0 +1,25 @@
1
+ ---
2
+ engines:
3
+ duplication:
4
+ enabled: true
5
+ config:
6
+ languages:
7
+ - ruby
8
+ - javascript
9
+ - python
10
+ - php
11
+ fixme:
12
+ enabled: true
13
+ rubocop:
14
+ enabled: true
15
+ ratings:
16
+ paths:
17
+ - "**.inc"
18
+ - "**.js"
19
+ - "**.jsx"
20
+ - "**.module"
21
+ - "**.php"
22
+ - "**.py"
23
+ - "**.rb"
24
+ exclude_paths:
25
+ - spec/
data/.rubocop.yml CHANGED
@@ -1,8 +1,17 @@
1
+ CaseIndentation:
2
+ IndentWhenRelativeTo: case
3
+ IndentOneStep: true
1
4
  Documentation:
2
5
  Enabled: false
6
+ Metrics/AbcSize:
7
+ Enabled: false
8
+ Metrics/CyclomaticComplexity:
9
+ Exclude:
10
+ - lib/rgit/cli.rb
3
11
  Metrics/LineLength:
4
12
  Max: 120
5
13
  Metrics/MethodLength:
6
14
  Max: 40
7
- Metrics/AbcSize:
8
- Enabled: false
15
+ Metrics/PerceivedComplexity:
16
+ Exclude:
17
+ - lib/rgit/cli.rb
data/.travis.yml CHANGED
@@ -2,3 +2,6 @@ language: ruby
2
2
  rvm:
3
3
  - 2.2.1
4
4
  before_install: gem install bundler -v 1.11.2
5
+ addons:
6
+ code_climate:
7
+ repo_token: "2ab359df06f020c1cba2747bcf9fb9a6fbec7788f039e4c521fc15e2dbf22d55"
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ ## Change Log
2
+
3
+ ### 1.1
4
+ * Added travis configuration
5
+ * Added code climate configuration
6
+ * Increased test coverage and code quality
7
+ * Moved to sub-commands
8
+ ### 1.0.2
9
+ * Initial Version
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 TODO: Write your name
3
+ Copyright (c) 2016 James Ridgway
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # r-git
2
2
 
3
+ [![Build Status](https://travis-ci.org/jamesridgway/r-git.svg?branch=master)](https://travis-ci.org/jamesridgway/r-git)
4
+ [![Code Climate](https://codeclimate.com/github/jamesridgway/r-git/badges/gpa.svg)](https://codeclimate.com/github/jamesridgway/r-git)
5
+ [![Test Coverage](https://codeclimate.com/github/jamesridgway/r-git/badges/coverage.svg)](https://codeclimate.com/github/jamesridgway/r-git/coverage)
6
+
3
7
  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
8
  * Pull
5
9
  * Checkout
@@ -20,27 +24,27 @@ Imagine the scenario where you have several git projects under some parent:
20
24
 
21
25
  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
26
 
23
- $ rgit --add-root
27
+ $ rgit add-root
24
28
 
25
29
  Running any of the following commands will result in that command being executed across all projects within the root:
26
30
 
27
- * `rgit -s`
31
+ * `rgit status`
28
32
 
29
33
  Status of all repositories
30
34
 
31
- * `rgit -p`
35
+ * `rgit pull`
32
36
 
33
37
  Execute git pull on all repositories
34
38
 
35
- * `rgit -f`
39
+ * `rgit fetch`
36
40
 
37
41
  Execute git fetch on all repositories
38
42
 
39
- * `rgit -c development`
43
+ * `rgit checkout development`
40
44
 
41
45
  Execute `git checkout development` on all repositories
42
46
 
43
- For example: executing `rgit -f` from within any folder in `personal-projects` will run git fetch on all repositories in that folder/root.
47
+ For example: executing `rgit fetch` from within any folder in `personal-projects` will run git fetch on all repositories in that folder/root.
44
48
 
45
49
  It's that simple!
46
50
 
@@ -52,16 +56,22 @@ Install it yourself as:
52
56
  ## Usage
53
57
  r-git is an executable gem with the following CLI options.
54
58
 
55
- Usage: rgit [options]
56
- --add-root [PATH] Add a root directory (defaults to pwd).
57
- --remove-root [PATH] Remove a root directory (defaults to pwd).
58
- --show-roots Show roots.
59
- -p, --pull Git pull
60
- -f, --fetch Git fetch
61
- -c, --checkout BRANCH Git checkout
62
- -s, --status Git status
63
- -h, --help Show this message
64
- --version Show version
59
+ USAGE:
60
+ rgit [global options] COMMAND [command options]
61
+
62
+ GLOBAL OPTIONS:
63
+ -v Run verbosely
64
+
65
+ COMMANDS:
66
+ add-root [PATH] Add a root directory (defaults to pwd).
67
+ remove-root [PATH] Remove a root directory (defaults to pwd).
68
+ show-roots Show roots.
69
+ pull Git pull
70
+ fetch Git fetch
71
+ checkout BRANCH Git checkout
72
+ status Git status
73
+ -h, --help Show this message
74
+ version Show version
65
75
 
66
76
  See the main description for examples of how to use r-git
67
77
 
data/lib/rgit/cli.rb CHANGED
@@ -1,37 +1,49 @@
1
+ require 'trollop'
2
+
1
3
  module Rgit
2
4
  class Cli
3
5
  include Rgit
6
+
7
+ SUB_COMMANDS = %w(add-root remove-root show-roots checkout pull fetch status version).freeze
8
+
4
9
  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|
10
+ global_opts = Trollop.options(args) do
11
+ banner 'rgit is a utility for managing multiple git repositories'
12
+ opt :verbose, 'Run verbosely', short: '-v'
13
+ stop_on SUB_COMMANDS
14
+ end
15
+
16
+ rgit.verbose = global_opts[:verbose]
17
+
18
+ cmd = args.shift
19
+ case cmd
20
+ when 'add-root'
21
+ path = args.size == 1 ? args[0] : Dir.pwd
22
+ rgit.add_root(path)
23
+ when 'remove-root'
24
+ path = args.size == 1 ? args[0] : Dir.pwd
25
+ rgit.remove_root(path)
26
+ when 'checkout'
27
+ branch = args[0] if args.size == 1
28
+ unless branch
29
+ puts 'ERROR: checkout subcommand expects a branch name'.red
30
+ return
31
+ end
32
+ rgit.checkout branch
33
+ when 'show-root'
14
34
  rgit.print_roots
15
- end
16
- opts.on('-p', '--pull', 'Git pull') do
35
+ when 'pull'
17
36
  rgit.pull
18
- end
19
- opts.on('-f', '--fetch', 'Git fetch') do
37
+ when 'fetch'
20
38
  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
39
+ when 'status'
26
40
  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)
41
+ when 'version'
42
+ puts "rgit #{VERSION}"
43
+ else
44
+ puts "ERROR: unknown subcommand #{cmd}".red
45
+ return
46
+ end
35
47
  end
36
48
  end
37
49
  end
@@ -3,7 +3,7 @@ require 'fileutils'
3
3
 
4
4
  module Rgit
5
5
  class Configuration
6
- attr_reader :filename
6
+ attr_reader :filename, :roots
7
7
 
8
8
  def self.exist?(filename = File.join(Dir.home, '.rgit.yml'))
9
9
  File.exist?(filename)
@@ -20,10 +20,6 @@ module Rgit
20
20
  Configuration.new(filename)
21
21
  end
22
22
 
23
- def roots
24
- @roots
25
- end
26
-
27
23
  def add_root(path)
28
24
  raise '"/" path unsupported!' if path == '/'
29
25
  @roots << path unless @roots.include? path
@@ -34,9 +30,7 @@ module Rgit
34
30
  end
35
31
 
36
32
  def save
37
- config = {
38
- 'roots' => @roots
39
- }
33
+ config = { 'roots' => @roots }
40
34
  File.open(@filename, 'w') do |f|
41
35
  f.write config.to_yaml
42
36
  end
@@ -56,11 +50,10 @@ module Rgit
56
50
  @filename = filename
57
51
  @roots = []
58
52
 
59
- return if File.size(filename) == 0
53
+ return if File.size(filename).zero?
60
54
 
61
55
  yaml = YAML.load_file(filename)
62
56
  @roots = yaml['roots']
63
57
  end
64
-
65
58
  end
66
59
  end
data/lib/rgit/rgit.rb CHANGED
@@ -6,9 +6,11 @@ require 'git'
6
6
  require 'colorize'
7
7
  module Rgit
8
8
  class Rgit
9
+ attr_accessor :verbose
9
10
 
10
11
  def initialize(config)
11
12
  @config = config
13
+ @verbose = false
12
14
  end
13
15
 
14
16
  def add_root(path)
@@ -27,20 +29,20 @@ module Rgit
27
29
 
28
30
  def pull(path = Dir.pwd)
29
31
  recursive_cmd(path) do |git|
30
- git.remotes.each do | remote|
32
+ git.remotes.each do |remote|
31
33
  puts " Pulling remote: #{remote.name}".colorize(:light_cyan)
32
34
  results = git.pull(remote.name, git.current_branch)
33
- puts results.split("\n").map {|l| " #{l}"}.join("\n")
35
+ puts results.split("\n").map { |l| " #{l}" }.join("\n") if @verbose
34
36
  end
35
37
  end
36
38
  end
37
39
 
38
40
  def fetch(path = Dir.pwd)
39
41
  recursive_cmd(path) do |git|
40
- git.remotes.each do | remote|
42
+ git.remotes.each do |remote|
41
43
  puts " Fetching remote: #{remote.name}".colorize(:light_cyan)
42
44
  results = git.fetch(remote.name, all: true)
43
- puts results.split("\n").map {|l| " #{l}"}.join("\n")
45
+ puts results.split("\n").map { |l| " #{l}" }.join("\n") if @verbose
44
46
  end
45
47
  end
46
48
  end
@@ -56,11 +58,11 @@ module Rgit
56
58
  recursive_cmd(path) do |git|
57
59
  unless git.status.untracked.empty?
58
60
  puts " Untracked changes (#{git.current_branch}):".colorize(:light_red)
59
- git.status.untracked.keys.each {|filename| puts " - #{filename}" }
61
+ git.status.untracked.keys.each { |filename| puts " - #{filename}" }
60
62
  end
61
63
  unless git.status.changed.empty?
62
64
  puts " Uncommitted changes (#{git.current_branch}):".colorize(:light_magenta)
63
- git.status.changed.keys.each {|filename| puts " - #{filename}" }
65
+ git.status.changed.keys.each { |filename| puts " - #{filename}" }
64
66
  end
65
67
  if git.status.untracked.empty? && git.status.changed.empty?
66
68
  puts " On branch: #{git.current_branch}".colorize(:green)
@@ -81,7 +83,7 @@ module Rgit
81
83
 
82
84
  private
83
85
 
84
- def recursive_cmd(path, &block)
86
+ def recursive_cmd(path)
85
87
  parent_path = @config.find_root(path)
86
88
  repositories(parent_path).each do |git|
87
89
  repo_name = git.dir.path.gsub("#{path}/", '')
@@ -89,15 +91,17 @@ module Rgit
89
91
  begin
90
92
  yield git
91
93
  rescue Git::GitExecuteError => e
92
- puts " Failed:".colorize(:red)
93
- puts e.message.split("\n").map {|l| " #{l}"}.join("\n").colorize(:red)
94
+ puts ' Failed:'.colorize(:red)
95
+ puts e.message.split("\n").map { |l| " #{l}" }.join("\n").colorize(:red)
94
96
  end
95
97
  end
96
98
  end
97
99
 
98
100
  def repositories(path)
99
101
  git_repos = []
100
- dirs = Dir.entries(path).select{ |entry| File.directory?(File.join(path, entry)) && !(entry == '.' || entry == '..') }.sort
102
+ dirs = Dir.entries(path).select do |entry|
103
+ File.directory?(File.join(path, entry)) && !(entry == '.' || entry == '..')
104
+ end.sort
101
105
  dirs.each do |dir|
102
106
  dir_path = File.join(path, dir)
103
107
  if File.exist?(File.join(dir_path, '.git', 'config'))
data/lib/rgit/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rgit
2
- VERSION = '1.0.2'.freeze
2
+ VERSION = '1.1'.freeze
3
3
  end
data/r-git.gemspec CHANGED
@@ -26,6 +26,8 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'rspec', '~> 3.0'
27
27
  spec.add_development_dependency 'rubocop', '~> 0.37'
28
28
  spec.add_development_dependency 'simplecov', '~> 0.11'
29
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0.0'
30
+ spec.add_dependency 'trollop', '~> 2.1.2'
29
31
  spec.add_dependency 'git', '~> 1.2.9'
30
32
  spec.add_dependency 'colorize', '~> 0.7.7'
31
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r-git
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Ridgway
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-20 00:00:00.000000000 Z
11
+ date: 2016-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.11'
83
+ - !ruby/object:Gem::Dependency
84
+ name: codeclimate-test-reporter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.0.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: trollop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 2.1.2
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.1.2
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: git
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -119,10 +147,12 @@ executables:
119
147
  extensions: []
120
148
  extra_rdoc_files: []
121
149
  files:
150
+ - ".codeclimate.yml"
122
151
  - ".gitignore"
123
152
  - ".rspec"
124
153
  - ".rubocop.yml"
125
154
  - ".travis.yml"
155
+ - CHANGELOG.md
126
156
  - Gemfile
127
157
  - LICENSE.txt
128
158
  - README.md
@@ -155,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
185
  version: '0'
156
186
  requirements: []
157
187
  rubyforge_project:
158
- rubygems_version: 2.4.8
188
+ rubygems_version: 2.5.1
159
189
  signing_key:
160
190
  specification_version: 4
161
191
  summary: Executable gem for managing multiple git repositories in a top level directory.