gitenv 1.0.4 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +8 -5
- data/LICENSE.txt +1 -1
- data/README.md +1 -11
- data/VERSION +1 -1
- data/lib/gitenv/actions/copy.rb +16 -17
- data/lib/gitenv/actions/symlink.rb +18 -20
- data/lib/gitenv/actions.rb +10 -9
- data/lib/gitenv/config.rb +25 -23
- data/lib/gitenv/context.rb +7 -7
- data/lib/gitenv/controller.rb +35 -37
- data/lib/gitenv/files/all_files.rb +3 -6
- data/lib/gitenv/files/dot_files.rb +2 -5
- data/lib/gitenv/files/matcher.rb +5 -5
- data/lib/gitenv/files/one_file.rb +3 -3
- data/lib/gitenv/files.rb +1 -1
- data/lib/gitenv/renderer.rb +3 -9
- data/lib/gitenv/repository.rb +2 -2
- data/lib/gitenv/status.rb +6 -8
- data/lib/gitenv.rb +2 -3
- data/lib/program.rb +2 -3
- metadata +58 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ba6699f7e9e5d8a5413ae5088771eaa92d87013d94ebef84ba848de8556834b
|
4
|
+
data.tar.gz: a78e8acf3ef1e23a9608c0f595706f3904e5a78872857c871bcf9e6775aa9c0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29c07fc4a8494b582b2276bfff8fb01ff726d3541d84a94f59cc05faf4d81036ead7ad8bb0ac0f74f2cc8aa7554158470ee89696394771b424fad162f8e0ce2d
|
7
|
+
data.tar.gz: 34fe5a76a0fee4619781452f32058a8566bc0ce77d4bea8a91345c1dab51e38727c2a4469151325429ff4c7e7905e324c02618dd2d373cf1a3a823c1d7a21b75
|
data/Gemfile
CHANGED
@@ -1,19 +1,22 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
+
gem 'commander', '~> 5.0'
|
3
4
|
gem 'paint', '~> 2.2'
|
4
|
-
gem 'commander', '~> 4.6'
|
5
5
|
|
6
6
|
group :development do
|
7
|
-
gem 'rake', '~> 13.0'
|
8
7
|
gem 'jeweler', '~> 2.0'
|
8
|
+
gem 'rake', '~> 13.0'
|
9
9
|
gem 'rake-version', '~> 1.0'
|
10
|
+
gem 'rubocop', '~> 1.66', require: false
|
11
|
+
gem 'rubocop-rake', '~> 0.6.0'
|
12
|
+
gem 'rubocop-rspec', '~> 3.0'
|
10
13
|
end
|
11
14
|
|
12
15
|
group :test do
|
13
|
-
gem '
|
14
|
-
gem 'fakefs', '~> 1.3', require: 'fakefs/safe'
|
16
|
+
gem 'fakefs', '~> 2.5', require: 'fakefs/safe'
|
15
17
|
gem 'rspec', '~> 3.10'
|
16
18
|
gem 'rspec-collection_matchers', '~> 1.2'
|
17
19
|
gem 'rspec-its', '~> 1.1'
|
18
20
|
gem 'simplecov', '~> 0.21.2'
|
21
|
+
gem 'simplecov-cobertura', '~> 2.1'
|
19
22
|
end
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Creates symlinks to your configuration files in a git repository (<a href="https
|
|
4
4
|
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/gitenv.svg)](http://badge.fury.io/rb/gitenv)
|
6
6
|
[![Build](https://github.com/AlphaHydrae/gitenv/actions/workflows/build.yml/badge.svg)](https://github.com/AlphaHydrae/gitenv/actions/workflows/build.yml)
|
7
|
-
[![Code Coverage](https://codecov.io/gh/AlphaHydrae/gitenv/branch/
|
7
|
+
[![Code Coverage](https://codecov.io/gh/AlphaHydrae/gitenv/branch/main/graph/badge.svg?token=PHYTXEW2MG)](https://codecov.io/gh/AlphaHydrae/gitenv)
|
8
8
|
|
9
9
|
Run gitenv without arguments to check the symlink configuration. First-time users will be prompted to enter the path to their environment repository so gitenv can set up its own config file.
|
10
10
|
|
@@ -114,13 +114,3 @@ copy('my_config_file').to('configs')
|
|
114
114
|
### Symlinks or copies in system directories
|
115
115
|
|
116
116
|
Just use `sudo`. Gitenv will happily set up your symlinks. You might have to add the `-E` switch to keep gitenv in the PATH.
|
117
|
-
|
118
|
-
## License (MIT)
|
119
|
-
|
120
|
-
Copyright (c) 2011 Alpha Hydrae
|
121
|
-
|
122
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
123
|
-
|
124
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
125
|
-
|
126
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.2.0
|
data/lib/gitenv/actions/copy.rb
CHANGED
@@ -1,19 +1,15 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
require 'fileutils'
|
3
2
|
require 'digest/sha1'
|
4
3
|
|
5
4
|
module Gitenv
|
6
|
-
|
7
5
|
class Copy
|
8
|
-
|
9
6
|
class Action < Action
|
10
|
-
|
11
|
-
def initialize context, files, options
|
7
|
+
def initialize(context, files, options)
|
12
8
|
super context, Copy, files, options
|
13
9
|
end
|
14
10
|
|
15
11
|
def overwrite *args
|
16
|
-
options = args.last.
|
12
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
17
13
|
overwrite = args.empty? ? true : args.shift
|
18
14
|
@options[:overwrite] = overwrite
|
19
15
|
@options[:backup] = options[:backup] if options.key?(:backup)
|
@@ -27,9 +23,12 @@ module Gitenv
|
|
27
23
|
end
|
28
24
|
end
|
29
25
|
|
30
|
-
def initialize
|
31
|
-
@context
|
32
|
-
@
|
26
|
+
def initialize(context, file, options = {})
|
27
|
+
@context = context
|
28
|
+
@file = file
|
29
|
+
@as = options[:as]
|
30
|
+
@overwrite = options[:overwrite]
|
31
|
+
@backup = options[:backup]
|
33
32
|
@mkdir = options.fetch :mkdir, true
|
34
33
|
@backup = true if @overwrite && !options.key?(:backup)
|
35
34
|
end
|
@@ -49,25 +48,25 @@ module Gitenv
|
|
49
48
|
|
50
49
|
def status
|
51
50
|
if !File.exist?(target)
|
52
|
-
Status.missing
|
51
|
+
Status.missing 'is not set up; apply will create the copy'
|
53
52
|
elsif @overwrite == false || digest(origin) == digest(target)
|
54
53
|
Status.ok 'ok'
|
55
54
|
elsif !@overwrite
|
56
|
-
Status.error
|
55
|
+
Status.error 'already exists; enable overwrite if you want to replace it'
|
57
56
|
elsif @backup && File.exist?(target_backup)
|
58
|
-
Status.error
|
57
|
+
Status.error 'already exists with backup copy'
|
59
58
|
else
|
60
|
-
backup_notice =
|
59
|
+
backup_notice = (' backup the file and' if @backup)
|
61
60
|
Status.warning "already exists; apply will#{backup_notice} overwrite"
|
62
61
|
end
|
63
62
|
end
|
64
63
|
|
65
64
|
def origin
|
66
|
-
@origin ||= File.join(*[
|
65
|
+
@origin ||= File.join(*[@context.from, @file].compact)
|
67
66
|
end
|
68
67
|
|
69
68
|
def target
|
70
|
-
@target ||= File.join(*[
|
69
|
+
@target ||= File.join(*[@context.to, target_name].compact)
|
71
70
|
end
|
72
71
|
|
73
72
|
def target_backup
|
@@ -80,9 +79,9 @@ module Gitenv
|
|
80
79
|
@target_name ||= @as || @file
|
81
80
|
end
|
82
81
|
|
83
|
-
def digest
|
82
|
+
def digest(file)
|
84
83
|
Digest::SHA1.new.tap do |dig|
|
85
|
-
File.open(file, 'rb'){ |io| dig.update io.readpartial(4096)
|
84
|
+
File.open(file, 'rb') { |io| dig.update io.readpartial(4096) until io.eof }
|
86
85
|
end
|
87
86
|
end
|
88
87
|
end
|
@@ -1,17 +1,12 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
1
|
module Gitenv
|
4
|
-
|
5
2
|
class Symlink
|
6
|
-
|
7
3
|
class Action < Action
|
8
|
-
|
9
|
-
def initialize context, files, options
|
4
|
+
def initialize(context, files, options)
|
10
5
|
super context, Symlink, files, options
|
11
6
|
end
|
12
7
|
|
13
8
|
def overwrite *args
|
14
|
-
options = args.last.
|
9
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
15
10
|
overwrite = args.empty? ? true : args.shift
|
16
11
|
@options[:overwrite] = overwrite
|
17
12
|
@options[:backup] = options[:backup] if options.key?(:backup)
|
@@ -25,9 +20,12 @@ module Gitenv
|
|
25
20
|
end
|
26
21
|
end
|
27
22
|
|
28
|
-
def initialize
|
29
|
-
@context
|
30
|
-
@
|
23
|
+
def initialize(context, file, options = {})
|
24
|
+
@context = context
|
25
|
+
@file = file
|
26
|
+
@as = options[:as]
|
27
|
+
@overwrite = options[:overwrite]
|
28
|
+
@backup = options[:backup]
|
31
29
|
@mkdir = options.fetch :mkdir, true
|
32
30
|
@backup = true if @overwrite && !options.key?(:backup)
|
33
31
|
end
|
@@ -37,7 +35,9 @@ module Gitenv
|
|
37
35
|
backup_exists = File.exist? link_backup
|
38
36
|
FileUtils.mv link, link_backup if @backup && file_or_symlink_exists?(link) && !backup_exists
|
39
37
|
return if File.symlink?(link) && File.readlink(link) == target
|
40
|
-
|
38
|
+
|
39
|
+
# TODO: only if link points somewhere else
|
40
|
+
FileUtils.rm link if @overwrite && file_or_symlink_exists?(link) && !backup_exists
|
41
41
|
File.symlink target, link unless File.exist?(link)
|
42
42
|
end
|
43
43
|
|
@@ -46,7 +46,7 @@ module Gitenv
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def status
|
49
|
-
backup_notice =
|
49
|
+
backup_notice = (' backup the file and' if @backup)
|
50
50
|
if File.symlink? link
|
51
51
|
current_target = File.expand_path File.readlink(link)
|
52
52
|
if @overwrite == false || current_target == target
|
@@ -54,7 +54,7 @@ module Gitenv
|
|
54
54
|
elsif !@overwrite
|
55
55
|
Status.error "exists but points to #{current_target}; enable overwrite if you want to replace it"
|
56
56
|
elsif @backup && File.exist?(link_backup)
|
57
|
-
Status.error
|
57
|
+
Status.error 'already exists with backup copy'
|
58
58
|
else
|
59
59
|
Status.warning "currently points to #{current_target}; apply will#{backup_notice} overwrite"
|
60
60
|
end
|
@@ -62,15 +62,15 @@ module Gitenv
|
|
62
62
|
if @overwrite
|
63
63
|
Status.warning "exists but is not a symlink; apply will#{backup_notice} overwrite"
|
64
64
|
else
|
65
|
-
Status.error
|
65
|
+
Status.error 'exists but is not a symlink; apply will ignore'
|
66
66
|
end
|
67
67
|
else
|
68
|
-
Status.missing
|
68
|
+
Status.missing 'is not set up; apply will create the link'
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
def link
|
73
|
-
@link ||= File.join(*[
|
73
|
+
@link ||= File.join(*[@context.to, link_name].compact)
|
74
74
|
end
|
75
75
|
|
76
76
|
def link_backup
|
@@ -78,7 +78,7 @@ module Gitenv
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def target
|
81
|
-
@target ||= File.join(*[
|
81
|
+
@target ||= File.join(*[@context.from, @file].compact)
|
82
82
|
end
|
83
83
|
|
84
84
|
private
|
@@ -87,9 +87,7 @@ module Gitenv
|
|
87
87
|
@link_name ||= @as || @file
|
88
88
|
end
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
def file_or_symlink_exists? path
|
90
|
+
def file_or_symlink_exists?(path)
|
93
91
|
File.symlink?(path) || File.exist?(path)
|
94
92
|
end
|
95
93
|
end
|
data/lib/gitenv/actions.rb
CHANGED
@@ -1,32 +1,33 @@
|
|
1
|
-
|
2
1
|
module Gitenv
|
3
|
-
|
4
2
|
class Action
|
5
3
|
attr_reader :options
|
6
4
|
|
7
|
-
def initialize
|
8
|
-
@context
|
5
|
+
def initialize(context, type, files, options)
|
6
|
+
@context = context
|
7
|
+
@type = type
|
8
|
+
@files = files
|
9
|
+
@options = options
|
9
10
|
end
|
10
11
|
|
11
|
-
def each
|
12
|
+
def each(&block)
|
12
13
|
@files.files(@context.from).each do |f|
|
13
14
|
block.call @type.new(@context, f, @options)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
def each_file
|
18
|
+
def each_file(&block)
|
18
19
|
@files.files(@context.from).each do |f|
|
19
20
|
block.call File.join(@context.from, f)
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
|
-
%w
|
24
|
+
%w[from to].each do |m|
|
24
25
|
define_method m do |*args|
|
25
|
-
@context.send
|
26
|
+
@context.send(*(args.unshift m))
|
26
27
|
self
|
27
28
|
end
|
28
29
|
end
|
29
30
|
end
|
30
31
|
end
|
31
32
|
|
32
|
-
Dir[File.join File.dirname(__FILE__), File.basename(__FILE__, '.*'), '*.rb'].each{ |lib| require lib }
|
33
|
+
Dir[File.join File.dirname(__FILE__), File.basename(__FILE__, '.*'), '*.rb'].each { |lib| require lib }
|
data/lib/gitenv/config.rb
CHANGED
@@ -1,44 +1,44 @@
|
|
1
1
|
require 'rbconfig'
|
2
2
|
|
3
3
|
module Gitenv
|
4
|
-
|
5
4
|
class Config
|
6
|
-
|
7
|
-
attr_reader :repos
|
8
|
-
attr_reader :actions
|
5
|
+
attr_reader :repos, :actions
|
9
6
|
|
10
7
|
def initialize
|
11
8
|
@context = Context.new self
|
12
|
-
@repos
|
9
|
+
@repos = []
|
10
|
+
@actions = []
|
13
11
|
end
|
14
12
|
|
15
|
-
def repo
|
13
|
+
def repo(path, &block)
|
16
14
|
@repos << Repository.new(path)
|
17
15
|
@context.from path, &block
|
18
16
|
self
|
19
17
|
end
|
20
18
|
|
21
|
-
def symlink
|
22
|
-
raise
|
23
|
-
|
19
|
+
def symlink(file, options = {})
|
20
|
+
raise 'You must specify a repository or a source directory to symlink from' unless @context.from
|
21
|
+
|
22
|
+
Symlink::Action.new(@context.dup, matcher(file), options).tap { |a| @actions << a }
|
24
23
|
end
|
25
24
|
|
26
|
-
def copy
|
27
|
-
raise
|
28
|
-
|
25
|
+
def copy(file, options = {})
|
26
|
+
raise 'You must specify a repository or a source directory to copy from' unless @context.from
|
27
|
+
|
28
|
+
Copy::Action.new(@context.dup, matcher(file), options).tap { |a| @actions << a }
|
29
29
|
end
|
30
30
|
|
31
|
-
def all_files
|
31
|
+
def all_files(options = {})
|
32
32
|
matcher :all_files, options
|
33
33
|
end
|
34
34
|
|
35
|
-
def dot_files
|
35
|
+
def dot_files(options = {})
|
36
36
|
matcher :dot_files, options
|
37
37
|
end
|
38
38
|
|
39
|
-
%w
|
40
|
-
define_method m do |*args
|
41
|
-
@context.send
|
39
|
+
%w[from to].each do |m|
|
40
|
+
define_method m do |*args, &block|
|
41
|
+
@context.send(*(args.unshift m), &block)
|
42
42
|
self
|
43
43
|
end
|
44
44
|
end
|
@@ -47,23 +47,25 @@ module Gitenv
|
|
47
47
|
@context.ignores
|
48
48
|
end
|
49
49
|
|
50
|
-
def include
|
51
|
-
raise
|
50
|
+
def include(other_config_file, optional: false)
|
51
|
+
raise 'Only absolute paths can be included' unless Pathname.new(other_config_file).absolute?
|
52
|
+
|
52
53
|
absolute_path = File.expand_path(other_config_file)
|
53
|
-
unless File.
|
54
|
+
unless File.exist?(absolute_path)
|
54
55
|
raise "Cannot find file to include #{absolute_path}" unless optional
|
56
|
+
|
55
57
|
return
|
56
58
|
end
|
57
59
|
|
58
60
|
contents = File.open(absolute_path, 'r').read
|
59
|
-
|
61
|
+
instance_eval contents, absolute_path
|
60
62
|
end
|
61
63
|
|
62
64
|
private
|
63
65
|
|
64
|
-
def matcher
|
66
|
+
def matcher(file, options = {})
|
65
67
|
options[:ignores] ||= @context.ignores.dup
|
66
|
-
if file.
|
68
|
+
if file.is_a? FilesMatcher
|
67
69
|
file
|
68
70
|
elsif file == :all_files
|
69
71
|
AllFiles.new options
|
data/lib/gitenv/context.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'rbconfig'
|
2
2
|
|
3
3
|
module Gitenv
|
4
|
-
|
5
4
|
class Context
|
6
5
|
attr_accessor :ignores
|
7
6
|
|
8
|
-
def initialize
|
9
|
-
@config
|
7
|
+
def initialize(config, options = {})
|
8
|
+
@config = config
|
9
|
+
@from = options[:from]
|
10
10
|
|
11
11
|
@to ||= File.expand_path('~')
|
12
12
|
|
@@ -14,28 +14,28 @@ module Gitenv
|
|
14
14
|
@ignores << '.DS_Store' if @ignores.empty? and RbConfig::CONFIG['host_os'] =~ /darwin/
|
15
15
|
end
|
16
16
|
|
17
|
-
def from
|
17
|
+
def from(path = nil, &block)
|
18
18
|
return @from if path.nil?
|
19
19
|
|
20
20
|
old = @from
|
21
21
|
@from = @from ? File.expand_path(path, @from) : File.expand_path(path)
|
22
22
|
|
23
23
|
if block
|
24
|
-
@config.instance_eval
|
24
|
+
@config.instance_eval(&block)
|
25
25
|
@from = old
|
26
26
|
end
|
27
27
|
|
28
28
|
self
|
29
29
|
end
|
30
30
|
|
31
|
-
def to
|
31
|
+
def to(path = nil, &block)
|
32
32
|
return @to if path.nil?
|
33
33
|
|
34
34
|
old = @to
|
35
35
|
@to = @to ? File.expand_path(path, @to) : File.expand_path(path)
|
36
36
|
|
37
37
|
if block
|
38
|
-
@config.instance_eval
|
38
|
+
@config.instance_eval(&block)
|
39
39
|
@to = old
|
40
40
|
end
|
41
41
|
|
data/lib/gitenv/controller.rb
CHANGED
@@ -1,11 +1,8 @@
|
|
1
1
|
require 'readline'
|
2
2
|
|
3
3
|
module Gitenv
|
4
|
-
|
5
4
|
class Controller
|
6
|
-
|
7
|
-
def initialize action, options
|
8
|
-
|
5
|
+
def initialize(action, options)
|
9
6
|
@action = action
|
10
7
|
@options = options
|
11
8
|
|
@@ -13,27 +10,24 @@ module Gitenv
|
|
13
10
|
end
|
14
11
|
|
15
12
|
def run
|
16
|
-
|
17
13
|
check_config_file!
|
18
14
|
|
19
|
-
if !File.exist?(config_file) and !repository
|
20
|
-
create_config_file!
|
21
|
-
end
|
15
|
+
create_config_file! if !File.exist?(config_file) and !repository
|
22
16
|
|
23
17
|
repo = repository
|
24
18
|
@config.from repo if repo && !repo.empty?
|
25
19
|
|
26
20
|
load_config_file!
|
27
21
|
|
28
|
-
|
29
|
-
#check_repository!
|
22
|
+
# @config.from repository
|
23
|
+
# check_repository!
|
30
24
|
|
31
25
|
# load dot files by default
|
32
|
-
#if @config.actions.empty?
|
26
|
+
# if @config.actions.empty?
|
33
27
|
# @config.symlink @config.dot_files
|
34
|
-
#end
|
28
|
+
# end
|
35
29
|
|
36
|
-
#check_files!
|
30
|
+
# check_files!
|
37
31
|
|
38
32
|
renderer = Renderer.new
|
39
33
|
@config.actions.each do |a|
|
@@ -47,7 +41,6 @@ module Gitenv
|
|
47
41
|
private
|
48
42
|
|
49
43
|
def create_config_file!
|
50
|
-
|
51
44
|
file = config_file
|
52
45
|
unless agree "You have no configuration file (#{file}); do you wish to create one? (y/n) "
|
53
46
|
puts
|
@@ -57,8 +50,8 @@ module Gitenv
|
|
57
50
|
repo = @options.repo || ENV['GITENV_REPO']
|
58
51
|
unless repo
|
59
52
|
Readline.completion_append_character = '/'
|
60
|
-
Readline.completion_proc =
|
61
|
-
Dir[str+'*'].grep
|
53
|
+
Readline.completion_proc = proc do |str|
|
54
|
+
Dir[str + '*'].grep(/^#{Regexp.escape(str)}/)
|
62
55
|
end
|
63
56
|
begin
|
64
57
|
repo = Readline.readline('Type the path to your environment repository: ', true)
|
@@ -68,19 +61,21 @@ module Gitenv
|
|
68
61
|
end
|
69
62
|
|
70
63
|
if !repo or repo.strip.empty?
|
71
|
-
puts
|
64
|
+
puts
|
65
|
+
abort 'You must specify an environment repository.'
|
72
66
|
elsif !File.directory?(File.expand_path(repo))
|
73
|
-
puts
|
67
|
+
puts
|
68
|
+
abort "No such directory #{repo}."
|
74
69
|
end
|
75
70
|
|
76
71
|
config = String.new.tap do |s|
|
77
|
-
s <<
|
78
|
-
s <<
|
79
|
-
s <<
|
80
|
-
s <<
|
72
|
+
s << %(\n# Path to your environment repository.)
|
73
|
+
s << %(\nrepo "#{repo}"\n)
|
74
|
+
s << %(\n# Create symlinks in your home folder.)
|
75
|
+
s << %(\nsymlink dot_files\n\n)
|
81
76
|
end
|
82
77
|
|
83
|
-
File.open(file, 'w'){ |f| f.write config }
|
78
|
+
File.open(file, 'w') { |f| f.write config }
|
84
79
|
|
85
80
|
puts
|
86
81
|
puts Paint["Successfully wrote configuration to #{file}", :green]
|
@@ -104,6 +99,7 @@ module Gitenv
|
|
104
99
|
def load_config_file!
|
105
100
|
file = config_file
|
106
101
|
return unless File.exist? file
|
102
|
+
|
107
103
|
contents = File.open(file, 'r').read
|
108
104
|
@config.instance_eval contents, file
|
109
105
|
end
|
@@ -113,18 +109,18 @@ module Gitenv
|
|
113
109
|
@config.actions.each do |a|
|
114
110
|
a.each_file do |f|
|
115
111
|
if !File.exist?(f)
|
116
|
-
problems << { :
|
117
|
-
#elsif !File.file?(f)
|
112
|
+
problems << { file: f, msg: 'does not exist' }
|
113
|
+
# elsif !File.file?(f)
|
118
114
|
# problems << { :file => f, :msg => "is not a file" }
|
119
115
|
elsif !File.readable?(f)
|
120
|
-
problems << { :
|
116
|
+
problems << { file: f, msg: 'is not readable' }
|
121
117
|
end
|
122
118
|
end
|
123
119
|
end
|
124
120
|
|
125
121
|
return unless problems.any?
|
126
122
|
|
127
|
-
msg =
|
123
|
+
msg = 'There are problems with the following files in your repository:'
|
128
124
|
problems.each do |p|
|
129
125
|
msg << "\n #{p[:file]} #{p[:msg]}"
|
130
126
|
end
|
@@ -133,7 +129,8 @@ module Gitenv
|
|
133
129
|
|
134
130
|
def check_config_file!
|
135
131
|
file = config_file
|
136
|
-
return
|
132
|
+
return unless File.exist?(file)
|
133
|
+
|
137
134
|
if !File.file?(file)
|
138
135
|
abort "#{file} is not a file. It cannot be used as a configuration file."
|
139
136
|
elsif !File.readable?(file)
|
@@ -142,26 +139,27 @@ module Gitenv
|
|
142
139
|
end
|
143
140
|
|
144
141
|
def check_repository!
|
145
|
-
|
146
|
-
msg =
|
142
|
+
unless @config.from
|
143
|
+
msg = 'You have not specified an environment repository.'
|
147
144
|
msg << "\nYou must either use the -r, --repo option or create"
|
148
145
|
msg << "\na configuration file (~/.gitenv.rb by default) with"
|
149
146
|
msg << "\nthe repo setting."
|
150
147
|
abort msg
|
151
148
|
end
|
152
149
|
return if File.directory? @config.from
|
150
|
+
|
153
151
|
notice = File.exist?(@config.from) ? 'is not a directory' : 'does not exist'
|
154
152
|
from = if @options.repo
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
153
|
+
"--repo #{@options.repo}"
|
154
|
+
elsif ENV['GITENV_REPO']
|
155
|
+
"$GITENV_REPO = #{ENV['GITENV_REPO']}"
|
156
|
+
else
|
157
|
+
%(repo "#{@config.from}")
|
158
|
+
end
|
161
159
|
abort "The repository you have specified #{notice}.\n (#{from})"
|
162
160
|
end
|
163
161
|
|
164
|
-
def abort
|
162
|
+
def abort(msg, code = 1)
|
165
163
|
warn Paint[msg, :red]
|
166
164
|
exit code
|
167
165
|
end
|
@@ -1,16 +1,13 @@
|
|
1
|
-
|
2
1
|
module Gitenv
|
3
|
-
|
4
2
|
class AllFiles < FilesMatcher
|
5
|
-
|
6
|
-
def files path
|
3
|
+
def files(path)
|
7
4
|
filter path, super(path)
|
8
5
|
end
|
9
6
|
|
10
7
|
private
|
11
8
|
|
12
|
-
def filter
|
13
|
-
entries.select{ |e| File.file? File.join(path, e) }
|
9
|
+
def filter(path, entries)
|
10
|
+
entries.select { |e| File.file? File.join(path, e) }
|
14
11
|
end
|
15
12
|
end
|
16
13
|
end
|
data/lib/gitenv/files/matcher.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Gitenv
|
2
2
|
class FilesMatcher
|
3
|
-
def initialize
|
3
|
+
def initialize(options = {})
|
4
4
|
@options = options
|
5
|
-
@ignores = options[:ignores] ? [
|
5
|
+
@ignores = options[:ignores] ? [options[:ignores]].flatten : []
|
6
6
|
end
|
7
7
|
|
8
|
-
def files
|
8
|
+
def files(path)
|
9
9
|
ignore Dir.entries(path)
|
10
10
|
end
|
11
11
|
|
@@ -16,8 +16,8 @@ module Gitenv
|
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
def ignore
|
20
|
-
entries.reject{ |e| @ignores.any?{ |g| g == e or (g.
|
19
|
+
def ignore(entries)
|
20
|
+
entries.reject { |e| @ignores.any? { |g| g == e or (g.is_a?(Regexp) and e.match(g)) } }
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/gitenv/files.rb
CHANGED
data/lib/gitenv/renderer.rb
CHANGED
@@ -1,19 +1,13 @@
|
|
1
|
-
|
2
1
|
module Gitenv
|
3
|
-
|
4
2
|
class Renderer
|
5
|
-
|
6
|
-
def initialize options = {}
|
3
|
+
def initialize(options = {})
|
7
4
|
@options = options
|
8
5
|
end
|
9
6
|
|
10
|
-
def render
|
11
|
-
|
7
|
+
def render(action)
|
12
8
|
status = action.status
|
13
9
|
color = status.color
|
14
|
-
error =
|
15
|
-
"\n #{Paint[status.message, color]}"
|
16
|
-
end
|
10
|
+
error = ("\n #{Paint[status.message, color]}" unless status.ok?)
|
17
11
|
|
18
12
|
" #{Paint[status.marker, color]} #{action}#{error}"
|
19
13
|
end
|
data/lib/gitenv/repository.rb
CHANGED
data/lib/gitenv/status.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
1
|
module Gitenv
|
4
|
-
|
5
2
|
class Status
|
6
|
-
TYPES = [
|
3
|
+
TYPES = %i[ok missing warning error]
|
7
4
|
COLORS = { ok: :green, missing: :blue, warning: :yellow, error: :red }
|
8
5
|
|
9
6
|
attr_reader :type, :message
|
@@ -11,7 +8,7 @@ module Gitenv
|
|
11
8
|
class << self
|
12
9
|
TYPES.each do |m|
|
13
10
|
define_method m do |message|
|
14
|
-
|
11
|
+
new m, message
|
15
12
|
end
|
16
13
|
end
|
17
14
|
end
|
@@ -23,7 +20,7 @@ module Gitenv
|
|
23
20
|
end
|
24
21
|
|
25
22
|
def marker
|
26
|
-
@type == :ok ?
|
23
|
+
@type == :ok ? '✓' : '✗'
|
27
24
|
end
|
28
25
|
|
29
26
|
def color
|
@@ -32,8 +29,9 @@ module Gitenv
|
|
32
29
|
|
33
30
|
private
|
34
31
|
|
35
|
-
def initialize
|
36
|
-
@type
|
32
|
+
def initialize(type, message)
|
33
|
+
@type = type
|
34
|
+
@message = message
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
data/lib/gitenv.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
require 'paint'
|
3
2
|
|
4
3
|
module Gitenv
|
5
|
-
VERSION = '1.0
|
4
|
+
VERSION = '1.2.0'
|
6
5
|
end
|
7
6
|
|
8
|
-
Dir[File.join File.dirname(__FILE__), File.basename(__FILE__, '.*'), '*.rb'].each{ |lib| require lib }
|
7
|
+
Dir[File.join File.dirname(__FILE__), File.basename(__FILE__, '.*'), '*.rb'].each { |lib| require lib }
|
data/lib/program.rb
CHANGED
@@ -11,7 +11,7 @@ global_option '-c', '--config PATH', 'Use a custom configuration file (defaults
|
|
11
11
|
command :info do |c|
|
12
12
|
c.syntax = 'gitenv info'
|
13
13
|
c.description = 'Display the current configuration (default action)'
|
14
|
-
c.action do |
|
14
|
+
c.action do |_args, options|
|
15
15
|
Gitenv::Controller.new(:info, options).run
|
16
16
|
end
|
17
17
|
end
|
@@ -19,7 +19,7 @@ end
|
|
19
19
|
command :apply do |c|
|
20
20
|
c.syntax = 'gitenv apply'
|
21
21
|
c.description = 'Create/update the symlinks'
|
22
|
-
c.action do |
|
22
|
+
c.action do |_args, options|
|
23
23
|
Gitenv::Controller.new(:apply, options).run
|
24
24
|
end
|
25
25
|
end
|
@@ -28,4 +28,3 @@ end
|
|
28
28
|
# TODO: add link to documentation in help
|
29
29
|
|
30
30
|
default_command :info
|
31
|
-
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitenv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Oulevay (Alpha Hydrae)
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: commander
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: paint
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -25,19 +39,19 @@ dependencies:
|
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '2.2'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: jeweler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
-
type: :
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '2.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,33 +67,61 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '13.0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rake-version
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '1.0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '1.0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: rubocop
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: '1.
|
89
|
+
version: '1.66'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: '1.
|
96
|
+
version: '1.66'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.6.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.6.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.0'
|
83
125
|
description: Gitenv sets up symlinks to your configuration files in a git repository.
|
84
126
|
email: git@alphahydrae.com
|
85
127
|
executables:
|
@@ -114,7 +156,7 @@ homepage: http://github.com/AlphaHydrae/gitenv
|
|
114
156
|
licenses:
|
115
157
|
- MIT
|
116
158
|
metadata: {}
|
117
|
-
post_install_message:
|
159
|
+
post_install_message:
|
118
160
|
rdoc_options: []
|
119
161
|
require_paths:
|
120
162
|
- lib
|
@@ -129,8 +171,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
171
|
- !ruby/object:Gem::Version
|
130
172
|
version: '0'
|
131
173
|
requirements: []
|
132
|
-
rubygems_version: 3.
|
133
|
-
signing_key:
|
174
|
+
rubygems_version: 3.5.16
|
175
|
+
signing_key:
|
134
176
|
specification_version: 4
|
135
177
|
summary: Symlink manager for git repositories with configuration files.
|
136
178
|
test_files: []
|