Merge pull request #82 from thenickperson/rubocop-fixes

Reduce Rubocop errors
This commit is contained in:
Christian Bundy
2014-01-23 12:19:57 -08:00
6 changed files with 251 additions and 131 deletions

View File

@@ -1,7 +1,8 @@
# -*- encoding : utf-8 -*-
class Homesick
# Git-related and file-related helper methods for the Homesick class
module Actions
# TODO move this to be more like thor's template, empty_directory, etc
# TODO: move this to be more like thor's template, empty_directory, etc
def git_clone(repo, config = {})
config ||= {}
destination = config[:destination] || File.basename(repo, '.git')
@@ -9,11 +10,13 @@ class Homesick
destination = Pathname.new(destination) unless destination.kind_of?(Pathname)
FileUtils.mkdir_p destination.dirname
if ! destination.directory?
say_status 'git clone', "#{repo} to #{destination.expand_path}", :green unless options[:quiet]
system "git clone -q --config push.default=upstream --recursive #{repo} #{destination}" unless options[:pretend]
else
if destination.directory?
say_status :exist, destination.expand_path, :blue unless options[:quiet]
else
say_status 'git clone',
"#{repo} to #{destination.expand_path}",
:green unless options[:quiet]
system "git clone -q --config push.default=upstream --recursive #{repo} #{destination}" unless options[:pretend]
end
end
@@ -21,11 +24,11 @@ class Homesick
path = Pathname.new(path)
inside path do
if !path.join('.git').exist?
if path.join('.git').exist?
say_status 'git init', 'already initialized', :blue unless options[:quiet]
else
say_status 'git init', '' unless options[:quiet]
system 'git init >/dev/null' unless options[:pretend]
else
say_status 'git init', 'already initialized', :blue unless options[:quiet]
end
end
end
@@ -34,11 +37,11 @@ class Homesick
existing_remote = `git config remote.#{name}.url`.chomp
existing_remote = nil if existing_remote == ''
if !existing_remote
if existing_remote
say_status 'git remote', "#{name} already exists", :blue unless options[:quiet]
else
say_status 'git remote', "add #{name} #{url}" unless options[:quiet]
system "git remote add #{name} #{url}" unless options[:pretend]
else
say_status 'git remote', "#{name} already exists", :blue unless options[:quiet]
end
end
@@ -78,12 +81,12 @@ class Homesick
def git_status(config = {})
say_status 'git status', '', :green unless options[:quiet]
system "git status" unless options[:pretend]
system 'git status' unless options[:pretend]
end
def git_diff(config = {})
say_status 'git diff', '', :green unless options[:quiet]
system "git diff" unless options[:pretend]
system 'git diff' unless options[:pretend]
end
def mv(source, destination, config = {})
@@ -93,9 +96,7 @@ class Homesick
if destination.exist?
say_status :conflict, "#{destination} exists", :red unless options[:quiet]
if options[:force] || shell.file_collision(destination) { source }
system "mv '#{source}' '#{destination}'" unless options[:pretend]
end
system "mv '#{source}' '#{destination}'" if (options[:force] || shell.file_collision(destination) { source }) && !options[:pretend]
else
# this needs some sort of message here.
system "mv '#{source}' '#{destination}'" unless options[:pretend]
@@ -133,25 +134,40 @@ class Homesick
destination = Pathname.new(destination)
FileUtils.mkdir_p destination.dirname
if destination.symlink?
if destination.readlink == source
say_status :identical, destination.expand_path, :blue unless options[:quiet]
else
say_status :conflict, "#{destination} exists and points to #{destination.readlink}", :red unless options[:quiet]
action = if destination.symlink? && destination.readlink == source
:identical
elsif destination.symlink?
:symlink_conflict
elsif destination.exist?
:conflict
else
:success
end
if options[:force] || shell.file_collision(destination) { source }
system "ln -nsf '#{source}' '#{destination}'" unless options[:pretend]
end
end
elsif destination.exist?
handle_symlink_action action, source, destination
end
def handle_symlink_action(action, source, destination)
case action
when :identical
say_status :identical, destination.expand_path, :blue unless options[:quiet]
when :symlink_conflict
say_status :conflict,
"#{destination} exists and points to #{destination.readlink}",
:red unless options[:quiet]
system "ln -nsf '#{source}' '#{destination}'" if collision_accepted?
when :conflict
say_status :conflict, "#{destination} exists", :red unless options[:quiet]
if options[:force] || shell.file_collision(destination) { source }
if collision_accepted?
system "rm -rf '#{destination}'" unless options[:pretend]
system "ln -sf '#{source}' '#{destination}'" unless options[:pretend]
end
else
say_status :symlink, "#{source.expand_path} to #{destination.expand_path}", :green unless options[:quiet]
say_status :symlink,
"#{source.expand_path} to #{destination.expand_path}",
:green unless options[:quiet]
system "ln -s '#{source}' '#{destination}'" unless options[:pretend]
end
end

View File

@@ -1,7 +1,6 @@
class Homesick
# Hack in support for diffing symlinks
class Shell < Thor::Shell::Color
def show_diff(destination, content)
destination = Pathname.new(destination)
@@ -12,6 +11,5 @@ class Homesick
super
end
end
end
end

View File

@@ -1,5 +1,7 @@
# -*- encoding : utf-8 -*-
class Homesick
# A representation of Homesick's version number in constants, including a
# String of the entire version number
module Version
MAJOR = 1
MINOR = 0