gitenv 0.1.0 → 1.0.4

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b4d133584750e57a1bf6b8e5bc1f642607fba22f68d892005512b8583de1b676
4
+ data.tar.gz: 0a9b20396dbcc9fa44a2806c994571c0fce138a22dc5a1d4a2bb53d485231cb1
5
+ SHA512:
6
+ metadata.gz: a3a7efbb5ff8f3b3db7efbac8f57b72881d4bd122b5e6f984124d45df1b0c38476d68b4c420f7016bf27aacda184405d56d0b76ede57c7fa3fa2a570a4f4c196
7
+ data.tar.gz: 43e962d0973fa761cf13a890e1e12096cc5802e0f9e2bd938712b08243eb0c90a4e105b9d264347ce90efc91271fb7ccd1aa29ee92cc0d0075d98b6e4148179f
data/Gemfile CHANGED
@@ -1,21 +1,19 @@
1
- source "http://rubygems.org"
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', '~> 0.8.5'
7
- gem 'commander', '~> 4.1.2'
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 'bundler'
13
- gem 'rake'
14
- gem 'rspec'
15
- gem 'fakefs', '~> 0.4.2', :require => 'fakefs/safe'
16
- gem 'jeweler'
17
- gem 'gemcutter'
18
- gem 'gem-release'
19
- gem 'rake-version'
20
- gem 'simplecov'
7
+ gem 'rake', '~> 13.0'
8
+ gem 'jeweler', '~> 2.0'
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'
21
19
  end
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Alpha Hydrae
1
+ Copyright (c) 2011-2021 Simon Oulevay (Alpha Hydrae)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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
- 0.1.0
1
+ 1.0.4
data/lib/gitenv.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  require 'paint'
3
3
 
4
4
  module Gitenv
5
- VERSION = '0.1.0'
5
+ VERSION = '1.0.4'
6
6
  end
7
7
 
8
8
  Dir[File.join File.dirname(__FILE__), File.basename(__FILE__, '.*'), '*.rb'].each{ |lib| require lib }
@@ -3,7 +3,7 @@ module Gitenv
3
3
 
4
4
  class Action
5
5
  attr_reader :options
6
-
6
+
7
7
  def initialize context, type, files, options
8
8
  @context, @type, @files, @options = context, type, files, options
9
9
  end
@@ -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
- @backup = true if @overwrite and !options.key?(:backup)
33
+ @mkdir = options.fetch :mkdir, true
34
+ @backup = true if @overwrite && !options.key?(:backup)
34
35
  end
35
36
 
36
37
  def apply
37
- backup_exists = File.exists? target_backup
38
- FileUtils.mv target, target_backup if @backup and File.exists?(target) and !backup_exists
39
- FileUtils.rm target if @overwrite and File.exists?(target) and !backup_exists
40
- FileUtils.cp origin, target unless File.exists?(target)
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.exists?(target)
51
+ if !File.exist?(target)
49
52
  Status.missing "is not set up; apply will create the copy"
