git-superproject 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77488a891a2ea164436a18c086dbcf6a6cf513a9
4
- data.tar.gz: c3f27a89cae98a4a10321dd1ef1c2502ae77fe21
3
+ metadata.gz: 75cae9609ec54fe4995a92b362a638e116449cc1
4
+ data.tar.gz: 4fb1400df0a73442693593c51816af85b9c68c7a
5
5
  SHA512:
6
- metadata.gz: 7e9abceba6edf0114c3617c0a59d0bc846de28ed246dcda94fbd3d6ff7c2a31d290e20e1841415dc65a244d784cb45661a832957a6a7df30d0ecd55c2c30f164
7
- data.tar.gz: 110cd34163237523a33118436e60db3b5543fee03d9c292a1d6bff4b1179470630d7718079ca564ac2d689a878af50708b449fe25f768d88ab63874df70401e8
6
+ metadata.gz: 36777c3684f35cc9dc5b055122396ebfdf65ac62de58e22c6dcdfb8c3722dc907c1be5aff7d1238f1bd24abf2f4d40c8f3a9b72304fb7ec15d105de4f35f18a0
7
+ data.tar.gz: '08e03c351a822a72fb316af0700d8a96419685e3d863f78210e429892b5ebe3946bce199c26e17c41f9dbe9524822169bf1c07cb0e613031c595f626380f6a44'
data/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
+ /Gemfile.lock
3
4
  /_yardoc/
4
5
  /coverage/
5
6
  /doc/
data/bin/setup CHANGED
@@ -3,6 +3,12 @@ set -euo pipefail
3
3
  IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
- bundle install
6
+ [ -f Brewfile ] && brew bundle
7
+ [ -f .ruby-version ] && rbenv install -s
8
+ gem install --conservative bundler
9
+ [ -f Gemfile ] && bundle install
7
10
 
8
- # Do any other automated setup that you need to do here
11
+ set +vxeu
12
+ echo
13
+
14
+ # That's all Folks!
data/exe/git-superproject CHANGED
@@ -27,8 +27,8 @@ when /\A--/
27
27
  end
28
28
  case command
29
29
  when '--list' then puts config.list(name).to_json
30
- when '--add' then puts config.add(name, ARGV).to_json
31
- when '--remove' then puts config.remove(name, ARGV).to_json
30
+ when '--add' then puts config.add(name, *ARGV).to_json
31
+ when '--remove' then puts config.remove(name, *ARGV).to_json
32
32
  else
33
33
  abort \
34
34
  "Unknown 'git superproject' command: #{command}\n\n" \
@@ -1,6 +1,6 @@
1
1
  module Git
2
2
  module Superproject
3
3
  NAME = 'git-superproject'.freeze
4
- VERSION = '0.1.0'.freeze
4
+ VERSION = '0.2.0'.freeze
5
5
  end
6
6
  end
@@ -1,5 +1,6 @@
1
1
  require 'git/superproject/version'
2
2
 
3
+ require 'set'
3
4
  require 'json'
4
5
  require 'English'
5
6
  require 'pathname'
@@ -26,50 +27,41 @@ module Git
26
27
 
27
28
  def initialize(key_value_pairs)
28
29
  @superprojects = Hash.new do |superprojects, name|
29
- superprojects[name] = []
30
+ superprojects[name] = Set.new # guarantee uniqueness
30
31
  end
31
32
 
32
33
  key_value_pairs.each do |key_value|
33
34
  key, value = key_value.split('=')
34
-
35
- key =~ /\Asuperproject\.(?<name>.*)\.repo\z/
36
- raise "Invalid superproject key: #{key}" unless $LAST_MATCH_INFO
37
-
38
- name = $LAST_MATCH_INFO[:name]
39
-
40
- value =~ %r{\A[-\w]+/[-\w]+\z}
41
- raise "Invalid repo name: #{value}" unless $LAST_MATCH_INFO
42
-
43
- @superprojects[name] << value
35
+ process(key, value)
44
36
  end
45
37
  end
46
38
 
47
39
  def list(name)
48
- @superprojects[name]
40
+ @superprojects[name].to_a.sort
49
41
  end
50
42
 
51
- def add(name, repos)
43
+ def add(name, *repos)
52
44
  repos.each do |repo|
53
- @superprojects[name] << repo
45
+ add_to(name, repo)
54
46
  end
55
- @superprojects[name]
47
+ list(name)
56
48
  end
57
49
 
58
- def remove(name, repos)
50
+ def remove(name, *repos)
59
51
  repos.each do |repo|
60
- @superprojects[name].delete(repo)
52
+ remove_from(name, repo)
61
53
  end
62
- @superprojects[name]
54
+ list(name)
63
55
  end
64
56
 
65
57
  def write_to(file)
66
58
  # create backup of original file
67
59
  FileUtils.mv(file, "#{file}~") if File.exist? file
68
60
 
69
- @superprojects.each do |name, repos|
70
- name = "superproject.#{name}.repo"
71
- repos.each do |repo|
72
- `git config --file #{file} --add #{name} #{repo}`
61
+ @superprojects.keys.each do |name|
62
+ key = "superproject.#{name}.repo"
63
+ list(name).each do |repo|
64
+ `git config --file #{file} --add #{key} #{repo}`
73
65
  end
74
66
  end
75
67
 
@@ -81,6 +73,26 @@ module Git
81
73
  @superprojects.to_json
82
74
  end
83
75
 
76
+ private
77
+
78
+ def process(key, repo)
79
+ key =~ /\Asuperproject\.(?<name>.*)\.repo\z/
80
+ raise "Invalid superproject key: #{key}" unless $LAST_MATCH_INFO
81
+
82
+ add_to($LAST_MATCH_INFO[:name], repo)
83
+ end
84
+
85
+ def add_to(name, repo)
86
+ repo =~ %r{\A[-.\w]+/[-.\w]+\z}
87
+ raise "Invalid repo name: #{repo}" unless $LAST_MATCH_INFO
88
+
89
+ @superprojects[name] << repo
90
+ end
91
+
92
+ def remove_from(name, repo)
93
+ @superprojects[name].delete(repo)
94
+ end
95
+
84
96
  end
85
97
 
86
98
  module Commands
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-superproject
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
  - Peter Vandenberk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-18 00:00:00.000000000 Z
11
+ date: 2018-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler