herdsman 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f18f584c60859f1587dd80aaa46f302cab09efb6
4
- data.tar.gz: e8a287c600b82bea7fed32924ab6779b3557e77c
3
+ metadata.gz: 671abc7a1456abb0f6b965c1de032a91c7a678ab
4
+ data.tar.gz: 343cc6f845a7ad9c017e2aa29aa155f81bbf8d2b
5
5
  SHA512:
6
- metadata.gz: 4413b1e186657cd9dbc41be92e6530b509e022fdf1bc1cb604c022a58dcec676acca1f7f67db6ffccf0edfc4f5b43988670d5bfb12787b8cf136b4d5fbf912d2
7
- data.tar.gz: 80d372ceb0e04bf9baf7775bdf404a6708b7c8ea4bc894ecc0d26e5e4f8ba8b894ea9fa988a9811806441f7e22ec66fce982171031026468ed7d8c69c8661432
6
+ metadata.gz: 1afcd2f8347b4528c307b12d4efb83ef93ba24c074b8bf1ca758ab95b45619877b479bb7115793c4e30ef407624a19b8d1a7316f442a3727a8f71187c7d22b39
7
+ data.tar.gz: a572e348727502c4c6b35bd93d3849f8ad17afaf2ae0983831c8b9a26769c66048fd02b25d4196dc1c3a528e82e798b026901ca006fd43c16f402c0cc791ea98
data/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
6
+
7
+ ## [v0.2.0] - 2017-03-01
8
+
9
+ ### Added
10
+
11
+ * `repositories:` alias for `repos:` config.
12
+ * Optional `fetch_cache:` property to `repos:` config.
13
+ * Optional `name:` property to `repos:` config.
14
+
15
+ ## v0.1.0 - 2017-02-20
16
+
17
+ ### Added
18
+
19
+ * `herdsman.yml` config file with `repos:` config, with `path:` and optional `revision:` properties for each repo.
20
+ * `status` command.
21
+ * `version` command.
22
+ * `--quiet`/`-q` option.
23
+
24
+ [Unreleased]: https://github.com/tommarshall/herdsman/compare/v0.2.0...HEAD
25
+ [v0.2.0]: https://github.com/tommarshall/herdsman/compare/v0.1.0...v0.2.0
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Herdsman
2
2
 
3
+ [![Gem Version](http://img.shields.io/gem/v/herdsman.svg)](https://rubygems.org/gems/herdsman)
4
+ [![Build Status](https://travis-ci.org/tommarshall/herdsman.svg?branch=master)](https://travis-ci.org/tommarshall/herdsman)
5
+ [![Code Climate](https://codeclimate.com/github/tommarshall/herdsman/badges/gpa.svg)](https://codeclimate.com/github/tommarshall/herdsman)
6
+ [![Test Coverage](https://codeclimate.com/github/tommarshall/herdsman/badges/coverage.svg)](https://codeclimate.com/github/tommarshall/herdsman/coverage)
7
+
3
8
  Herdsman is a command line utility for working with multiple Git repositories.
4
9
 
5
10
  ## Installation
@@ -52,7 +57,9 @@ repos:
52
57
  - /path/to/foo-repo
53
58
  - ../../path/to/bar-repo
54
59
  - path: /path/to/baz-repo
60
+ name: 'Baz repo' # defaults to basename of path if unset, i.e. `baz-repo`
55
61
  revision: qux-branch # defaults to `master` if unset
62
+ fetch_cache: 300 # in seconds, defaults to `0` if unset
56
63
  ```
57
64
 
58
65
  ## License
data/lib/herdsman/cli.rb CHANGED
@@ -49,10 +49,10 @@ module Herdsman
49
49
  end
50
50
 
51
51
  def herd_members(repos)
52
- repos.map do |repo|
52
+ repos.map do |herd_member_config|
53
53
  Herdsman::HerdMember.new(
54
- Herdsman::GitRepo.new(env, repo.path),
55
- repo.revision,
54
+ Herdsman::GitRepo.new(env, herd_member_config.path),
55
+ herd_member_config,
56
56
  )
57
57
  end
58
58
  end
@@ -1,4 +1,5 @@
1
1
  require 'yaml'
2
+ require 'herdsman/herd_member_config'
2
3
 
3
4
  module Herdsman
4
5
  class Config
@@ -8,9 +9,9 @@ module Herdsman
8
9
  end
9
10
 
10
11
  def repos
11
- config_repos = config['repos'] || []
12
- config_repos.map do |repo_config|
13
- RepoConfig.new(repo_config)
12
+ config_repos = config['repos'] || config['repositories'] || []
13
+ config_repos.map do |herd_member_config|
14
+ HerdMemberConfig.new(herd_member_config)
14
15
  end
15
16
  end
16
17
 
@@ -18,36 +19,6 @@ module Herdsman
18
19
 
19
20
  attr_reader :config
20
21
 
21
- class RepoConfig
22
- def initialize(repo_config)
23
- @repo_config = repo_config
24
- end
25
-
26
- def path
27
- if repo_config.is_a?(Hash)
28
- repo_config['path']
29
- else
30
- repo_config
31
- end
32
- end
33
-
34
- def revision
35
- if repo_config.is_a?(Hash) && repo_config.include?('revision')
36
- repo_config['revision']
37
- else
38
- default_revision
39
- end
40
- end
41
-
42
- private
43
-
44
- attr_reader :repo_config
45
-
46
- def default_revision
47
- 'master'
48
- end
49
- end
50
-
51
22
  def read_config!(path)
52
23
  YAML.load_file(path)
53
24
  rescue
@@ -16,6 +16,11 @@ module Herdsman
16
16
  git_output('rev-parse --git-dir')
17
17
  end
18
18
 
19
+ def fetch!
20
+ _, _, proc_status = git_command('fetch --all')
21
+ raise 'Fetch failed' unless proc_status.exitstatus.zero?
22
+ end
23
+
19
24
  def current_head
20
25
  current_branch_name || current_tag_name || abbreviated_commit_ref
21
26
  end
@@ -33,7 +38,6 @@ module Herdsman
33
38
  end
34
39
 
35
40
  def has_unpulled_commits?
36
- fetch
37
41
  git_output('log --oneline ..@{u}').lines.any?
38
42
  end
39
43
 
@@ -43,6 +47,12 @@ module Herdsman
43
47
  )
44
48
  end
45
49
 
50
+ def last_fetched
51
+ File.mtime(File.join(File.expand_path(path, Dir.pwd), '.git/FETCH_HEAD'))
52
+ rescue
53
+ Time.at(0)
54
+ end
55
+
46
56
  private
47
57
 
48
58
  attr_reader :env
@@ -66,20 +76,16 @@ module Herdsman
66
76
  StatusParser.new(git_output('status --porcelain'))
67
77
  end
68
78
 
69
- def fetch
70
- git_output('fetch --all')
79
+ def git_output(command)
80
+ git_command(command).first.chomp
71
81
  end
72
82
 
73
- def git_output(command)
83
+ def git_command(command)
74
84
  Dir.chdir(File.expand_path(path, Dir.pwd)) do
75
- Open3.capture3(git_command(command)).first.chomp
85
+ Open3.capture3("#{env.git_command} #{command}")
76
86
  end
77
87
  end
78
88
 
79
- def git_command(sub_command)
80
- "#{env.git_command} #{sub_command}"
81
- end
82
-
83
89
  class StatusParser
84
90
  def initialize(status_porcelain)
85
91
  @status_porcelain = status_porcelain
@@ -1,10 +1,8 @@
1
1
  module Herdsman
2
2
  class HerdMember
3
- attr_reader :name
4
- def initialize(repo, revision, args = {})
5
- @repo = repo
6
- @revision = revision
7
- @name = args[:name] || default_name
3
+ def initialize(repo, config)
4
+ @repo = repo
5
+ @config = config
8
6
  end
9
7
 
10
8
  def gathered?
@@ -24,11 +22,7 @@ module Herdsman
24
22
 
25
23
  private
26
24
 
27
- attr_reader :repo, :revision
28
-
29
- def default_name
30
- File.basename(repo.path)
31
- end
25
+ attr_reader :repo, :config
32
26
 
33
27
  Message = Struct.new(:level, :msg)
34
28
 
@@ -40,6 +34,28 @@ module Herdsman
40
34
  @messages = []
41
35
  end
42
36
 
37
+ def name
38
+ config.name
39
+ end
40
+
41
+ def revision
42
+ config.revision
43
+ end
44
+
45
+ def fetch_cache
46
+ config.fetch_cache
47
+ end
48
+
49
+ def fetch_cached?
50
+ Time.now - repo.last_fetched < fetch_cache
51
+ end
52
+
53
+ def repo_fetch!
54
+ repo.fetch!
55
+ rescue
56
+ messages << Message.new(:warn, "#{name} failed to fetch")
57
+ end
58
+
43
59
  def repo_initialized?
44
60
  unless repo.initialized?
45
61
  messages << Message.new(:warn, "#{repo.path} is not a git repo")
@@ -55,6 +71,7 @@ module Herdsman
55
71
  end
56
72
 
57
73
  def repo_has_zero_unpulled_commits?
74
+ repo_fetch! unless fetch_cached?
58
75
  if repo.has_unpulled_commits?
59
76
  messages << Message.new(:warn, "#{name} has unpulled commits")
60
77
  end
@@ -0,0 +1,52 @@
1
+ module Herdsman
2
+ class HerdMemberConfig
3
+ def initialize(args = {})
4
+ @args = args
5
+ validate!
6
+ end
7
+
8
+ def path
9
+ args.fetch('path')
10
+ rescue
11
+ args
12
+ end
13
+
14
+ def name
15
+ args.fetch('name')
16
+ rescue
17
+ default_name
18
+ end
19
+
20
+ def revision
21
+ args.fetch('revision')
22
+ rescue
23
+ default_revision
24
+ end
25
+
26
+ def fetch_cache
27
+ args.fetch('fetch_cache').to_i
28
+ rescue
29
+ default_fetch_cache
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :args
35
+
36
+ def default_name
37
+ File.basename(path)
38
+ end
39
+
40
+ def default_revision
41
+ 'master'
42
+ end
43
+
44
+ def default_fetch_cache
45
+ 0
46
+ end
47
+
48
+ def validate!
49
+ raise 'Invalid repo config, path is required' unless path.is_a?(String)
50
+ end
51
+ end
52
+ end
@@ -1,3 +1,3 @@
1
1
  module Herdsman
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: herdsman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Marshall
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-20 00:00:00.000000000 Z
11
+ date: 2017-03-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Herdsman is a CLI utility for working with multiple Git repositories
14
14
  email: tommarshall7@gmail.com
@@ -17,6 +17,7 @@ executables:
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - CHANGELOG.md
20
21
  - README.md
21
22
  - bin/herdsman
22
23
  - herdsman.gemspec
@@ -28,6 +29,7 @@ files:
28
29
  - lib/herdsman/git_repo.rb
29
30
  - lib/herdsman/herd.rb
30
31
  - lib/herdsman/herd_member.rb
32
+ - lib/herdsman/herd_member_config.rb
31
33
  - lib/herdsman/log_adapter.rb
32
34
  - lib/herdsman/version.rb
33
35
  homepage: https://github.com/tommarshall/herdsman
@@ -50,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
52
  version: '0'
51
53
  requirements: []
52
54
  rubyforge_project:
53
- rubygems_version: 2.4.5.1
55
+ rubygems_version: 2.5.2
54
56
  signing_key:
55
57
  specification_version: 4
56
58
  summary: A CLI utility for working with multiple Git repositories