50
- elsif @overwrite == false or digest(origin) == digest(target)
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 and File.exists?(target_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 overwrite = true
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.rm link if @overwrite and File.symlink?(link) # FIXME: only if link points somewhere else
31
- File.symlink target, link unless File.symlink?(link) or File.exists?(link)
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 or current_target == target
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 = {}
@@ -6,7 +6,7 @@ module Gitenv
6
6
  attr_accessor :ignores
7
7
 
8
8
  def initialize config, options = {}
9
- @config, @from, @ignores = config, options[:from], options[:ignores]
9
+ @config, @from = config, options[:from]
10
10
 
11
11
  @to ||= File.expand_path('~')
12
12
 
@@ -16,10 +16,13 @@ module Gitenv
16
16
 
17
17
  check_config_file!
18
18
 
19
- if !File.exists?(config_file) and !repository
19
+ if !File.exist?(config_file) and !repository
20
20
  create_config_file!
21
21
  end
22
22
 
23
+ repo = repository
24
+ @config.from repo if repo && !repo.empty?
25
+
23
26
  load_config_file!
24
27
 
25
28
  #@config.from repository
@@ -85,7 +88,7 @@ module Gitenv
85
88
  end
86
89
 
87
90
  def repository
88
- @options.repo || @config.from || ENV['GITENV_REPO']
91
+ @options.repo || ENV['GITENV_REPO']
89
92
  end
90
93
 
91
94
  def config_file
@@ -100,7 +103,7 @@ module Gitenv
100
103
 
101
104
  def load_config_file!
102
105
  file = config_file
103
- return unless File.exists? file
106
+ return unless File.exist? file
104
107
  contents = File.open(file, 'r').read
105
108
  @config.instance_eval contents, file
106
109
  end
@@ -109,7 +112,7 @@ module Gitenv
109
112
  problems = []
110
113
  @config.actions.each do |a|
111
114
  a.each_file do |f|
112
- if !File.exists?(f)
115
+ if !File.exist?(f)
113
116
  problems << { :file => f, :msg => "does not exist" }
114
117
  #elsif !File.file?(f)
115
118
  # problems << { :file => f, :msg => "is not a file" }
@@ -130,7 +133,7 @@ module Gitenv
130
133
 
131
134
  def check_config_file!
132
135
  file = config_file
133
- return if !File.exists?(file)
136
+ return if !File.exist?(file)
134
137
  if !File.file?(file)
135
138
  abort "#{file} is not a file. It cannot be used as a configuration file."
136
139
  elsif !File.readable?(file)
@@ -147,7 +150,7 @@ module Gitenv
147
150
  abort msg
148
151
  end
149
152
  return if File.directory? @config.from
150
- notice = File.exists?(@config.from) ? 'is not a directory' : 'does not exist'
153
+ notice = File.exist?(@config.from) ? 'is not a directory' : 'does not exist'
151
154
  from = if @options.repo
152
155
  "--repo #{@options.repo}"
153
156
  elsif ENV['GITENV_REPO']
@@ -1,8 +1,5 @@
1
-
2
1
  module Gitenv
3
-
4
2
  class FilesMatcher
5
-
6
3
  def initialize options = {}
7
4
  @options = options
8
5
  @ignores = options[:ignores] ? [ options[:ignores] ].flatten : []
@@ -1,8 +1,5 @@
1
-
2
1
  module Gitenv
3
-
4
2
  class OneFile < FilesMatcher
5
-
6
3
  def initialize file, options = {}
7
4
  super options
8
5
  @file = file
@@ -1,10 +1,13 @@
1
-
2
1
  module Gitenv
3
-
4
2
  class Repository
3
+ attr_reader :path
5
4
 
6
5
  def initialize path
7
6
  @path = path
8
7
  end
8
+
9
+ def == other
10
+ other.path == path
11
+ end
9
12
  end
10
13
  end
metadata CHANGED
@@ -1,194 +1,87 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 1.0.4
6
5
  platform: ruby
7
6
  authors:
8
- - AlphaHydrae
7
+ - Simon Oulevay (Alpha Hydrae)
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-13 00:00:00.000000000 Z
11
+ date: 2021-07-19 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: paint
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: 0.8.5
19
+ version: '2.2'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: 0.8.5
26
+ version: '2.2'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: commander
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
- version: 4.1.2
33
+ version: '4.6'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
- version: 4.1.2
46
- - !ruby/object:Gem::Dependency
47
- name: bundler
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
40
+ version: '4.6'
62
41
  - !ruby/object:Gem::Dependency
63
42
  name: rake
64
43
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
79
- name: rspec
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '0'
86
- type: :development
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
- - !ruby/object:Gem::Dependency
95
- name: fakefs
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
44
  requirements:
99
- - - ~>
45
+ - - "~>"
100
46
  - !ruby/object:Gem::Version
101
- version: 0.4.2
47
+ version: '13.0'
102
48
  type: :development
103
49
  prerelease: false
104
50
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
51
  requirements:
107
- - - ~>
52
+ - - "~>"
108
53
  - !ruby/object:Gem::Version
109
- version: 0.4.2
54
+ version: '13.0'
110
55
  - !ruby/object:Gem::Dependency
111
56
  name: jeweler
112
57
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
58
  requirements:
115
- - - ! '>='
59
+ - - "~>"
116
60
  - !ruby/object:Gem::Version
117
- version: '0'
61
+ version: '2.0'
118
62
  type: :development
119
63
  prerelease: false
120
64
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
65
  requirements:
123
- - - ! '>='
66
+ - - "~>"
124
67
  - !ruby/object:Gem::Version
125
- version: '0'
126
- - !ruby/object:Gem::Dependency
127
- name: gemcutter
128
- requirement: !ruby/object:Gem::Requirement
129
- none: false
130
- requirements:
131
- - - ! '>='
132
- - !ruby/object:Gem::Version
133
- version: '0'
134
- type: :development
135
- prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ! '>='
140
- - !ruby/object:Gem::Version
141
- version: '0'
142
- - !ruby/object:Gem::Dependency
143
- name: gem-release
144
- requirement: !ruby/object:Gem::Requirement
145
- none: false
146
- requirements:
147
- - - ! '>='
148
- - !ruby/object:Gem::Version
149
- version: '0'
150
- type: :development
151
- prerelease: false
152
- version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
- requirements:
155
- - - ! '>='
156
- - !ruby/object:Gem::Version
157
- version: '0'
68
+ version: '2.0'
158
69
  - !ruby/object:Gem::Dependency
159
70
  name: rake-version
160
71
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
- requirements:
163
- - - ! '>='
164
- - !ruby/object:Gem::Version
165
- version: '0'
166
- type: :development
167
- prerelease: false
168
- version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
- requirements:
171
- - - ! '>='
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
- - !ruby/object:Gem::Dependency
175
- name: simplecov
176
- requirement: !ruby/object:Gem::Requirement
177
- none: false
178
72
  requirements:
179
- - - ! '>='
73
+ - - "~>"
180
74
  - !ruby/object:Gem::Version
181
- version: '0'
75
+ version: '1.0'
182
76
  type: :development
183
77
  prerelease: false
184
78
  version_requirements: !ruby/object:Gem::Requirement
185
- none: false
186
79
  requirements:
187
- - - ! '>='
80
+ - - "~>"
188
81
  - !ruby/object:Gem::Version
189
- version: '0'
82
+ version: '1.0'
190
83
  description: Gitenv sets up symlinks to your configuration files in a git repository.
191
- email: hydrae.alpha@gmail.com
84
+ email: git@alphahydrae.com
192
85
  executables:
193
86
  - gitenv
194
87
  extensions: []
@@ -220,27 +113,24 @@ files:
220
113
  homepage: http://github.com/AlphaHydrae/gitenv
221
114
  licenses:
222
115
  - MIT
116
+ metadata: {}
223
117
  post_install_message:
224
118
  rdoc_options: []
225
119
  require_paths:
226
120
  - lib
227
121
  required_ruby_version: !ruby/object:Gem::Requirement
228
- none: false
229
122
  requirements:
230
- - - ! '>='
123
+ - - ">="
231
124
  - !ruby/object:Gem::Version
232
125
  version: '0'
233
126
  required_rubygems_version: !ruby/object:Gem::Requirement
234
- none: false
235
127
  requirements:
236
- - - ! '>='
128
+ - - ">="
237
129
  - !ruby/object:Gem::Version
238
130
  version: '0'
239
131
  requirements: []
240
- rubyforge_project:
241
- rubygems_version: 1.8.25
132
+ rubygems_version: 3.2.15
242
133
  signing_key:
243
- specification_version: 3
134
+ specification_version: 4
244
135
  summary: Symlink manager for git repositories with configuration files.
245
136
  test_files: []
246
- has_rdoc: