gitenv 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ffb4ea926396af97597fa7f0e6ea09087b3bfc41
4
- data.tar.gz: 274f1ee44491aba02c54489064a48cd625afdf14
3
+ metadata.gz: c01b85f1089abd188b5127a3ee739ff9f0444d1c
4
+ data.tar.gz: 475c4c025297edc07a150d611fb946d33094c256
5
5
  SHA512:
6
- metadata.gz: 5311998ee8af20192519240910810029922e05462f768db0789307e24f7e782d78babfcdd067da0933a557fed9818637f44a4e682d8eb8c2af4ca00ebc3137e8
7
- data.tar.gz: 3c2cd2803a321b384ecff57dcba7d41807d511a03c5aef95513fa5d9cb203be5237ba7408f00ee8a67f9eb32987c1551234cf109f3af57dedd2bef7b6a22330b
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', '~> 0.9.0'
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
- gem 'rake', '~> 10.4'
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.6.3', :require => 'fakefs/safe'
16
+ gem 'fakefs', '~> 0.9.0', :require => 'fakefs/safe'
16
17
  gem 'jeweler', '~> 2.0'
17
- gem 'rake-version', '~> 0.4.1'
18
- gem 'simplecov', '~> 0.9.1'
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.2.0
1
+ 0.3.0
data/lib/gitenv.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  require 'paint'
3
3
 
4
4
  module Gitenv
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
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,34 @@ 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.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 or current_target == target
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
@@ -16,7 +16,7 @@ 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
 
@@ -103,7 +103,7 @@ module Gitenv
103
103
 
104
104
  def load_config_file!
105
105
  file = config_file
106
- return unless File.exists? 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.exists?(f)
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.exists?(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.exists?(@config.from) ? 'is not a directory' : 'does not exist'
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.2.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: 2015-01-14 00:00:00.000000000 Z
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: 0.9.0
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: 0.9.0
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: '10.4'
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: '10.4'
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.6.3
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.6.3
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.4.1
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.4.1
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.9.1
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.9.1
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.4.5
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.