gitenv 0.2.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +14 -14
- data/LICENSE.txt +1 -1
- data/README.md +4 -0
- data/VERSION +1 -1
- data/lib/gitenv.rb +1 -1
- data/lib/gitenv/actions.rb +1 -1
- data/lib/gitenv/actions/copy.rb +11 -8
- data/lib/gitenv/actions/symlink.rb +35 -8
- data/lib/gitenv/config.rb +12 -0
- data/lib/gitenv/context.rb +1 -1
- data/lib/gitenv/controller.rb +5 -5
- data/lib/gitenv/files/matcher.rb +0 -3
- data/lib/gitenv/files/one_file.rb +0 -3
- data/lib/gitenv/repository.rb +5 -2
- metadata +11 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 066334c209061edcd32f246eea29be949b62329779fb600b741546c6b033a3d0
|
4
|
+
data.tar.gz: 64e0c52f52bcc698762175fd3397854d4c42dfedf44f19f958a9eb77ca59cd70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83feb9539ad0ae87f1e69dae0af1a97a15f1e1e79104dd521f8a8302ff657c62a13a571dd4d0c2b2ea0095d4f1253d4beb920d7c38505d53ce3e6d6c9ca2f923
|
7
|
+
data.tar.gz: fb87187285ae1614d3ba05035ac1459aa602e0b434929df379f4ae790bcde507d9c29aa064b6c77af1a812876c0537cd33c8cef06308be9eb7152d25c8240c0f
|
data/Gemfile
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
source "
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
1
|
+
source "https://rubygems.org"
|
5
2
|
|
6
|
-
gem 'paint', '~>
|
7
|
-
gem 'commander', '~> 4.
|
3
|
+
gem 'paint', '~> 2.2'
|
4
|
+
gem 'commander', '~> 4.6'
|
8
5
|
|
9
|
-
# Add dependencies to develop your gem here.
|
10
|
-
# Include everything needed to run rake, tests, features, etc.
|
11
6
|
group :development do
|
12
|
-
gem 'rake', '~>
|
13
|
-
gem 'rspec', '~> 3.1'
|
14
|
-
gem 'rspec-its', '~> 1.1'
|
15
|
-
gem 'fakefs', '~> 0.6.3', :require => 'fakefs/safe'
|
7
|
+
gem 'rake', '~> 13.0'
|
16
8
|
gem 'jeweler', '~> 2.0'
|
17
|
-
gem 'rake-version', '~> 0
|
18
|
-
|
9
|
+
gem 'rake-version', '~> 1.0'
|
10
|
+
end
|
11
|
+
|
12
|
+
group :test do
|
13
|
+
gem 'codecov', '~> 0.5.2', require: false
|
14
|
+
gem 'fakefs', '~> 1.3', require: 'fakefs/safe'
|
15
|
+
gem 'rspec', '~> 3.10'
|
16
|
+
gem 'rspec-collection_matchers', '~> 1.2'
|
17
|
+
gem 'rspec-its', '~> 1.1'
|
18
|
+
gem 'simplecov', '~> 0.21.2'
|
19
19
|
end
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
Creates symlinks to your configuration files in a git repository (<a href="https://github.com/AlphaHydrae/env">like mine</a>).
|
4
4
|
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/gitenv.svg)](http://badge.fury.io/rb/gitenv)
|
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/master/graph/badge.svg?token=PHYTXEW2MG)](https://codecov.io/gh/AlphaHydrae/gitenv)
|
8
|
+
|
5
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.
|
6
10
|
|
7
11
|
#=> gitenv
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
1.1.0
|
data/lib/gitenv.rb
CHANGED
data/lib/gitenv/actions.rb
CHANGED
data/lib/gitenv/actions/copy.rb
CHANGED
@@ -30,14 +30,17 @@ module Gitenv
|
|
30
30
|
def initialize context, file, options = {}
|
31
31
|
@context, @file = context, file
|
32
32
|
@as, @overwrite, @backup = options[:as], options[:overwrite], options[:backup]
|
33
|
-
@
|
33
|
+
@mkdir = options.fetch :mkdir, true
|
34
|
+
@backup = true if @overwrite && !options.key?(:backup)
|
34
35
|
end
|
35
36
|
|
36
37
|
def apply
|
37
|
-
|
38
|
-
FileUtils.
|
39
|
-
|
40
|
-
FileUtils.
|
38
|
+
# TODO: test with mkdir option set to false
|
39
|
+
FileUtils.mkdir_p File.dirname(target) if @mkdir
|
40
|
+
backup_exists = File.exist? target_backup
|
41
|
+
FileUtils.mv target, target_backup if @backup && File.exist?(target) && !backup_exists
|
42
|
+
FileUtils.rm target if @overwrite && File.exist?(target) && !backup_exists
|
43
|
+
FileUtils.cp origin, target unless File.exist?(target)
|
41
44
|
end
|
42
45
|
|
43
46
|
def to_s
|
@@ -45,13 +48,13 @@ module Gitenv
|
|
45
48
|
end
|
46
49
|
|
47
50
|
def status
|
48
|
-
if !File.
|
51
|
+
if !File.exist?(target)
|
49
52
|
Status.missing "is not set up; apply will create the copy"
|
50
|
-
elsif @overwrite == false
|
53
|
+
elsif @overwrite == false || digest(origin) == digest(target)
|
51
54
|
Status.ok 'ok'
|
52
55
|
elsif !@overwrite
|
53
56
|
Status.error "already exists; enable overwrite if you want to replace it"
|
54
|
-
elsif @backup
|
57
|
+
elsif @backup && File.exist?(target_backup)
|
55
58
|
Status.error "already exists with backup copy"
|
56
59
|
else
|
57
60
|
backup_notice = if @backup; " backup the file and"; end
|
@@ -10,25 +10,35 @@ module Gitenv
|
|
10
10
|
super context, Symlink, files, options
|
11
11
|
end
|
12
12
|
|
13
|
-
def overwrite
|
13
|
+
def overwrite *args
|
14
|
+
options = args.last.kind_of?(Hash) ? args.pop : {}
|
15
|
+
overwrite = args.empty? ? true : args.shift
|
14
16
|
@options[:overwrite] = overwrite
|
17
|
+
@options[:backup] = options[:backup] if options.key?(:backup)
|
15
18
|
self
|
16
19
|
end
|
17
20
|
|
18
21
|
def once
|
19
22
|
@options[:overwrite] = false
|
23
|
+
@options[:backup] = false
|
20
24
|
self
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
24
28
|
def initialize context, file, options = {}
|
25
29
|
@context, @file = context, file
|
26
|
-
@as, @overwrite = options[:as], options[:overwrite]
|
30
|
+
@as, @overwrite, @backup = options[:as], options[:overwrite], options[:backup]
|
31
|
+
@mkdir = options.fetch :mkdir, true
|
32
|
+
@backup = true if @overwrite && !options.key?(:backup)
|
27
33
|
end
|
28
34
|
|
29
35
|
def apply
|
30
|
-
FileUtils.
|
31
|
-
|
36
|
+
FileUtils.mkdir_p File.dirname(link) if @mkdir
|
37
|
+
backup_exists = File.exist? link_backup
|
38
|
+
FileUtils.mv link, link_backup if @backup && file_or_symlink_exists?(link) && !backup_exists
|
39
|
+
return if File.symlink?(link) && File.readlink(link) == target
|
40
|
+
FileUtils.rm link if @overwrite && file_or_symlink_exists?(link) && !backup_exists # TODO: only if link points somewhere else
|
41
|
+
File.symlink target, link unless File.exist?(link)
|
32
42
|
end
|
33
43
|
|
34
44
|
def to_s
|
@@ -36,17 +46,24 @@ module Gitenv
|
|
36
46
|
end
|
37
47
|
|
38
48
|
def status
|
49
|
+
backup_notice = if @backup; " backup the file and"; end
|
39
50
|
if File.symlink? link
|
40
51
|
current_target = File.expand_path File.readlink(link)
|
41
|
-
if @overwrite == false
|
52
|
+
if @overwrite == false || current_target == target
|
42
53
|
Status.ok 'ok'
|
43
54
|
elsif !@overwrite
|
44
55
|
Status.error "exists but points to #{current_target}; enable overwrite if you want to replace it"
|
56
|
+
elsif @backup && File.exist?(link_backup)
|
57
|
+
Status.error "already exists with backup copy"
|
45
58
|
else
|
46
|
-
Status.warning "currently points to #{current_target}; apply will overwrite"
|
59
|
+
Status.warning "currently points to #{current_target}; apply will#{backup_notice} overwrite"
|
60
|
+
end
|
61
|
+
elsif File.exist? link
|
62
|
+
if @overwrite
|
63
|
+
Status.warning "exists but is not a symlink; apply will#{backup_notice} overwrite"
|
64
|
+
else
|
65
|
+
Status.error "exists but is not a symlink; apply will ignore"
|
47
66
|
end
|
48
|
-
elsif File.exists? link
|
49
|
-
Status.error "exists but is not a symlink; apply will ignore"
|
50
67
|
else
|
51
68
|
Status.missing "is not set up; apply will create the link"
|
52
69
|
end
|
@@ -56,6 +73,10 @@ module Gitenv
|
|
56
73
|
@link ||= File.join(*[ @context.to, link_name].compact)
|
57
74
|
end
|
58
75
|
|
76
|
+
def link_backup
|
77
|
+
@link_backup ||= "#{link}.orig"
|
78
|
+
end
|
79
|
+
|
59
80
|
def target
|
60
81
|
@target ||= File.join(*[ @context.from, @file ].compact)
|
61
82
|
end
|
@@ -65,5 +86,11 @@ module Gitenv
|
|
65
86
|
def link_name
|
66
87
|
@link_name ||= @as || @file
|
67
88
|
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def file_or_symlink_exists? path
|
93
|
+
File.symlink?(path) || File.exist?(path)
|
94
|
+
end
|
68
95
|
end
|
69
96
|
end
|
data/lib/gitenv/config.rb
CHANGED
@@ -47,6 +47,18 @@ module Gitenv
|
|
47
47
|
@context.ignores
|
48
48
|
end
|
49
49
|
|
50
|
+
def include other_config_file, optional: false
|
51
|
+
raise "Only absolute paths can be included" unless Pathname.new(other_config_file).absolute?
|
52
|
+
absolute_path = File.expand_path(other_config_file)
|
53
|
+
unless File.exists?(absolute_path)
|
54
|
+
raise "Cannot find file to include #{absolute_path}" unless optional
|
55
|
+
return
|
56
|
+
end
|
57
|
+
|
58
|
+
contents = File.open(absolute_path, 'r').read
|
59
|
+
self.instance_eval contents, absolute_path
|
60
|
+
end
|
61
|
+
|
50
62
|
private
|
51
63
|
|
52
64
|
def matcher file, options = {}
|
data/lib/gitenv/context.rb
CHANGED
data/lib/gitenv/controller.rb
CHANGED
@@ -16,7 +16,7 @@ module Gitenv
|
|
16
16
|
|
17
17
|
check_config_file!
|
18
18
|
|
19
|
-
if !File.
|
19
|
+
if !File.exist?(config_file) and !repository
|
20
20
|
create_config_file!
|
21
21
|
end
|
22
22
|
|
@@ -103,7 +103,7 @@ module Gitenv
|
|
103
103
|
|
104
104
|
def load_config_file!
|
105
105
|
file = config_file
|
106
|
-
return unless File.
|
106
|
+
return unless File.exist? file
|
107
107
|
contents = File.open(file, 'r').read
|
108
108
|
@config.instance_eval contents, file
|
109
109
|
end
|
@@ -112,7 +112,7 @@ module Gitenv
|
|
112
112
|
problems = []
|
113
113
|
@config.actions.each do |a|
|
114
114
|
a.each_file do |f|
|
115
|
-
if !File.
|
115
|
+
if !File.exist?(f)
|
116
116
|
problems << { :file => f, :msg => "does not exist" }
|
117
117
|
#elsif !File.file?(f)
|
118
118
|
# problems << { :file => f, :msg => "is not a file" }
|
@@ -133,7 +133,7 @@ module Gitenv
|
|
133
133
|
|
134
134
|
def check_config_file!
|
135
135
|
file = config_file
|
136
|
-
return if !File.
|
136
|
+
return if !File.exist?(file)
|
137
137
|
if !File.file?(file)
|
138
138
|
abort "#{file} is not a file. It cannot be used as a configuration file."
|
139
139
|
elsif !File.readable?(file)
|
@@ -150,7 +150,7 @@ module Gitenv
|
|
150
150
|
abort msg
|
151
151
|
end
|
152
152
|
return if File.directory? @config.from
|
153
|
-
notice = File.
|
153
|
+
notice = File.exist?(@config.from) ? 'is not a directory' : 'does not exist'
|
154
154
|
from = if @options.repo
|
155
155
|
"--repo #{@options.repo}"
|
156
156
|
elsif ENV['GITENV_REPO']
|
data/lib/gitenv/files/matcher.rb
CHANGED
data/lib/gitenv/repository.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitenv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Oulevay (Alpha Hydrae)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: paint
|
@@ -16,84 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '2.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '2.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: commander
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '4.
|
33
|
+
version: '4.6'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '4.
|
40
|
+
version: '4.6'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rspec
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.1'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '3.1'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec-its
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '1.1'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '1.1'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: fakefs
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.6.3
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.6.3
|
54
|
+
version: '13.0'
|
97
55
|
- !ruby/object:Gem::Dependency
|
98
56
|
name: jeweler
|
99
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,28 +72,14 @@ dependencies:
|
|
114
72
|
requirements:
|
115
73
|
- - "~>"
|
116
74
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: 0.4.1
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: simplecov
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: 0.9.1
|
75
|
+
version: '1.0'
|
132
76
|
type: :development
|
133
77
|
prerelease: false
|
134
78
|
version_requirements: !ruby/object:Gem::Requirement
|
135
79
|
requirements:
|
136
80
|
- - "~>"
|
137
81
|
- !ruby/object:Gem::Version
|
138
|
-
version: 0
|
82
|
+
version: '1.0'
|
139
83
|
description: Gitenv sets up symlinks to your configuration files in a git repository.
|
140
84
|
email: git@alphahydrae.com
|
141
85
|
executables:
|
@@ -185,8 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
129
|
- !ruby/object:Gem::Version
|
186
130
|
version: '0'
|
187
131
|
requirements: []
|
188
|
-
|
189
|
-
rubygems_version: 2.4.5
|
132
|
+
rubygems_version: 3.2.15
|
190
133
|
signing_key:
|
191
134
|
specification_version: 4
|
192
135
|
summary: Symlink manager for git repositories with configuration files.
|