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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ffb4ea926396af97597fa7f0e6ea09087b3bfc41
4
- data.tar.gz: 274f1ee44491aba02c54489064a48cd625afdf14
2
+ SHA256:
3
+ metadata.gz: 066334c209061edcd32f246eea29be949b62329779fb600b741546c6b033a3d0
4
+ data.tar.gz: 64e0c52f52bcc698762175fd3397854d4c42dfedf44f19f958a9eb77ca59cd70
5
5
  SHA512:
6
- metadata.gz: 5311998ee8af20192519240910810029922e05462f768db0789307e24f7e782d78babfcdd067da0933a557fed9818637f44a4e682d8eb8c2af4ca00ebc3137e8
7
- data.tar.gz: 3c2cd2803a321b384ecff57dcba7d41807d511a03c5aef95513fa5d9cb203be5237ba7408f00ee8a67f9eb32987c1551234cf109f3af57dedd2bef7b6a22330b
6
+ metadata.gz: 83feb9539ad0ae87f1e69dae0af1a97a15f1e1e79104dd521f8a8302ff657c62a13a571dd4d0c2b2ea0095d4f1253d4beb920d7c38505d53ce3e6d6c9ca2f923
7
+ data.tar.gz: fb87187285ae1614d3ba05035ac1459aa602e0b434929df379f4ae790bcde507d9c29aa064b6c77af1a812876c0537cd33c8cef06308be9eb7152d25c8240c0f
data/Gemfile CHANGED
@@ -1,19 +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.9.0'
7
- gem 'commander', '~> 4.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 'rake', '~> 10.4'
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.4.1'
18
- gem 'simplecov', '~> 0.9.1'
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
@@ -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.2.0
1
+ 1.1.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 = '1.1.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,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,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']
@@ -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,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: 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: 2015-01-14 00:00:00.000000000 Z
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: 0.9.0
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: 0.9.0
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.2'
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.2'
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: '10.4'
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: '10.4'
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.4.1
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.9.1
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
- rubyforge_project:
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.