changit 0.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 +7 -0
- data/.gitignore +3 -0
- data/LICENSE +21 -0
- data/README.md +28 -0
- data/Rakefile +10 -0
- data/bin/changit +5 -0
- data/changit.gemspec +20 -0
- data/demo.gif +0 -0
- data/lib/changit/config_reader.rb +23 -0
- data/lib/changit/config_writer.rb +63 -0
- data/lib/changit/git_dir_finder.rb +15 -0
- data/lib/changit/version.rb +3 -0
- data/lib/changit.rb +17 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2b4a8ebb640fc22a9ebe8670d46e0573634e0c8b
|
4
|
+
data.tar.gz: 031dd2c48bbfbef3cd134dc0a965ceabda6b017d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e56e10a4970f8063ca601941300660f72508ae23d91b7196b06e2d7a5696bb5dc555abfa3b73a80285ebb1cd8689e577c295b7871df81447b867f71fa694a0c7
|
7
|
+
data.tar.gz: 9068aed8fca24cdf5c173a3b66ac226a0596e7cdd1bcf6a482450dede815b71a0b8cd9c86acbaad7fa569b5e1e0e794e36bb6b87794dff8b9112b36932c41640
|
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 Ahmad Saleh
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Changit
|
2
|
+
---
|
3
|
+
|
4
|
+
An over-engineered tool to change git config for multiple projects at once.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem install changit
|
10
|
+
```
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
In a hub-directory (that contains multiple git projects), add a `.gitconfig`
|
15
|
+
file with your configuration, and run:
|
16
|
+
|
17
|
+
```sh
|
18
|
+
changit
|
19
|
+
```
|
20
|
+
|
21
|
+
## Demo
|
22
|
+
|
23
|
+

|
24
|
+
|
25
|
+
|
26
|
+
## License
|
27
|
+
|
28
|
+
See [LICENSE](https://github.com/aaooki/changit/blob/master/LICENSE).
|
data/Rakefile
ADDED
data/bin/changit
ADDED
data/changit.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.expand_path('../lib/changit/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["aaooki"]
|
6
|
+
gem.email = ["aaooki7@gmail.com"]
|
7
|
+
gem.description = %q{An over-engineered tool to change git config for multiple projects at once.}
|
8
|
+
gem.summary = %q{An over-engineered tool to change git config for multiple projects at once.}
|
9
|
+
gem.homepage = "https://github.com/aaooki/changit"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\).reject do |f|
|
12
|
+
f.match(%r{^(test|spec|features)/})
|
13
|
+
end
|
14
|
+
|
15
|
+
gem.executables = ["changit"]
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.name = "changit"
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.version = Changit::VERSION
|
20
|
+
end
|
data/demo.gif
ADDED
Binary file
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Changit
|
2
|
+
class ConfigReader
|
3
|
+
DEFAULT_SEARCH_PATH = "#{Dir.pwd}/.gitconfig".freeze
|
4
|
+
|
5
|
+
attr_reader :search_path
|
6
|
+
|
7
|
+
def initialize(search_path: DEFAULT_SEARCH_PATH)
|
8
|
+
@search_path = search_path
|
9
|
+
|
10
|
+
freeze
|
11
|
+
end
|
12
|
+
|
13
|
+
def read
|
14
|
+
search_result = Dir.glob(@search_path)
|
15
|
+
|
16
|
+
if search_result.empty?
|
17
|
+
fail "File #{@search_path} not found."
|
18
|
+
else
|
19
|
+
File.read(search_result.first)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Changit
|
2
|
+
class ConfigWriter
|
3
|
+
attr_reader :config, :config_files
|
4
|
+
|
5
|
+
def initialize(config, config_files)
|
6
|
+
@config = config
|
7
|
+
@config_files = config_files
|
8
|
+
end
|
9
|
+
|
10
|
+
def write
|
11
|
+
hsrc = parse(@config)
|
12
|
+
|
13
|
+
@config_files.each do |path|
|
14
|
+
hdst = parse(File.read(path))
|
15
|
+
hmerged = comp_and_merge(hsrc, hdst)
|
16
|
+
|
17
|
+
out = ""
|
18
|
+
hmerged.each do |k, v|
|
19
|
+
out += "#{k}\n"
|
20
|
+
v.each do |v_k, v_v|
|
21
|
+
out += "\t#{v_k} = #{v_v}\n"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
File.open(path, 'w') { |f| f.write(out); f.close }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse(config)
|
30
|
+
h = Hash.new
|
31
|
+
|
32
|
+
config.each_line do |line|
|
33
|
+
line.strip!
|
34
|
+
line.gsub!(/\s+/, '')
|
35
|
+
|
36
|
+
if line =~ /^\[\w+\]$/
|
37
|
+
h[line] = {}
|
38
|
+
else
|
39
|
+
key, value = line.split('=')
|
40
|
+
h[h.to_a.last[0]][key] = value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
h
|
45
|
+
end
|
46
|
+
|
47
|
+
def comp_and_merge(hsrc, hdst)
|
48
|
+
hdifference = hsrc.dup.delete_if { |k, _| hdst.key?(k) }
|
49
|
+
|
50
|
+
hdst.each do |k, v|
|
51
|
+
if hsrc[k]
|
52
|
+
hdst[k] = hdst[k].merge(hsrc[k])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
unless hdifference.empty?
|
57
|
+
hdst.merge!(hdifference)
|
58
|
+
end
|
59
|
+
|
60
|
+
hdst
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Changit
|
2
|
+
class GitDirFinder
|
3
|
+
DEFAULT_SEARCH_PATH = Dir.pwd.freeze
|
4
|
+
|
5
|
+
def initialize(search_path: DEFAULT_SEARCH_PATH)
|
6
|
+
@search_path = "#{search_path}/**/.git/config"
|
7
|
+
|
8
|
+
freeze
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_all
|
12
|
+
Dir.glob(@search_path)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/changit.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'changit/version'
|
2
|
+
require 'changit/git_dir_finder'
|
3
|
+
require 'changit/config_reader'
|
4
|
+
require 'changit/config_writer'
|
5
|
+
|
6
|
+
module Changit
|
7
|
+
def self.run
|
8
|
+
# File to copy from
|
9
|
+
config = ConfigReader.new.read
|
10
|
+
|
11
|
+
# First, search directories inside the current pwd and make sure they contain a .git dir
|
12
|
+
files_to_write_to = GitDirFinder.new.find_all
|
13
|
+
|
14
|
+
# Then, copy the gitconfig file content to each .git/config file in these directories
|
15
|
+
ConfigWriter.new(config, files_to_write_to).write
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: changit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- aaooki
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: An over-engineered tool to change git config for multiple projects at
|
14
|
+
once.
|
15
|
+
email:
|
16
|
+
- aaooki7@gmail.com
|
17
|
+
executables:
|
18
|
+
- changit
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- ".gitignore"
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- bin/changit
|
27
|
+
- changit.gemspec
|
28
|
+
- demo.gif
|
29
|
+
- lib/changit.rb
|
30
|
+
- lib/changit/config_reader.rb
|
31
|
+
- lib/changit/config_writer.rb
|
32
|
+
- lib/changit/git_dir_finder.rb
|
33
|
+
- lib/changit/version.rb
|
34
|
+
homepage: https://github.com/aaooki/changit
|
35
|
+
licenses: []
|
36
|
+
metadata: {}
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 2.5.1
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: An over-engineered tool to change git config for multiple projects at once.
|
57
|
+
test_files: []
|