Apply fixes suggested by Rubocop.
This commit is contained in:
@@ -5,9 +5,7 @@ module Homesick
|
||||
def mv(source, destination)
|
||||
source = Pathname.new(source)
|
||||
destination = Pathname.new(destination + source.basename)
|
||||
if destination.exist? && (options[:force] || shell.file_collision(destination) { source })
|
||||
say_status :conflict, "#{destination} exists", :red
|
||||
end
|
||||
say_status :conflict, "#{destination} exists", :red if destination.exist? && (options[:force] || shell.file_collision(destination) { source })
|
||||
FileUtils.mv source, destination unless options[:pretend]
|
||||
end
|
||||
|
||||
@@ -42,41 +40,36 @@ module Homesick
|
||||
destination = Pathname.new(destination)
|
||||
FileUtils.mkdir_p destination.dirname
|
||||
|
||||
action = if destination.symlink? && destination.readlink == source
|
||||
:identical
|
||||
elsif destination.symlink?
|
||||
:symlink_conflict
|
||||
elsif destination.exist?
|
||||
:conflict
|
||||
else
|
||||
:success
|
||||
end
|
||||
action = :success
|
||||
action = :identical if destination.symlink? && destination.readlink == source
|
||||
action = :symlink_conflict if destination.symlink?
|
||||
action = :conflict if destination.exist?
|
||||
|
||||
handle_symlink_action action, source, destination
|
||||
end
|
||||
|
||||
def handle_symlink_action(action, source, destination)
|
||||
case action
|
||||
when :identical
|
||||
if action == :identical
|
||||
say_status :identical, destination.expand_path, :blue
|
||||
when :symlink_conflict, :conflict
|
||||
if action == :conflict
|
||||
say_status :conflict, "#{destination} exists", :red
|
||||
else
|
||||
say_status :conflict,
|
||||
"#{destination} exists and points to #{destination.readlink}",
|
||||
:red
|
||||
end
|
||||
return
|
||||
end
|
||||
message = generate_symlink_message action, source, destination
|
||||
if %i[symlink_conflict conflict].include?(action)
|
||||
say_status :conflict, message, :red
|
||||
if collision_accepted?(destination, source)
|
||||
FileUtils.rm_r destination, force: true unless options[:pretend]
|
||||
FileUtils.ln_s source, destination, force: true unless options[:pretend]
|
||||
end
|
||||
else
|
||||
say_status :symlink,
|
||||
"#{source.expand_path} to #{destination.expand_path}",
|
||||
:green
|
||||
FileUtils.ln_s source, destination unless options[:pretend]
|
||||
say_status :symlink, message, :green
|
||||
end
|
||||
FileUtils.ln_s source, destination, force: true unless options[:pretend]
|
||||
end
|
||||
|
||||
def generate_symlink_message(action, source, destination)
|
||||
message = "#{source.expand_path} to #{destination.expand_path}"
|
||||
message = "#{destination} exists and points to #{destination.readlink}" if action == :symlink_conflict
|
||||
message = "#{destination} exists" if action == :conflict
|
||||
message
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- encoding : utf-8 -*-
|
||||
module Homesick
|
||||
module Actions
|
||||
# Git-related helper methods for Homesick
|
||||
@@ -8,18 +7,20 @@ module Homesick
|
||||
major: 1,
|
||||
minor: 8,
|
||||
patch: 0
|
||||
}
|
||||
}.freeze
|
||||
STRING = MIN_VERSION.values.join('.')
|
||||
|
||||
def git_version_correct?
|
||||
info = `git --version`.scan(/(\d+)\.(\d+)\.(\d+)/).flatten.map(&:to_i)
|
||||
return false unless info.count == 3
|
||||
current_version = Hash[[:major, :minor, :patch].zip(info)]
|
||||
return true if current_version.eql?(MIN_VERSION)
|
||||
return true if current_version[:major] > MIN_VERSION[:major]
|
||||
return true if current_version[:major] == MIN_VERSION[:major] && current_version[:minor] > MIN_VERSION[:minor]
|
||||
return true if current_version[:major] == MIN_VERSION[:major] && current_version[:minor] == MIN_VERSION[:minor] && current_version[:patch] >= MIN_VERSION[:patch]
|
||||
false
|
||||
|
||||
current_version = Hash[%i[major minor patch].zip(info)]
|
||||
major_equals = current_version.eql?(MIN_VERSION)
|
||||
major_greater = current_version[:major] > MIN_VERSION[:major]
|
||||
minor_greater = current_version[:major] == MIN_VERSION[:major] && current_version[:minor] > MIN_VERSION[:minor]
|
||||
patch_greater = current_version[:major] == MIN_VERSION[:major] && current_version[:minor] == MIN_VERSION[:minor] && current_version[:patch] >= MIN_VERSION[:patch]
|
||||
|
||||
major_equals || major_greater || minor_greater || patch_greater
|
||||
end
|
||||
|
||||
# TODO: move this to be more like thor's template, empty_directory, etc
|
||||
|
||||
Reference in New Issue
Block a user