gitenv 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -5
- data/README.md +5 -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 +28 -8
- data/lib/gitenv/controller.rb +5 -5
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c01b85f1089abd188b5127a3ee739ff9f0444d1c
|
4
|
+
data.tar.gz: 475c4c025297edc07a150d611fb946d33094c256
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fd9b73508af24b593bb601358ef94a44daad5c4dd27c793ba4b700f420200f1897888a4a66d2a386a4b25142503d607fa82dbc168ee2b2c9eac73e8b6029403
|
7
|
+
data.tar.gz: 3094a5ddab27645bfaf1713af0fe0d573a91e6a71e2815736a8c102e51abb8ffff766e94fc0d8063bf04f26defe0287ef992cf3de59b2b3949f9b1762256257d
|
data/Gemfile
CHANGED
@@ -3,17 +3,18 @@ source "http://rubygems.org"
|
|
3
3
|
# Example:
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
5
5
|
|
6
|
-
gem 'paint', '~>
|
6
|
+
gem 'paint', '~> 1.0'
|
7
7
|
gem 'commander', '~> 4.2'
|
8
8
|
|
9
9
|
# Add dependencies to develop your gem here.
|
10
10
|
# Include everything needed to run rake, tests, features, etc.
|
11
11
|
group :development do
|
12
|
-
|
12
|
+
require 'pp' # https://github.com/fakefs/fakefs/issues/99
|
13
|
+
gem 'rake', '~> 11.0'
|
13
14
|
gem 'rspec', '~> 3.1'
|
14
15
|
gem 'rspec-its', '~> 1.1'
|
15
|
-
gem 'fakefs', '~> 0.
|
16
|
+
gem 'fakefs', '~> 0.9.0', :require => 'fakefs/safe'
|
16
17
|
gem 'jeweler', '~> 2.0'
|
17
|
-
gem 'rake-version', '~> 0
|
18
|
-
gem 'simplecov', '~> 0.
|
18
|
+
gem 'rake-version', '~> 1.0'
|
19
|
+
gem 'simplecov', '~> 0.12.0'
|
19
20
|
end
|
data/README.md
CHANGED
@@ -2,6 +2,11 @@
|
|
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
|
+
[![Dependency Status](https://gemnasium.com/AlphaHydrae/gitenv.svg)](https://gemnasium.com/AlphaHydrae/gitenv)
|
7
|
+
[![Build Status](https://travis-ci.org/AlphaHydrae/gitenv.svg?branch=master)](http://travis-ci.org/AlphaHydrae/gitenv)
|
8
|
+
[![Coverage Status](https://coveralls.io/repos/AlphaHydrae/gitenv/badge.svg)](https://coveralls.io/r/AlphaHydrae/gitenv)
|
9
|
+
|
5
10
|
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
11
|
|
7
12
|
#=> gitenv
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.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,34 @@ 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.exist?(link) && !backup_exists
|
39
|
+
FileUtils.rm link if @overwrite && File.exist?(link) && !backup_exists # TODO: only if link points somewhere else
|
40
|
+
File.symlink target, link unless File.exist?(link)
|
32
41
|
end
|
33
42
|
|
34
43
|
def to_s
|
@@ -36,17 +45,24 @@ module Gitenv
|
|
36
45
|
end
|
37
46
|
|
38
47
|
def status
|
48
|
+
backup_notice = if @backup; " backup the file and"; end
|
39
49
|
if File.symlink? link
|
40
50
|
current_target = File.expand_path File.readlink(link)
|
41
|
-
if @overwrite == false
|
51
|
+
if @overwrite == false || current_target == target
|
42
52
|
Status.ok 'ok'
|
43
53
|
elsif !@overwrite
|
44
54
|
Status.error "exists but points to #{current_target}; enable overwrite if you want to replace it"
|
55
|
+
elsif @backup && File.exist?(link_backup)
|
56
|
+
Status.error "already exists with backup copy"
|
45
57
|
else
|
46
|
-
Status.warning "currently points to #{current_target}; apply will overwrite"
|
58
|
+
Status.warning "currently points to #{current_target}; apply will#{backup_notice} overwrite"
|
59
|
+
end
|
60
|
+
elsif File.exist? link
|
61
|
+
if @overwrite
|
62
|
+
Status.warning "exists but is not a symlink; apply will#{backup_notice} overwrite"
|
63
|
+
else
|
64
|
+
Status.error "exists but is not a symlink; apply will ignore"
|
47
65
|
end
|
48
|
-
elsif File.exists? link
|
49
|
-
Status.error "exists but is not a symlink; apply will ignore"
|
50
66
|
else
|
51
67
|
Status.missing "is not set up; apply will create the link"
|
52
68
|
end
|
@@ -56,6 +72,10 @@ module Gitenv
|
|
56
72
|
@link ||= File.join(*[ @context.to, link_name].compact)
|
57
73
|
end
|
58
74
|
|
75
|
+
def link_backup
|
76
|
+
@link_backup ||= "#{link}.orig"
|
77
|
+
end
|
78
|
+
|
59
79
|
def target
|
60
80
|
@target ||= File.join(*[ @context.from, @file ].compact)
|
61
81
|
end
|
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']
|
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: 0.
|
4
|
+
version: 0.3.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: 2016-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: paint
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '1.0'
|
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: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: commander
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '11.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: '
|
54
|
+
version: '11.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 0.
|
89
|
+
version: 0.9.0
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 0.
|
96
|
+
version: 0.9.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: jeweler
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,28 +114,28 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0
|
117
|
+
version: '1.0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0
|
124
|
+
version: '1.0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: simplecov
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 0.
|
131
|
+
version: 0.12.0
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 0.
|
138
|
+
version: 0.12.0
|
139
139
|
description: Gitenv sets up symlinks to your configuration files in a git repository.
|
140
140
|
email: git@alphahydrae.com
|
141
141
|
executables:
|
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
186
|
version: '0'
|
187
187
|
requirements: []
|
188
188
|
rubyforge_project:
|
189
|
-
rubygems_version: 2.
|
189
|
+
rubygems_version: 2.5.1
|
190
190
|
signing_key:
|
191
191
|
specification_version: 4
|
192
192
|
summary: Symlink manager for git repositories with configuration files.
|