From e202b7eae776024f292fd3e226d91d745721de65 Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Sat, 4 Jan 2014 20:20:10 -0500 Subject: [PATCH 01/18] Add a rubocop todo-style config created by "--auto-gen-config" and inherit it --- .rubocop.yml | 1 + rubocop-todo.yml | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 .rubocop.yml create mode 100644 rubocop-todo.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..137ead8 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1 @@ +inherit_from: rubocop-todo.yml diff --git a/rubocop-todo.yml b/rubocop-todo.yml new file mode 100644 index 0000000..f7f8ebc --- /dev/null +++ b/rubocop-todo.yml @@ -0,0 +1,66 @@ +# This configuration was generated by `rubocop --auto-gen-config`. +# The point is for the user to remove these configuration records +# one by one as the offences are removed from the code base. + +BlockAlignment: + Enabled: false + +BlockNesting: + Max: 4 + +ClassLength: + Max: 352 + +CommentAnnotation: + Enabled: false + +CyclomaticComplexity: + Max: 16 + +Documentation: + Enabled: false + +EmptyLinesAroundBody: + Enabled: false + +Eval: + Enabled: false + +FavorUnlessOverNegatedIf: + Enabled: false + +HashSyntax: + Enabled: false + +IndentationWidth: + Enabled: false + +LineLength: + Max: 174 + +MethodLength: + Max: 31 + +PerlBackrefs: + Enabled: false + +RedundantReturn: + Enabled: false + +RegexpLiteral: + Enabled: false + +SignalException: + Enabled: false + +SpaceAfterComma: + Enabled: false + +SpaceAfterNot: + Enabled: false + +SpaceAroundBlockBraces: + Enabled: false + +StringLiterals: + Enabled: false From f03e7670cf1c04f36ca70eb1bf870f8bf69f5658 Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Sat, 4 Jan 2014 20:39:44 -0500 Subject: [PATCH 02/18] Fix an issue reported by rubocop that wasn't ignored in the todo config Issue text: Favor modifier if/unless usage when you have a single-line body. --- lib/homesick.rb | 4 +--- lib/homesick/actions.rb | 8 ++------ rubocop-todo.yml | 5 +---- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/lib/homesick.rb b/lib/homesick.rb index 039de4a..c33bb8f 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -31,9 +31,7 @@ class Homesick < Thor destination = nil if File.exist?(uri) uri = Pathname.new(uri).expand_path - if uri.to_s.start_with?(repos_dir.to_s) - raise "Castle already cloned to #{uri}" - end + raise "Castle already cloned to #{uri}" if uri.to_s.start_with?(repos_dir.to_s) destination = uri.basename diff --git a/lib/homesick/actions.rb b/lib/homesick/actions.rb index b079325..e73ed4d 100644 --- a/lib/homesick/actions.rb +++ b/lib/homesick/actions.rb @@ -93,9 +93,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] @@ -155,9 +153,7 @@ class Homesick else say_status :conflict, "#{destination} exists and points to #{destination.readlink}", :red unless options[:quiet] - if options[:force] || shell.file_collision(destination) { source } - system "ln -nsf '#{source}' '#{destination}'" unless options[:pretend] - end + system "ln -nsf '#{source}' '#{destination}'" if (options[:force] || shell.file_collision(destination) { source }) && !options[:pretend] end elsif destination.exist? say_status :conflict, "#{destination} exists", :red unless options[:quiet] diff --git a/rubocop-todo.yml b/rubocop-todo.yml index f7f8ebc..712dd03 100644 --- a/rubocop-todo.yml +++ b/rubocop-todo.yml @@ -5,11 +5,8 @@ BlockAlignment: Enabled: false -BlockNesting: - Max: 4 - ClassLength: - Max: 352 + Max: 350 CommentAnnotation: Enabled: false From fc2bbb1d6e2f3d37c7fed28e8fedacd859524744 Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Sat, 4 Jan 2014 21:57:14 -0500 Subject: [PATCH 03/18] Fix several rubocop issues with "rubocop -a" --- lib/homesick.rb | 41 ++++++++++++++---------------- lib/homesick/actions.rb | 6 ++--- lib/homesick/shell.rb | 2 -- rubocop-todo.yml | 27 -------------------- spec/homesick_spec.rb | 56 ++++++++++++++++++++--------------------- 5 files changed, 50 insertions(+), 82 deletions(-) diff --git a/lib/homesick.rb b/lib/homesick.rb index c33bb8f..68bd9f1 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -31,22 +31,22 @@ class Homesick < Thor destination = nil if File.exist?(uri) uri = Pathname.new(uri).expand_path - raise "Castle already cloned to #{uri}" if uri.to_s.start_with?(repos_dir.to_s) + fail "Castle already cloned to #{uri}" if uri.to_s.start_with?(repos_dir.to_s) destination = uri.basename ln_s uri, destination elsif uri =~ GITHUB_NAME_REPO_PATTERN destination = Pathname.new(uri).basename - git_clone "https://github.com/#{$1}.git", :destination => destination + git_clone "https://github.com/#{Regexp.last_match[1]}.git", destination: destination elsif uri =~ /%r([^%r]*?)(\.git)?\Z/ - destination = Pathname.new($1) + destination = Pathname.new(Regexp.last_match[1]) git_clone uri elsif uri =~ /[^:]+:([^:]+)(\.git)?\Z/ - destination = Pathname.new($1) + destination = Pathname.new(Regexp.last_match[1]) git_clone uri else - raise "Unknown URI format: #{uri}" + fail "Unknown URI format: #{uri}" end if destination.join('.gitmodules').exist? @@ -80,7 +80,7 @@ class Homesick < Thor end desc 'pull CASTLE', 'Update the specified castle' - method_option :all, :type => :boolean, :default => false, :required => false, :desc => 'Update all cloned castles' + method_option :all, type: :boolean, default: false, required: false, desc: 'Update all cloned castles' def pull(name = DEFAULT_CASTLE_NAME) if options[:all] inside_each_castle do |castle| @@ -90,13 +90,11 @@ class Homesick < Thor else update_castle name end - end desc 'commit CASTLE MESSAGE', "Commit the specified castle's changes" def commit(name = DEFAULT_CASTLE_NAME, message = nil) commit_castle name, message - end desc 'push CASTLE', 'Push the specified castle' @@ -122,7 +120,7 @@ class Homesick < Thor end desc 'symlink CASTLE', 'Symlinks all dotfiles from the specified castle' - method_option :force, :default => false, :desc => 'Overwrite existing conflicting symlinks without prompting.' + method_option :force, default: false, desc: 'Overwrite existing conflicting symlinks without prompting.' def symlink(name = DEFAULT_CASTLE_NAME) check_castle_existance(name, 'symlink') @@ -231,20 +229,19 @@ class Homesick < Thor end end - desc "destroy CASTLE", "Delete all symlinks and remove the cloned repository" + desc 'destroy CASTLE', 'Delete all symlinks and remove the cloned repository' def destroy(name) - check_castle_existance name, "destroy" + check_castle_existance name, 'destroy' - if shell.yes?("This will destroy your castle irreversible! Are you sure?") + if shell.yes?('This will destroy your castle irreversible! Are you sure?') unlink(name) rm_rf repos_dir.join(name) end - end - desc "cd CASTLE", "Open a new shell in the root of the given castle" + desc 'cd CASTLE', 'Open a new shell in the root of the given castle' def cd(castle = DEFAULT_CASTLE_NAME) - check_castle_existance castle, "cd" + check_castle_existance castle, 'cd' castle_dir = repos_dir.join(castle) say_status "cd #{castle_dir.realpath}", "Opening a new shell in castle '#{castle}'. To return to the original one exit from the new shell.", :green inside castle_dir do @@ -252,14 +249,14 @@ class Homesick < Thor end end - desc "open CASTLE", "Open your default editor in the root of the given castle" + desc 'open CASTLE', 'Open your default editor in the root of the given castle' def open(castle = DEFAULT_CASTLE_NAME) - if ! ENV['EDITOR'] - say_status :error,"The $EDITOR environment variable must be set to use this command", :red + if !ENV['EDITOR'] + say_status :error, 'The $EDITOR environment variable must be set to use this command', :red exit(1) end - check_castle_existance castle, "open" + check_castle_existance castle, 'open' castle_dir = repos_dir.join(castle) say_status "#{ENV['EDITOR']} #{castle_dir.realpath}", "Opening the root directory of castle '#{castle}' in editor '#{ENV['EDITOR']}'.", :green inside castle_dir do @@ -297,7 +294,7 @@ class Homesick < Thor def all_castles dirs = Pathname.glob("#{repos_dir}/**/.git", File::FNM_DOTMATCH) # reject paths that lie inside another castle, like git submodules - return dirs.reject do |dir| + dirs.reject do |dir| dirs.any? do |other| dir != other && dir.fnmatch(other.parent.join('*').to_s) end @@ -325,7 +322,7 @@ class Homesick < Thor def commit_castle(castle, message) check_castle_existance(castle, 'commit') inside repos_dir.join(castle) do - git_commit_all :message => message + git_commit_all message: message end end @@ -402,7 +399,7 @@ class Homesick < Thor def each_file(castle, basedir, subdirs) absolute_basedir = Pathname.new(basedir).expand_path inside basedir do - files = Pathname.glob('{.*,*}').reject{ |a| ['.', '..'].include?(a.to_s) } + files = Pathname.glob('{.*,*}').reject { |a| ['.', '..'].include?(a.to_s) } files.each do |path| absolute_path = path.expand_path castle_home = castle_dir(castle) diff --git a/lib/homesick/actions.rb b/lib/homesick/actions.rb index e73ed4d..2dc3488 100644 --- a/lib/homesick/actions.rb +++ b/lib/homesick/actions.rb @@ -9,7 +9,7 @@ class Homesick destination = Pathname.new(destination) unless destination.kind_of?(Pathname) FileUtils.mkdir_p destination.dirname - if ! destination.directory? + 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 @@ -78,12 +78,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 = {}) diff --git a/lib/homesick/shell.rb b/lib/homesick/shell.rb index 880801c..7bf1a65 100644 --- a/lib/homesick/shell.rb +++ b/lib/homesick/shell.rb @@ -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 diff --git a/rubocop-todo.yml b/rubocop-todo.yml index 712dd03..f5174f3 100644 --- a/rubocop-todo.yml +++ b/rubocop-todo.yml @@ -17,18 +17,12 @@ CyclomaticComplexity: Documentation: Enabled: false -EmptyLinesAroundBody: - Enabled: false - Eval: Enabled: false FavorUnlessOverNegatedIf: Enabled: false -HashSyntax: - Enabled: false - IndentationWidth: Enabled: false @@ -38,26 +32,5 @@ LineLength: MethodLength: Max: 31 -PerlBackrefs: - Enabled: false - -RedundantReturn: - Enabled: false - RegexpLiteral: Enabled: false - -SignalException: - Enabled: false - -SpaceAfterComma: - Enabled: false - -SpaceAfterNot: - Enabled: false - -SpaceAroundBlockBraces: - Enabled: false - -StringLiterals: - Enabled: false diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index 91a132a..05e7626 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -99,7 +99,7 @@ describe 'homesick' do end it 'should clone a github repo' do - homesick.should_receive(:git_clone).with('https://github.com/wfarr/dotfiles.git', :destination => Pathname.new('dotfiles')) + homesick.should_receive(:git_clone).with('https://github.com/wfarr/dotfiles.git', destination: Pathname.new('dotfiles')) homesick.clone 'wfarr/dotfiles' end @@ -165,7 +165,7 @@ describe 'homesick' do end context 'when forced' do - let(:homesick) { Homesick.new [], :force => true } + let(:homesick) { Homesick.new [], force: true } it 'can override symlinks to directories' do somewhere_else = create_construct @@ -237,7 +237,7 @@ describe 'homesick' do end end - context "when call with no castle name" do + context 'when call with no castle name' do let(:castle) { given_castle('dotfiles') } it 'using default castle name: "dotfiles"' do dotfile = castle.file('.some_dotfile') @@ -320,7 +320,7 @@ describe 'homesick' do end end - context "when call with no castle name" do + context 'when call with no castle name' do let(:castle) { given_castle('dotfiles') } it 'using default castle name: "dotfiles"' do @@ -484,7 +484,7 @@ describe 'homesick' do some_nested_dir.realpath.should == tracked_file.realpath end - context "when call with no castle name" do + context 'when call with no castle name' do it 'using default castle name: "dotfiles"' do castle = given_castle('dotfiles') @@ -553,62 +553,62 @@ describe 'homesick' do end end - describe "destroy" do - it "removes the symlink files" do + describe 'destroy' do + it 'removes the symlink files' do expect_any_instance_of(Thor::Shell::Basic).to receive(:yes?).and_return('y') - given_castle("stronghold") + given_castle('stronghold') some_rc_file = home.file '.some_rc_file' - homesick.track(some_rc_file.to_s, "stronghold") + homesick.track(some_rc_file.to_s, 'stronghold') homesick.destroy('stronghold') some_rc_file.should_not be_exist end - it "deletes the cloned repository" do + it 'deletes the cloned repository' do expect_any_instance_of(Thor::Shell::Basic).to receive(:yes?).and_return('y') - castle = given_castle("stronghold") + castle = given_castle('stronghold') some_rc_file = home.file '.some_rc_file' - homesick.track(some_rc_file.to_s, "stronghold") + homesick.track(some_rc_file.to_s, 'stronghold') homesick.destroy('stronghold') castle.should_not be_exist end end - describe "cd" do + describe 'cd' do it "cd's to the root directory of the given castle" do given_castle('castle_repo') - homesick.should_receive("inside").once.with(kind_of(Pathname)).and_yield - homesick.should_receive("system").once.with(ENV["SHELL"]) + homesick.should_receive('inside').once.with(kind_of(Pathname)).and_yield + homesick.should_receive('system').once.with(ENV['SHELL']) Capture.stdout { homesick.cd 'castle_repo' } end - it "returns an error message when the given castle does not exist" do - homesick.should_receive("say_status").once.with(:error, /Could not cd castle_repo, expected \/tmp\/construct_container.* exist and contain dotfiles/, :red) - expect { homesick.cd "castle_repo" }.to raise_error(SystemExit) + it 'returns an error message when the given castle does not exist' do + homesick.should_receive('say_status').once.with(:error, /Could not cd castle_repo, expected \/tmp\/construct_container.* exist and contain dotfiles/, :red) + expect { homesick.cd 'castle_repo' }.to raise_error(SystemExit) end end - describe "open" do - it "opens the system default editor in the root of the given castle" do + describe 'open' do + it 'opens the system default editor in the root of the given castle' do ENV.stub(:[]).and_call_original # Make sure calls to ENV use default values for most things... ENV.stub(:[]).with('EDITOR').and_return('vim') # Set a default value for 'EDITOR' just in case none is set given_castle 'castle_repo' - homesick.should_receive("inside").once.with(kind_of(Pathname)).and_yield - homesick.should_receive("system").once.with('vim') + homesick.should_receive('inside').once.with(kind_of(Pathname)).and_yield + homesick.should_receive('system').once.with('vim') Capture.stdout { homesick.open 'castle_repo' } end - it "returns an error message when the $EDITOR environment variable is not set" do + it 'returns an error message when the $EDITOR environment variable is not set' do ENV.stub(:[]).with('EDITOR').and_return(nil) # Set the default editor to make sure it fails. - homesick.should_receive("say_status").once.with(:error, "The $EDITOR environment variable must be set to use this command", :red) - expect { homesick.open "castle_repo" }.to raise_error(SystemExit) + homesick.should_receive('say_status').once.with(:error, 'The $EDITOR environment variable must be set to use this command', :red) + expect { homesick.open 'castle_repo' }.to raise_error(SystemExit) end - it "returns an error message when the given castle does not exist" do + it 'returns an error message when the given castle does not exist' do ENV.stub(:[]).with('EDITOR').and_return('vim') # Set a default just in case none is set - homesick.should_receive("say_status").once.with(:error, /Could not open castle_repo, expected \/tmp\/construct_container.* exist and contain dotfiles/, :red) - expect { homesick.open "castle_repo" }.to raise_error(SystemExit) + homesick.should_receive('say_status').once.with(:error, /Could not open castle_repo, expected \/tmp\/construct_container.* exist and contain dotfiles/, :red) + expect { homesick.open 'castle_repo' }.to raise_error(SystemExit) end end From 12244abb568d84efbf082007a0b51a09f1c2b93a Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Sat, 4 Jan 2014 22:09:28 -0500 Subject: [PATCH 04/18] Fix a few more syntax-related rubocop issues manually --- lib/homesick.rb | 4 ++-- lib/homesick/actions.rb | 2 +- rubocop-todo.yml | 15 --------------- spec/homesick_spec.rb | 4 ++-- 4 files changed, 5 insertions(+), 20 deletions(-) diff --git a/lib/homesick.rb b/lib/homesick.rb index 68bd9f1..a4fdc18 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -251,7 +251,7 @@ class Homesick < Thor desc 'open CASTLE', 'Open your default editor in the root of the given castle' def open(castle = DEFAULT_CASTLE_NAME) - if !ENV['EDITOR'] + unless ENV['EDITOR'] say_status :error, 'The $EDITOR environment variable must be set to use this command', :red exit(1) @@ -427,7 +427,7 @@ class Homesick < Thor home_path = home_dir.join(relative_dir).join(path) yield(absolute_path, home_path) - end + end end end diff --git a/lib/homesick/actions.rb b/lib/homesick/actions.rb index 2dc3488..bf20a9e 100644 --- a/lib/homesick/actions.rb +++ b/lib/homesick/actions.rb @@ -1,7 +1,7 @@ # -*- encoding : utf-8 -*- class Homesick 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') diff --git a/rubocop-todo.yml b/rubocop-todo.yml index f5174f3..7ecb968 100644 --- a/rubocop-todo.yml +++ b/rubocop-todo.yml @@ -2,15 +2,9 @@ # The point is for the user to remove these configuration records # one by one as the offences are removed from the code base. -BlockAlignment: - Enabled: false - ClassLength: Max: 350 -CommentAnnotation: - Enabled: false - CyclomaticComplexity: Max: 16 @@ -20,17 +14,8 @@ Documentation: Eval: Enabled: false -FavorUnlessOverNegatedIf: - Enabled: false - -IndentationWidth: - Enabled: false - LineLength: Max: 174 MethodLength: Max: 31 - -RegexpLiteral: - Enabled: false diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index 05e7626..6c68f16 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -584,7 +584,7 @@ describe 'homesick' do end it 'returns an error message when the given castle does not exist' do - homesick.should_receive('say_status').once.with(:error, /Could not cd castle_repo, expected \/tmp\/construct_container.* exist and contain dotfiles/, :red) + homesick.should_receive('say_status').once.with(:error, %r{Could not cd castle_repo, expected /tmp/construct_container.* exist and contain dotfiles}, :red) expect { homesick.cd 'castle_repo' }.to raise_error(SystemExit) end end @@ -607,7 +607,7 @@ describe 'homesick' do it 'returns an error message when the given castle does not exist' do ENV.stub(:[]).with('EDITOR').and_return('vim') # Set a default just in case none is set - homesick.should_receive('say_status').once.with(:error, /Could not open castle_repo, expected \/tmp\/construct_container.* exist and contain dotfiles/, :red) + homesick.should_receive('say_status').once.with(:error, %r{Could not open castle_repo, expected /tmp/construct_container.* exist and contain dotfiles}, :red) expect { homesick.open 'castle_repo' }.to raise_error(SystemExit) end end From 8f634b9d079a9a7ba89939cbaac02b17180edce6 Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Sat, 4 Jan 2014 22:46:44 -0500 Subject: [PATCH 05/18] Add brief documentation comments for Homesick and Homesick::Actions --- lib/homesick.rb | 1 + lib/homesick/actions.rb | 1 + rubocop-todo.yml | 3 --- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/homesick.rb b/lib/homesick.rb index a4fdc18..026d6e6 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -1,6 +1,7 @@ # -*- encoding : utf-8 -*- require 'thor' +# Homesick's command line interface (with some helper methods) class Homesick < Thor autoload :Shell, 'homesick/shell' autoload :Actions, 'homesick/actions' diff --git a/lib/homesick/actions.rb b/lib/homesick/actions.rb index bf20a9e..239c33e 100644 --- a/lib/homesick/actions.rb +++ b/lib/homesick/actions.rb @@ -1,5 +1,6 @@ # -*- 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 def git_clone(repo, config = {}) diff --git a/rubocop-todo.yml b/rubocop-todo.yml index 7ecb968..225b514 100644 --- a/rubocop-todo.yml +++ b/rubocop-todo.yml @@ -8,9 +8,6 @@ ClassLength: CyclomaticComplexity: Max: 16 -Documentation: - Enabled: false - Eval: Enabled: false From 7d36460851d536a84fa7657b9cad0c8429ca2771 Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Sat, 4 Jan 2014 23:10:07 -0500 Subject: [PATCH 06/18] Rename the todo config to .rubocop.yml, now that more rubocop issues are fixed --- .rubocop.yml | 19 ++++++++++++++++++- rubocop-todo.yml | 18 ------------------ 2 files changed, 18 insertions(+), 19 deletions(-) delete mode 100644 rubocop-todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index 137ead8..b429de0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1 +1,18 @@ -inherit_from: rubocop-todo.yml +# This configuration was generated by `rubocop --auto-gen-config`. +# The point is for the user to remove these configuration records +# one by one as the offences are removed from the code base. + +ClassLength: + Enabled: false + +CyclomaticComplexity: + Max: 16 + +Eval: + Enabled: false + +LineLength: + Max: 174 + +MethodLength: + Max: 31 diff --git a/rubocop-todo.yml b/rubocop-todo.yml deleted file mode 100644 index 225b514..0000000 --- a/rubocop-todo.yml +++ /dev/null @@ -1,18 +0,0 @@ -# This configuration was generated by `rubocop --auto-gen-config`. -# The point is for the user to remove these configuration records -# one by one as the offences are removed from the code base. - -ClassLength: - Max: 350 - -CyclomaticComplexity: - Max: 16 - -Eval: - Enabled: false - -LineLength: - Max: 174 - -MethodLength: - Max: 31 From 604a3b2a20a9c80475d4699d2d722c42a3fa94ba Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Sun, 5 Jan 2014 00:48:57 -0500 Subject: [PATCH 07/18] Add todo comments to the rubocop config --- .rubocop.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index b429de0..65c6cf8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,10 @@ -# This configuration was generated by `rubocop --auto-gen-config`. -# The point is for the user to remove these configuration records -# one by one as the offences are removed from the code base. +# TODO: Eval is required for the .homesickrc feature. This should eventually be +# removed if the feature is implemented in a more secure way. +Eval: + Enabled: false + +# TODO: The following settings disable reports about issues that can be fixed +# through refactoring. Remove these as offenses are removed from the code base. ClassLength: Enabled: false @@ -8,9 +12,6 @@ ClassLength: CyclomaticComplexity: Max: 16 -Eval: - Enabled: false - LineLength: Max: 174 From 571c5799e92fbe1c10fd408b6f6d76b73fe8b84f Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Mon, 6 Jan 2014 21:04:25 -0500 Subject: [PATCH 08/18] Swap some if/else statements so the positive case is always first --- lib/homesick/actions.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/homesick/actions.rb b/lib/homesick/actions.rb index 239c33e..096aad4 100644 --- a/lib/homesick/actions.rb +++ b/lib/homesick/actions.rb @@ -10,11 +10,11 @@ class Homesick destination = Pathname.new(destination) unless destination.kind_of?(Pathname) FileUtils.mkdir_p destination.dirname - if !destination.directory? + 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] - else - say_status :exist, destination.expand_path, :blue unless options[:quiet] end end @@ -22,11 +22,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 @@ -35,11 +35,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 From c667cefd4cf8caa7cb4bd25b9592bf507a478850 Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Tue, 7 Jan 2014 02:48:50 -0500 Subject: [PATCH 09/18] Refactor the clone method to decrease its cyclomatic complexity --- .rubocop.yml | 4 ++-- lib/homesick.rb | 14 ++------------ lib/homesick/actions.rb | 11 +++++++++++ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 65c6cf8..b973d36 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,10 +10,10 @@ ClassLength: Enabled: false CyclomaticComplexity: - Max: 16 + Max: 9 LineLength: - Max: 174 + Max: 163 MethodLength: Max: 31 diff --git a/lib/homesick.rb b/lib/homesick.rb index 026d6e6..c707dfc 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -40,23 +40,13 @@ class Homesick < Thor elsif uri =~ GITHUB_NAME_REPO_PATTERN destination = Pathname.new(uri).basename git_clone "https://github.com/#{Regexp.last_match[1]}.git", destination: destination - elsif uri =~ /%r([^%r]*?)(\.git)?\Z/ + elsif uri =~ /%r([^%r]*?)(\.git)?\Z/ || uri =~ /[^:]+:([^:]+)(\.git)?\Z/ destination = Pathname.new(Regexp.last_match[1]) - git_clone uri - elsif uri =~ /[^:]+:([^:]+)(\.git)?\Z/ - destination = Pathname.new(Regexp.last_match[1]) - git_clone uri + git_clone uri, destination: destination else fail "Unknown URI format: #{uri}" end - if destination.join('.gitmodules').exist? - inside destination do - git_submodule_init - git_submodule_update - end - end - rc(destination) end end diff --git a/lib/homesick/actions.rb b/lib/homesick/actions.rb index 096aad4..c9d73e9 100644 --- a/lib/homesick/actions.rb +++ b/lib/homesick/actions.rb @@ -16,6 +16,17 @@ class Homesick 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 + + git_setup_submodules destination + end + + def git_setup_submodules(path) + if path.join('.gitmodules').exist? + inside path do + git_submodule_init + git_submodule_update + end + end end def git_init(path = '.') From 7e659f11fe7edb4ae63c8bef7feed64ba56e5dfa Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Tue, 7 Jan 2014 20:03:09 -0500 Subject: [PATCH 10/18] Fix some broken spec expectations and move/rename a method --- lib/homesick.rb | 15 +++++++++++++-- lib/homesick/actions.rb | 11 ----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/homesick.rb b/lib/homesick.rb index c707dfc..dde5198 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -42,12 +42,12 @@ class Homesick < Thor git_clone "https://github.com/#{Regexp.last_match[1]}.git", destination: destination elsif uri =~ /%r([^%r]*?)(\.git)?\Z/ || uri =~ /[^:]+:([^:]+)(\.git)?\Z/ destination = Pathname.new(Regexp.last_match[1]) - git_clone uri, destination: destination + git_clone uri else fail "Unknown URI format: #{uri}" end - rc(destination) + setup_castle(destination) end end @@ -433,4 +433,15 @@ class Homesick < Thor ln_s absolute_path, home_path end end + + def setup_castle(path) + if path.join('.gitmodules').exist? + inside path do + git_submodule_init + git_submodule_update + end + end + + rc(path) + end end diff --git a/lib/homesick/actions.rb b/lib/homesick/actions.rb index c9d73e9..096aad4 100644 --- a/lib/homesick/actions.rb +++ b/lib/homesick/actions.rb @@ -16,17 +16,6 @@ class Homesick 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 - - git_setup_submodules destination - end - - def git_setup_submodules(path) - if path.join('.gitmodules').exist? - inside path do - git_submodule_init - git_submodule_update - end - end end def git_init(path = '.') From e42eff4e10d8e64879a20e572b208c3a794dad3f Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Tue, 7 Jan 2014 20:12:53 -0500 Subject: [PATCH 11/18] Refactor the ln_s method to decrease its cyclomatic complexity --- .rubocop.yml | 2 +- lib/homesick.rb | 4 ++++ lib/homesick/actions.rb | 14 ++++++-------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index b973d36..1b7634b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,7 +10,7 @@ ClassLength: Enabled: false CyclomaticComplexity: - Max: 9 + Max: 7 LineLength: Max: 163 diff --git a/lib/homesick.rb b/lib/homesick.rb index dde5198..628ef24 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -387,6 +387,10 @@ class Homesick < Thor first_p.mtime > second_p.mtime && !first_p.symlink? end + def collision_accepted? + options[:force] || shell.file_collision(destination) { source } + end + def each_file(castle, basedir, subdirs) absolute_basedir = Pathname.new(basedir).expand_path inside basedir do diff --git a/lib/homesick/actions.rb b/lib/homesick/actions.rb index 096aad4..3bfd4e2 100644 --- a/lib/homesick/actions.rb +++ b/lib/homesick/actions.rb @@ -148,18 +148,16 @@ 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] + if destination.symlink? && destination.readlink == source + say_status :identical, destination.expand_path, :blue unless options[:quiet] + elsif destination.symlink? + say_status :conflict, "#{destination} exists and points to #{destination.readlink}", :red unless options[:quiet] - system "ln -nsf '#{source}' '#{destination}'" if (options[:force] || shell.file_collision(destination) { source }) && !options[:pretend] - end + smart_system "ln -nsf '#{source}' '#{destination}'" if collision_accepted? elsif destination.exist? 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 From 0bbb82f9ba6b1b9303c15a4ee7e0cc31524bec66 Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Wed, 8 Jan 2014 21:31:59 -0500 Subject: [PATCH 12/18] Wrap all lines of Ruby code to 79 characters (maximum) --- .rubocop.yml | 5 +- lib/homesick.rb | 68 +++++++++++++++++------ lib/homesick/actions.rb | 30 ++++++++--- spec/homesick_spec.rb | 116 +++++++++++++++++++++++++++++----------- spec/spec_helper.rb | 3 +- 5 files changed, 162 insertions(+), 60 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1b7634b..ebddc05 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,8 +12,5 @@ ClassLength: CyclomaticComplexity: Max: 7 -LineLength: - Max: 163 - MethodLength: - Max: 31 + Max: 36 diff --git a/lib/homesick.rb b/lib/homesick.rb index 628ef24..ec14750 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -32,14 +32,16 @@ class Homesick < Thor destination = nil if File.exist?(uri) uri = Pathname.new(uri).expand_path - fail "Castle already cloned to #{uri}" if uri.to_s.start_with?(repos_dir.to_s) + fail "Castle already cloned to #{uri}" \ + if uri.to_s.start_with?(repos_dir.to_s) destination = uri.basename ln_s uri, destination elsif uri =~ GITHUB_NAME_REPO_PATTERN destination = Pathname.new(uri).basename - git_clone "https://github.com/#{Regexp.last_match[1]}.git", destination: destination + git_clone "https://github.com/#{Regexp.last_match[1]}.git", + destination: destination elsif uri =~ /%r([^%r]*?)(\.git)?\Z/ || uri =~ /[^:]+:([^:]+)(\.git)?\Z/ destination = Pathname.new(Regexp.last_match[1]) git_clone uri @@ -57,21 +59,28 @@ class Homesick < Thor destination = Pathname.new(name) homesickrc = destination.join('.homesickrc').expand_path if homesickrc.exist? - proceed = shell.yes?("#{name} has a .homesickrc. Proceed with evaling it? (This could be destructive)") + proceed = shell.yes?("#{name} has a .homesickrc. Proceed with "\ + "evaling it? (This could be destructive)") if proceed shell.say_status 'eval', homesickrc inside destination do eval homesickrc.read, binding, homesickrc.expand_path.to_s end else - shell.say_status 'eval skip', "not evaling #{homesickrc}, #{destination} may need manual configuration", :blue + shell.say_status 'eval skip', "not evaling #{homesickrc}, " \ + "#{destination} may need manual " \ + "configuration", :blue end end end end desc 'pull CASTLE', 'Update the specified castle' - method_option :all, type: :boolean, default: false, required: false, desc: 'Update all cloned castles' + method_option :all, + type: :boolean, + default: false, + required: false, + desc: 'Update all cloned castles' def pull(name = DEFAULT_CASTLE_NAME) if options[:all] inside_each_castle do |castle| @@ -111,7 +120,10 @@ class Homesick < Thor end desc 'symlink CASTLE', 'Symlinks all dotfiles from the specified castle' - method_option :force, default: false, desc: 'Overwrite existing conflicting symlinks without prompting.' + method_option :force, + default: false, + desc: 'Overwrite existing conflicting symlinks without ' \ + 'prompting.' def symlink(name = DEFAULT_CASTLE_NAME) check_castle_existance(name, 'symlink') @@ -151,7 +163,11 @@ class Homesick < Thor target.delete mv absolute_path, castle_path else - shell.say_status(:track, "#{target} already exists, and is more recent than #{file}. Run 'homesick SYMLINK CASTLE' to create symlinks.", :blue) unless options[:quiet] + shell.say_status(:track, + "#{target} already exists, and is more recent " \ + "than #{file}. Run 'homesick SYMLINK CASTLE' " \ + "to create symlinks.", + :blue) unless options[:quiet] end else mv absolute_path, castle_path @@ -168,13 +184,16 @@ class Homesick < Thor end # are we tracking something nested? Add the parent dir to the manifest - subdir_add(castle, relative_dir) unless relative_dir.eql?(Pathname.new('.')) + subdir_add(castle, relative_dir) \ + unless relative_dir.eql?(Pathname.new('.')) end desc 'list', 'List cloned castles' def list inside_each_castle do |castle| - say_status castle.relative_path_from(repos_dir).to_s, `git config remote.origin.url`.chomp, :cyan + say_status castle.relative_path_from(repos_dir).to_s, + `git config remote.origin.url`.chomp, + :cyan end end @@ -234,22 +253,32 @@ class Homesick < Thor def cd(castle = DEFAULT_CASTLE_NAME) check_castle_existance castle, 'cd' castle_dir = repos_dir.join(castle) - say_status "cd #{castle_dir.realpath}", "Opening a new shell in castle '#{castle}'. To return to the original one exit from the new shell.", :green + say_status "cd #{castle_dir.realpath}", + "Opening a new shell in castle '#{castle}'. To return to the " \ + "original one exit from the new shell.", + :green inside castle_dir do system(ENV['SHELL']) end end - desc 'open CASTLE', 'Open your default editor in the root of the given castle' + desc 'open CASTLE', + 'Open your default editor in the root of the given castle' def open(castle = DEFAULT_CASTLE_NAME) unless ENV['EDITOR'] - say_status :error, 'The $EDITOR environment variable must be set to use this command', :red + say_status :error, + 'The $EDITOR environment variable must be set to use ' \ + 'this command', + :red exit(1) end check_castle_existance castle, 'open' castle_dir = repos_dir.join(castle) - say_status "#{ENV['EDITOR']} #{castle_dir.realpath}", "Opening the root directory of castle '#{castle}' in editor '#{ENV['EDITOR']}'.", :green + say_status "#{ENV['EDITOR']} #{castle_dir.realpath}", + "Opening the root directory of castle '#{castle}' in editor " \ + "'#{ENV['EDITOR']}'.", + :green inside castle_dir do system(ENV['EDITOR']) end @@ -276,7 +305,10 @@ class Homesick < Thor def check_castle_existance(name, action) unless castle_dir(name).exist? - say_status :error, "Could not #{action} #{name}, expected #{castle_dir(name)} exist and contain dotfiles", :red + say_status :error, + "Could not #{action} #{name}, expected " \ + "#{castle_dir(name)} exist and contain dotfiles", + :red exit(1) end @@ -355,7 +387,9 @@ class Homesick < Thor def subdir_remove(castle, path) subdir_filepath = subdir_file(castle) if subdir_filepath.exist? - lines = IO.readlines(subdir_filepath).delete_if { |line| line == "#{path}\n" } + lines = IO.readlines(subdir_filepath).delete_if do |line| + line == "#{path}\n" + end File.open(subdir_filepath, 'w') { |manfile| manfile.puts lines } end @@ -394,7 +428,9 @@ class Homesick < Thor def each_file(castle, basedir, subdirs) absolute_basedir = Pathname.new(basedir).expand_path inside basedir do - files = Pathname.glob('{.*,*}').reject { |a| ['.', '..'].include?(a.to_s) } + files = Pathname.glob('{.*,*}').reject do + |a| ['.', '..'].include?(a.to_s) + end files.each do |path| absolute_path = path.expand_path castle_home = castle_dir(castle) diff --git a/lib/homesick/actions.rb b/lib/homesick/actions.rb index 3bfd4e2..775f932 100644 --- a/lib/homesick/actions.rb +++ b/lib/homesick/actions.rb @@ -7,14 +7,18 @@ class Homesick config ||= {} destination = config[:destination] || File.basename(repo, '.git') - destination = Pathname.new(destination) unless destination.kind_of?(Pathname) + destination = Pathname.new(destination) \ + unless destination.kind_of?(Pathname) FileUtils.mkdir_p destination.dirname 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] + 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 @@ -50,7 +54,8 @@ class Homesick def git_submodule_update(config = {}) say_status 'git submodule', 'update', :green unless options[:quiet] - system 'git submodule --quiet update --init --recursive >/dev/null 2>&1' unless options[:pretend] + system 'git submodule --quiet update --init --recursive ' \ + '>/dev/null 2>&1' unless options[:pretend] end def git_pull(config = {}) @@ -94,7 +99,10 @@ class Homesick if destination.exist? say_status :conflict, "#{destination} exists", :red unless options[:quiet] - system "mv '#{source}' '#{destination}'" if (options[:force] || shell.file_collision(destination) { source }) && !options[:pretend] + 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] @@ -151,9 +159,13 @@ class Homesick if destination.symlink? && destination.readlink == source say_status :identical, destination.expand_path, :blue unless options[:quiet] elsif destination.symlink? - say_status :conflict, "#{destination} exists and points to #{destination.readlink}", :red unless options[:quiet] + say_status :conflict, + "#{destination} exists and points to " \ + "#{destination.readlink}", + :red unless options[:quiet] - smart_system "ln -nsf '#{source}' '#{destination}'" if collision_accepted? + smart_system "ln -nsf '#{source}' '#{destination}'" \ + if collision_accepted? elsif destination.exist? say_status :conflict, "#{destination} exists", :red unless options[:quiet] @@ -162,7 +174,9 @@ class Homesick 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 diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index 6c68f16..35e8d59 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -18,7 +18,9 @@ describe 'homesick' do somewhere = create_construct local_repo = somewhere.directory('some_repo') local_repo.file('.homesickrc') do |file| - file << "File.open(Dir.pwd + '/testing', 'w') { |f| f.print 'testing' }" + file << "File.open(Dir.pwd + '/testing', 'w') do + |f| f.print 'testing' + end" end expect($stdout).to receive(:print) @@ -48,7 +50,8 @@ describe 'homesick' do it 'should raise an error' do homesick.should_not_receive(:git_clone) - expect { homesick.clone @existing_dir.to_s }.to raise_error(/already cloned/i) + expect { homesick.clone @existing_dir.to_s }.to \ + raise_error(/already cloned/i) end end end @@ -56,33 +59,39 @@ describe 'homesick' do it 'should clone git repo like file:///path/to.git' do bare_repo = File.join(create_construct.to_s, 'dotfiles.git') system "git init --bare #{bare_repo} >/dev/null 2>&1" + # Capture stderr to suppress message about cloning an empty repo. Capture.stderr do homesick.clone "file://#{bare_repo}" end - File.directory?(File.join(home.to_s, '.homesick/repos/dotfiles')).should be_true + File.directory?(File.join(home.to_s, '.homesick/repos/dotfiles')) + .should be_true end it 'should clone git repo like git://host/path/to.git' do - homesick.should_receive(:git_clone).with('git://github.com/technicalpickles/pickled-vim.git') + homesick.should_receive(:git_clone) + .with('git://github.com/technicalpickles/pickled-vim.git') homesick.clone 'git://github.com/technicalpickles/pickled-vim.git' end it 'should clone git repo like git@host:path/to.git' do - homesick.should_receive(:git_clone).with('git@github.com:technicalpickles/pickled-vim.git') + homesick.should_receive(:git_clone) + .with('git@github.com:technicalpickles/pickled-vim.git') homesick.clone 'git@github.com:technicalpickles/pickled-vim.git' end it 'should clone git repo like http://host/path/to.git' do - homesick.should_receive(:git_clone).with('http://github.com/technicalpickles/pickled-vim.git') + homesick.should_receive(:git_clone) + .with('http://github.com/technicalpickles/pickled-vim.git') homesick.clone 'http://github.com/technicalpickles/pickled-vim.git' end it 'should clone git repo like http://host/path/to' do - homesick.should_receive(:git_clone).with('http://github.com/technicalpickles/pickled-vim') + homesick.should_receive(:git_clone) + .with('http://github.com/technicalpickles/pickled-vim') homesick.clone 'http://github.com/technicalpickles/pickled-vim' end @@ -93,13 +102,16 @@ describe 'homesick' do homesick.clone 'gitolite:pickled-vim.git' end - it 'should throw an exception when trying to clone a malformed uri like malformed' do + it 'should throw an exception when trying to clone a malformed uri like ' \ + 'malformed' do homesick.should_not_receive(:git_clone) expect { homesick.clone 'malformed' }.to raise_error end it 'should clone a github repo' do - homesick.should_receive(:git_clone).with('https://github.com/wfarr/dotfiles.git', destination: Pathname.new('dotfiles')) + homesick.should_receive(:git_clone) + .with('https://github.com/wfarr/dotfiles.git', + destination: Pathname.new('dotfiles')) homesick.clone 'wfarr/dotfiles' end @@ -116,7 +128,9 @@ describe 'homesick' do it 'executes the .homesickrc' do castle.file('.homesickrc') do |file| - file << "File.open(Dir.pwd + '/testing', 'w') { |f| f.print 'testing' }" + file << "File.open(Dir.pwd + '/testing', 'w') do + |f| f.print 'testing' + end" end expect_any_instance_of(Thor::Shell::Basic).to receive(:say_status).with('eval', kind_of(Pathname)) @@ -134,7 +148,9 @@ describe 'homesick' do it 'does not execute the .homesickrc' do castle.file('.homesickrc') do |file| - file << "File.open(Dir.pwd + '/testing', 'w') { |f| f.print 'testing' }" + file << "File.open(Dir.pwd + '/testing', 'w') do + |f| f.print 'testing' + end" end expect_any_instance_of(Thor::Shell::Basic).to receive(:say_status).with('eval skip', /not evaling.+/, :blue) @@ -219,7 +235,9 @@ describe 'homesick' do end context "with '.config' and '.config/someapp' in .homesick_subdir" do - let(:castle) { given_castle('glencairn', ['.config', '.config/someapp']) } + let(:castle) do + given_castle('glencairn', ['.config', '.config/someapp']) + end it 'can symlink under both of .config and .config/someapp' do config_dir = castle.directory('.config') config_dotfile = config_dir.file('.some_dotfile') @@ -231,9 +249,11 @@ describe 'homesick' do home_config_dir = home.join('.config') home_someapp_dir = home_config_dir.join('someapp') home_config_dir.symlink?.should be == false - home_config_dir.join('.some_dotfile').readlink.should be == config_dotfile + home_config_dir.join('.some_dotfile').readlink + .should be == config_dotfile home_someapp_dir.symlink?.should be == false - home_someapp_dir.join('.some_appfile').readlink.should == someapp_dotfile + home_someapp_dir.join('.some_appfile').readlink + .should == someapp_dotfile end end @@ -301,7 +321,9 @@ describe 'homesick' do end context "with '.config' and '.config/someapp' in .homesick_subdir" do - let(:castle) { given_castle('glencairn', ['.config', '.config/someapp']) } + let(:castle) do + given_castle('glencairn', ['.config', '.config/someapp']) + end it 'can unsymlink under both of .config and .config/someapp' do config_dir = castle.directory('.config') @@ -339,8 +361,14 @@ describe 'homesick' do given_castle('zomg') given_castle('wtf/zomg') - homesick.should_receive(:say_status).with('zomg', 'git://github.com/technicalpickles/zomg.git', :cyan) - homesick.should_receive(:say_status).with('wtf/zomg', 'git://github.com/technicalpickles/zomg.git', :cyan) + homesick.should_receive(:say_status) + .with('zomg', + 'git://github.com/technicalpickles/zomg.git', + :cyan) + homesick.should_receive(:say_status) + .with('wtf/zomg', + 'git://github.com/technicalpickles/zomg.git', + :cyan) homesick.list end @@ -350,7 +378,8 @@ describe 'homesick' do it 'should say "nothing to commit" when there are no changes' do given_castle('castle_repo') text = Capture.stdout { homesick.status('castle_repo') } - text.should =~ /nothing to commit \(create\/copy files and use "git add" to track\)$/ + text.should =~ Regexp.new('nothing to commit \(create\/copy files and ' \ + 'use "git add" to track\)$') end it 'should say "Changes to be committed" when there are changes' do @@ -358,7 +387,8 @@ describe 'homesick' do some_rc_file = home.file '.some_rc_file' homesick.track(some_rc_file.to_s, 'castle_repo') text = Capture.stdout { homesick.status('castle_repo') } - text.should =~ /Changes to be committed:.*new file:\s*home\/.some_rc_file/m + text.should =~ + /Changes to be committed:.*new file:\s*home\/.some_rc_file/m end end @@ -504,11 +534,15 @@ describe 'homesick' do given_castle('castle_repo') some_rc_file = home.file '.a_random_rc_file' homesick.track(some_rc_file.to_s, 'castle_repo') - text = Capture.stdout { homesick.commit('castle_repo', 'Test message') } + text = Capture.stdout do + homesick.commit('castle_repo', 'Test message') + end text.should =~ /^\[master \(root-commit\) \w+\] Test message/ end end + # Note that this is a test for the subdir_file related feature of track, + # not for the subdir_file method itself. describe 'subdir_file' do it 'should add the nested files parent to the subdir_file' do @@ -537,7 +571,8 @@ describe 'homesick' do end end - it 'should remove the parent of a tracked file from the subdir_file if the parent itself is tracked' do + it 'should remove the parent of a tracked file from the subdir_file ' \ + 'if the parent itself is tracked' do castle = given_castle('castle_repo') some_nested_file = home.file('some/nested/file.txt') @@ -555,7 +590,8 @@ describe 'homesick' do describe 'destroy' do it 'removes the symlink files' do - expect_any_instance_of(Thor::Shell::Basic).to receive(:yes?).and_return('y') + expect_any_instance_of(Thor::Shell::Basic).to \ + receive(:yes?).and_return('y') given_castle('stronghold') some_rc_file = home.file '.some_rc_file' homesick.track(some_rc_file.to_s, 'stronghold') @@ -565,7 +601,8 @@ describe 'homesick' do end it 'deletes the cloned repository' do - expect_any_instance_of(Thor::Shell::Basic).to receive(:yes?).and_return('y') + expect_any_instance_of(Thor::Shell::Basic).to \ + receive(:yes?).and_return('y') castle = given_castle('stronghold') some_rc_file = home.file '.some_rc_file' homesick.track(some_rc_file.to_s, 'stronghold') @@ -584,30 +621,47 @@ describe 'homesick' do end it 'returns an error message when the given castle does not exist' do - homesick.should_receive('say_status').once.with(:error, %r{Could not cd castle_repo, expected /tmp/construct_container.* exist and contain dotfiles}, :red) + homesick.should_receive('say_status').once + .with(:error, + Regexp.new('Could not cd castle_repo, expected ' \ + '/tmp/construct_container.* exist and contain dotfiles'), + :red) expect { homesick.cd 'castle_repo' }.to raise_error(SystemExit) end end describe 'open' do it 'opens the system default editor in the root of the given castle' do - ENV.stub(:[]).and_call_original # Make sure calls to ENV use default values for most things... - ENV.stub(:[]).with('EDITOR').and_return('vim') # Set a default value for 'EDITOR' just in case none is set + # Make sure calls to ENV use default values for most things... + ENV.stub(:[]).and_call_original + # Set a default value for 'EDITOR' just in case none is set + ENV.stub(:[]).with('EDITOR').and_return('vim') given_castle 'castle_repo' homesick.should_receive('inside').once.with(kind_of(Pathname)).and_yield homesick.should_receive('system').once.with('vim') Capture.stdout { homesick.open 'castle_repo' } end - it 'returns an error message when the $EDITOR environment variable is not set' do - ENV.stub(:[]).with('EDITOR').and_return(nil) # Set the default editor to make sure it fails. - homesick.should_receive('say_status').once.with(:error, 'The $EDITOR environment variable must be set to use this command', :red) + it 'returns an error message when the $EDITOR environment variable is ' \ + 'not set' do + # Set the default editor to make sure it fails. + ENV.stub(:[]).with('EDITOR').and_return(nil) + homesick.should_receive('say_status').once + .with(:error, + 'The $EDITOR environment variable must be set to use '\ + 'this command', + :red) expect { homesick.open 'castle_repo' }.to raise_error(SystemExit) end it 'returns an error message when the given castle does not exist' do - ENV.stub(:[]).with('EDITOR').and_return('vim') # Set a default just in case none is set - homesick.should_receive('say_status').once.with(:error, %r{Could not open castle_repo, expected /tmp/construct_container.* exist and contain dotfiles}, :red) + # Set a default just in case none is set + ENV.stub(:[]).with('EDITOR').and_return('vim') + homesick.should_receive('say_status').once + .with(:error, + Regexp.new('Could not open castle_repo, expected ' \ + '/tmp/construct_container.* exist and contain dotfiles'), + :red) expect { homesick.open 'castle_repo' }.to raise_error(SystemExit) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e594897..aed4112 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -24,7 +24,8 @@ RSpec.configure do |config| system 'git init >/dev/null 2>&1' system 'git config user.email "test@test.com"' system 'git config user.name "Test Name"' - system "git remote add origin git://github.com/technicalpickles/#{name}.git >/dev/null 2>&1" + system "git remote add origin " \ + "git://github.com/technicalpickles/#{name}.git >/dev/null 2>&1" if subdirs subdir_file = castle.join(Homesick::SUBDIR_FILENAME) subdirs.each do |subdir| From bb735763c6db5da6015cf6e5ce298c54bb0af390 Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Thu, 9 Jan 2014 01:00:40 -0500 Subject: [PATCH 13/18] Separate the action handling of ln_s into a new method to lower complexity --- .rubocop.yml | 3 --- lib/homesick/actions.rb | 24 +++++++++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index ebddc05..7a9badf 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,8 +9,5 @@ Eval: ClassLength: Enabled: false -CyclomaticComplexity: - Max: 7 - MethodLength: Max: 36 diff --git a/lib/homesick/actions.rb b/lib/homesick/actions.rb index 775f932..3829e26 100644 --- a/lib/homesick/actions.rb +++ b/lib/homesick/actions.rb @@ -156,17 +156,31 @@ class Homesick destination = Pathname.new(destination) FileUtils.mkdir_p destination.dirname - if destination.symlink? && destination.readlink == source + action = if destination.symlink? && destination.readlink == source + :identical + elsif destination.symlink? + :symlink_conflict + elsif destination.exist? + :conflict + else + :success + end + + 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] - elsif destination.symlink? + when :symlink_conflict say_status :conflict, "#{destination} exists and points to " \ "#{destination.readlink}", :red unless options[:quiet] - smart_system "ln -nsf '#{source}' '#{destination}'" \ - if collision_accepted? - elsif destination.exist? + system "ln -nsf '#{source}' '#{destination}'" if collision_accepted? + when :conflict say_status :conflict, "#{destination} exists", :red unless options[:quiet] if collision_accepted? From 82be04ad8a5078e583a556b579ec19c425a5a681 Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Wed, 15 Jan 2014 23:13:48 -0500 Subject: [PATCH 14/18] Fix rubocop issues for some recently merged code --- lib/homesick/actions.rb | 33 ++++++++++++++-------- lib/homesick/version.rb | 2 ++ spec/homesick_spec.rb | 62 ++++++++++++++++++++++++++++------------- 3 files changed, 67 insertions(+), 30 deletions(-) diff --git a/lib/homesick/actions.rb b/lib/homesick/actions.rb index 3829e26..bdae043 100644 --- a/lib/homesick/actions.rb +++ b/lib/homesick/actions.rb @@ -12,7 +12,8 @@ class Homesick FileUtils.mkdir_p destination.dirname if destination.directory? - say_status :exist, destination.expand_path, :blue unless options[:quiet] + say_status :exist, destination.expand_path, :blue \ + unless options[:quiet] else say_status 'git clone', "#{repo} to #{destination.expand_path}", @@ -27,7 +28,8 @@ class Homesick inside path do if path.join('.git').exist? - say_status 'git init', 'already initialized', :blue unless options[:quiet] + 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] @@ -40,7 +42,8 @@ class Homesick existing_remote = nil if existing_remote == '' if existing_remote - say_status 'git remote', "#{name} already exists", :blue unless options[:quiet] + 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] @@ -71,7 +74,8 @@ class Homesick def git_commit_all(config = {}) say_status 'git commit all', '', :green unless options[:quiet] if config[:message] - system "git commit -a -m '#{config[:message]}'" unless options[:pretend] + system "git commit -a -m '#{config[:message]}'" \ + unless options[:pretend] else system 'git commit -v -a' unless options[:pretend] end @@ -97,7 +101,8 @@ class Homesick destination = Pathname.new(destination + source.basename) if destination.exist? - say_status :conflict, "#{destination} exists", :red unless options[:quiet] + say_status :conflict, "#{destination} exists", :red \ + unless options[:quiet] system "mv '#{source}' '#{destination}'" \ if (options[:force] || @@ -113,10 +118,12 @@ class Homesick target = Pathname.new(target) if target.symlink? - say_status :unlink, "#{target.expand_path}", :green unless options[:quiet] + say_status :unlink, "#{target.expand_path}", :green \ + unless options[:quiet] FileUtils.rm_rf target else - say_status :conflict, "#{target} is not a symlink", :red unless options[:quiet] + say_status :conflict, "#{target} is not a symlink", :red \ + unless options[:quiet] end end @@ -134,10 +141,12 @@ class Homesick target = Pathname.new(target) if target.symlink? - say_status :unlink, "#{target.expand_path}", :green unless options[:quiet] + say_status :unlink, "#{target.expand_path}", :green \ + unless options[:quiet] FileUtils.rm_rf target else - say_status :conflict, "#{target} is not a symlink", :red unless options[:quiet] + say_status :conflict, "#{target} is not a symlink", :red \ + unless options[:quiet] end end @@ -172,7 +181,8 @@ class Homesick def handle_symlink_action(action, source, destination) case action when :identical - say_status :identical, destination.expand_path, :blue unless options[:quiet] + say_status :identical, destination.expand_path, :blue \ + unless options[:quiet] when :symlink_conflict say_status :conflict, "#{destination} exists and points to " \ @@ -181,7 +191,8 @@ class Homesick system "ln -nsf '#{source}' '#{destination}'" if collision_accepted? when :conflict - say_status :conflict, "#{destination} exists", :red unless options[:quiet] + say_status :conflict, "#{destination} exists", :red \ + unless options[:quiet] if collision_accepted? system "rm -rf '#{destination}'" unless options[:pretend] diff --git a/lib/homesick/version.rb b/lib/homesick/version.rb index a81902d..5c5dfcb 100644 --- a/lib/homesick/version.rb +++ b/lib/homesick/version.rb @@ -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 diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index 35e8d59..6650dd1 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -25,7 +25,8 @@ describe 'homesick' do expect($stdout).to receive(:print) expect($stdin).to receive(:gets).and_return('y') - expect_any_instance_of(Thor::Shell::Basic).to receive(:say_status).with('eval', kind_of(Pathname)) + expect_any_instance_of(Thor::Shell::Basic).to \ + receive(:say_status).with('eval', kind_of(Pathname)) homesick.clone local_repo castles.join('some_repo').join('testing').should exist @@ -102,8 +103,8 @@ describe 'homesick' do homesick.clone 'gitolite:pickled-vim.git' end - it 'should throw an exception when trying to clone a malformed uri like ' \ - 'malformed' do + it 'should throw an exception when trying to clone a malformed uri ' \ + 'like malformed' do homesick.should_not_receive(:git_clone) expect { homesick.clone 'malformed' }.to raise_error end @@ -133,7 +134,8 @@ describe 'homesick' do end" end - expect_any_instance_of(Thor::Shell::Basic).to receive(:say_status).with('eval', kind_of(Pathname)) + expect_any_instance_of(Thor::Shell::Basic).to \ + receive(:say_status).with('eval', kind_of(Pathname)) homesick.rc castle castle.join('testing').should exist @@ -153,7 +155,8 @@ describe 'homesick' do end" end - expect_any_instance_of(Thor::Shell::Basic).to receive(:say_status).with('eval skip', /not evaling.+/, :blue) + expect_any_instance_of(Thor::Shell::Basic).to \ + receive(:say_status).with('eval skip', /not evaling.+/, :blue) homesick.rc castle castle.join('testing').should_not exist @@ -397,7 +400,9 @@ describe 'homesick' do given_castle('castle_repo') some_rc_file = home.file '.some_rc_file' homesick.track(some_rc_file.to_s, 'castle_repo') - Capture.stdout { homesick.commit 'castle_repo', 'Adding a file to the test' } + Capture.stdout do + homesick.commit 'castle_repo', 'Adding a file to the test' + end text = Capture.stdout { homesick.diff('castle_repo') } text.should eq('') end @@ -406,9 +411,11 @@ describe 'homesick' do given_castle('castle_repo') some_rc_file = home.file '.some_rc_file' homesick.track(some_rc_file.to_s, 'castle_repo') - Capture.stdout { homesick.commit 'castle_repo', 'Adding a file to the test' } + Capture.stdout do + homesick.commit 'castle_repo', 'Adding a file to the test' + end File.open(some_rc_file.to_s, 'w') do |file| - file.puts "Some test text" + file.puts 'Some test text' end text = Capture.stdout { homesick.diff('castle_repo') } text.should =~ /diff --git.+Some test text$/m @@ -426,17 +433,24 @@ describe 'homesick' do end describe 'pull' do - it 'should perform a pull, submodule init and update when the given castle exists' do + it 'should perform a pull, submodule init and update when the given ' \ + 'castle exists' do given_castle('castle_repo') homesick.stub(:system).once.with('git pull --quiet') homesick.stub(:system).once.with('git submodule --quiet init') - homesick.stub(:system).once.with('git submodule --quiet update --init --recursive >/dev/null 2>&1') + homesick.stub(:system).once.with('git submodule --quiet update ' \ + '--init --recursive >/dev/null 2>&1') homesick.pull 'castle_repo' end - it 'should print an error message when trying to pull a non-existant castle' do - homesick.should_receive("say_status").once.with(:error, /Could not pull castle_repo, expected \/tmp\/construct_container.* exist and contain dotfiles/, :red) - expect { homesick.pull "castle_repo" }.to raise_error(SystemExit) + it 'should print an error message when trying to pull a non-existant ' \ + 'castle' do + homesick.should_receive('say_status').once + .with(:error, + Regexp.new('Could not pull castle_repo, expected ' \ + '/tmp/construct_container.* exist and contain dotfiles'), + :red) + expect { homesick.pull 'castle_repo' }.to raise_error(SystemExit) end describe '--all' do @@ -444,9 +458,14 @@ describe 'homesick' do given_castle('castle_repo') given_castle('glencairn') homesick.stub(:system).exactly(2).times.with('git pull --quiet') - homesick.stub(:system).exactly(2).times.with('git submodule --quiet init') - homesick.stub(:system).exactly(2).times.with('git submodule --quiet update --init --recursive >/dev/null 2>&1') - Capture.stdout { Capture.stderr { homesick.invoke 'pull', [], all: true } } + homesick.stub(:system).exactly(2).times + .with('git submodule --quiet init') + homesick.stub(:system).exactly(2).times + .with('git submodule --quiet update --init --recursive ' \ + '>/dev/null 2>&1') + Capture.stdout do + Capture.stderr { homesick.invoke 'pull', [], all: true } + end end end @@ -459,9 +478,14 @@ describe 'homesick' do homesick.push 'castle_repo' end - it 'should print an error message when trying to push a non-existant castle' do - homesick.should_receive("say_status").once.with(:error, /Could not push castle_repo, expected \/tmp\/construct_container.* exist and contain dotfiles/, :red) - expect { homesick.push "castle_repo" }.to raise_error(SystemExit) + it 'should print an error message when trying to push a non-existant '\ + 'castle' do + homesick.should_receive('say_status').once + .with(:error, + Regexp.new('Could not push castle_repo, expected ' \ + '/tmp/construct_container.* exist and contain dotfiles'), + :red) + expect { homesick.push 'castle_repo' }.to raise_error(SystemExit) end end From 81734291310feb025fef213630d2ae6e397392d2 Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Thu, 16 Jan 2014 00:30:42 -0500 Subject: [PATCH 15/18] Ignore the remaining cyclomatic complexity issues --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 7a9badf..005d569 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,5 +9,8 @@ Eval: ClassLength: Enabled: false +CyclomaticComplexity: + Max: 13 + MethodLength: Max: 36 From 08a71f657f607a1cac2d62ae40aef03abfa6f4ed Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Mon, 20 Jan 2014 16:03:18 -0500 Subject: [PATCH 16/18] Fix a minor code style issue where "do" wasn't on the same line as its params --- lib/homesick.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/homesick.rb b/lib/homesick.rb index ec14750..a007e1c 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -428,8 +428,8 @@ class Homesick < Thor def each_file(castle, basedir, subdirs) absolute_basedir = Pathname.new(basedir).expand_path inside basedir do - files = Pathname.glob('{.*,*}').reject do - |a| ['.', '..'].include?(a.to_s) + files = Pathname.glob('{.*,*}').reject do |a| + ['.', '..'].include?(a.to_s) end files.each do |path| absolute_path = path.expand_path From 95943deb820d3a26c8fd0aa13e4dbd4e31d81742 Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Mon, 20 Jan 2014 21:03:21 -0500 Subject: [PATCH 17/18] Revert changes that use "\" and disable the line length cop --- .rubocop.yml | 3 +++ lib/homesick.rb | 34 +++++++++-------------- lib/homesick/actions.rb | 50 +++++++++++----------------------- spec/homesick_spec.rb | 60 ++++++++++++++--------------------------- spec/spec_helper.rb | 3 +-- 5 files changed, 52 insertions(+), 98 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 005d569..67ee52d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,5 +12,8 @@ ClassLength: CyclomaticComplexity: Max: 13 +LineLength: + Enabled: false + MethodLength: Max: 36 diff --git a/lib/homesick.rb b/lib/homesick.rb index a007e1c..7b8d76f 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -32,8 +32,7 @@ class Homesick < Thor destination = nil if File.exist?(uri) uri = Pathname.new(uri).expand_path - fail "Castle already cloned to #{uri}" \ - if uri.to_s.start_with?(repos_dir.to_s) + fail "Castle already cloned to #{uri}" if uri.to_s.start_with?(repos_dir.to_s) destination = uri.basename @@ -59,17 +58,16 @@ class Homesick < Thor destination = Pathname.new(name) homesickrc = destination.join('.homesickrc').expand_path if homesickrc.exist? - proceed = shell.yes?("#{name} has a .homesickrc. Proceed with "\ - "evaling it? (This could be destructive)") + proceed = shell.yes?("#{name} has a .homesickrc. Proceed with evaling it? (This could be destructive)") if proceed shell.say_status 'eval', homesickrc inside destination do eval homesickrc.read, binding, homesickrc.expand_path.to_s end else - shell.say_status 'eval skip', "not evaling #{homesickrc}, " \ - "#{destination} may need manual " \ - "configuration", :blue + shell.say_status 'eval skip', + "not evaling #{homesickrc}, #{destination} may need manual configuration", + :blue end end end @@ -122,8 +120,7 @@ class Homesick < Thor desc 'symlink CASTLE', 'Symlinks all dotfiles from the specified castle' method_option :force, default: false, - desc: 'Overwrite existing conflicting symlinks without ' \ - 'prompting.' + desc: 'Overwrite existing conflicting symlinks without prompting.' def symlink(name = DEFAULT_CASTLE_NAME) check_castle_existance(name, 'symlink') @@ -164,9 +161,7 @@ class Homesick < Thor mv absolute_path, castle_path else shell.say_status(:track, - "#{target} already exists, and is more recent " \ - "than #{file}. Run 'homesick SYMLINK CASTLE' " \ - "to create symlinks.", + "#{target} already exists, and is more recent than #{file}. Run 'homesick SYMLINK CASTLE' to create symlinks.", :blue) unless options[:quiet] end else @@ -184,8 +179,7 @@ class Homesick < Thor end # are we tracking something nested? Add the parent dir to the manifest - subdir_add(castle, relative_dir) \ - unless relative_dir.eql?(Pathname.new('.')) + subdir_add(castle, relative_dir) unless relative_dir.eql?(Pathname.new('.')) end desc 'list', 'List cloned castles' @@ -254,8 +248,7 @@ class Homesick < Thor check_castle_existance castle, 'cd' castle_dir = repos_dir.join(castle) say_status "cd #{castle_dir.realpath}", - "Opening a new shell in castle '#{castle}'. To return to the " \ - "original one exit from the new shell.", + "Opening a new shell in castle '#{castle}'. To return to the original one exit from the new shell.", :green inside castle_dir do system(ENV['SHELL']) @@ -267,8 +260,7 @@ class Homesick < Thor def open(castle = DEFAULT_CASTLE_NAME) unless ENV['EDITOR'] say_status :error, - 'The $EDITOR environment variable must be set to use ' \ - 'this command', + 'The $EDITOR environment variable must be set to use this command', :red exit(1) @@ -276,8 +268,7 @@ class Homesick < Thor check_castle_existance castle, 'open' castle_dir = repos_dir.join(castle) say_status "#{ENV['EDITOR']} #{castle_dir.realpath}", - "Opening the root directory of castle '#{castle}' in editor " \ - "'#{ENV['EDITOR']}'.", + "Opening the root directory of castle '#{castle}' in editor '#{ENV['EDITOR']}'.", :green inside castle_dir do system(ENV['EDITOR']) @@ -306,8 +297,7 @@ class Homesick < Thor def check_castle_existance(name, action) unless castle_dir(name).exist? say_status :error, - "Could not #{action} #{name}, expected " \ - "#{castle_dir(name)} exist and contain dotfiles", + "Could not #{action} #{name}, expected #{castle_dir(name)} exist and contain dotfiles", :red exit(1) diff --git a/lib/homesick/actions.rb b/lib/homesick/actions.rb index bdae043..eb1eced 100644 --- a/lib/homesick/actions.rb +++ b/lib/homesick/actions.rb @@ -7,19 +7,16 @@ class Homesick config ||= {} destination = config[:destination] || File.basename(repo, '.git') - destination = Pathname.new(destination) \ - unless destination.kind_of?(Pathname) + destination = Pathname.new(destination) unless destination.kind_of?(Pathname) FileUtils.mkdir_p destination.dirname if destination.directory? - say_status :exist, destination.expand_path, :blue \ - unless options[:quiet] + 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] + system "git clone -q --config push.default=upstream --recursive #{repo} #{destination}" unless options[:pretend] end end @@ -28,8 +25,7 @@ class Homesick inside path do if path.join('.git').exist? - say_status 'git init', 'already initialized', :blue \ - unless options[:quiet] + 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] @@ -42,8 +38,7 @@ class Homesick existing_remote = nil if existing_remote == '' if existing_remote - say_status 'git remote', "#{name} already exists", :blue \ - unless options[:quiet] + 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] @@ -57,8 +52,7 @@ class Homesick def git_submodule_update(config = {}) say_status 'git submodule', 'update', :green unless options[:quiet] - system 'git submodule --quiet update --init --recursive ' \ - '>/dev/null 2>&1' unless options[:pretend] + system 'git submodule --quiet update --init --recursive >/dev/null 2>&1' unless options[:pretend] end def git_pull(config = {}) @@ -74,8 +68,7 @@ class Homesick def git_commit_all(config = {}) say_status 'git commit all', '', :green unless options[:quiet] if config[:message] - system "git commit -a -m '#{config[:message]}'" \ - unless options[:pretend] + system "git commit -a -m '#{config[:message]}'" unless options[:pretend] else system 'git commit -v -a' unless options[:pretend] end @@ -101,13 +94,9 @@ class Homesick destination = Pathname.new(destination + source.basename) if destination.exist? - say_status :conflict, "#{destination} exists", :red \ - unless options[:quiet] + say_status :conflict, "#{destination} exists", :red unless options[:quiet] - system "mv '#{source}' '#{destination}'" \ - if (options[:force] || - shell.file_collision(destination) { source }) && - !options[:pretend] + 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] @@ -118,12 +107,10 @@ class Homesick target = Pathname.new(target) if target.symlink? - say_status :unlink, "#{target.expand_path}", :green \ - unless options[:quiet] + say_status :unlink, "#{target.expand_path}", :green unless options[:quiet] FileUtils.rm_rf target else - say_status :conflict, "#{target} is not a symlink", :red \ - unless options[:quiet] + say_status :conflict, "#{target} is not a symlink", :red unless options[:quiet] end end @@ -141,12 +128,10 @@ class Homesick target = Pathname.new(target) if target.symlink? - say_status :unlink, "#{target.expand_path}", :green \ - unless options[:quiet] + say_status :unlink, "#{target.expand_path}", :green unless options[:quiet] FileUtils.rm_rf target else - say_status :conflict, "#{target} is not a symlink", :red \ - unless options[:quiet] + say_status :conflict, "#{target} is not a symlink", :red unless options[:quiet] end end @@ -181,18 +166,15 @@ class Homesick def handle_symlink_action(action, source, destination) case action when :identical - say_status :identical, destination.expand_path, :blue \ - unless options[:quiet] + say_status :identical, destination.expand_path, :blue unless options[:quiet] when :symlink_conflict say_status :conflict, - "#{destination} exists and points to " \ - "#{destination.readlink}", + "#{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] + say_status :conflict, "#{destination} exists", :red unless options[:quiet] if collision_accepted? system "rm -rf '#{destination}'" unless options[:pretend] diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index 6650dd1..1b7b7a0 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -25,8 +25,7 @@ describe 'homesick' do expect($stdout).to receive(:print) expect($stdin).to receive(:gets).and_return('y') - expect_any_instance_of(Thor::Shell::Basic).to \ - receive(:say_status).with('eval', kind_of(Pathname)) + expect_any_instance_of(Thor::Shell::Basic).to receive(:say_status).with('eval', kind_of(Pathname)) homesick.clone local_repo castles.join('some_repo').join('testing').should exist @@ -51,8 +50,7 @@ describe 'homesick' do it 'should raise an error' do homesick.should_not_receive(:git_clone) - expect { homesick.clone @existing_dir.to_s }.to \ - raise_error(/already cloned/i) + expect { homesick.clone @existing_dir.to_s }.to raise_error(/already cloned/i) end end end @@ -103,8 +101,7 @@ describe 'homesick' do homesick.clone 'gitolite:pickled-vim.git' end - it 'should throw an exception when trying to clone a malformed uri ' \ - 'like malformed' do + it 'should throw an exception when trying to clone a malformed uri like malformed' do homesick.should_not_receive(:git_clone) expect { homesick.clone 'malformed' }.to raise_error end @@ -134,8 +131,7 @@ describe 'homesick' do end" end - expect_any_instance_of(Thor::Shell::Basic).to \ - receive(:say_status).with('eval', kind_of(Pathname)) + expect_any_instance_of(Thor::Shell::Basic).to receive(:say_status).with('eval', kind_of(Pathname)) homesick.rc castle castle.join('testing').should exist @@ -155,8 +151,7 @@ describe 'homesick' do end" end - expect_any_instance_of(Thor::Shell::Basic).to \ - receive(:say_status).with('eval skip', /not evaling.+/, :blue) + expect_any_instance_of(Thor::Shell::Basic).to receive(:say_status).with('eval skip', /not evaling.+/, :blue) homesick.rc castle castle.join('testing').should_not exist @@ -381,8 +376,7 @@ describe 'homesick' do it 'should say "nothing to commit" when there are no changes' do given_castle('castle_repo') text = Capture.stdout { homesick.status('castle_repo') } - text.should =~ Regexp.new('nothing to commit \(create\/copy files and ' \ - 'use "git add" to track\)$') + text.should =~ /nothing to commit \(create\/copy files and use "git add" to track\)$/ end it 'should say "Changes to be committed" when there are changes' do @@ -433,22 +427,18 @@ describe 'homesick' do end describe 'pull' do - it 'should perform a pull, submodule init and update when the given ' \ - 'castle exists' do + it 'should perform a pull, submodule init and update when the given castle exists' do given_castle('castle_repo') homesick.stub(:system).once.with('git pull --quiet') homesick.stub(:system).once.with('git submodule --quiet init') - homesick.stub(:system).once.with('git submodule --quiet update ' \ - '--init --recursive >/dev/null 2>&1') + homesick.stub(:system).once.with('git submodule --quiet update --init --recursive >/dev/null 2>&1') homesick.pull 'castle_repo' end - it 'should print an error message when trying to pull a non-existant ' \ - 'castle' do + it 'should print an error message when trying to pull a non-existant castle' do homesick.should_receive('say_status').once .with(:error, - Regexp.new('Could not pull castle_repo, expected ' \ - '/tmp/construct_container.* exist and contain dotfiles'), + %r{Could not pull castle_repo, expected /tmp/construct_container.* exist and contain dotfiles}, :red) expect { homesick.pull 'castle_repo' }.to raise_error(SystemExit) end @@ -461,8 +451,7 @@ describe 'homesick' do homesick.stub(:system).exactly(2).times .with('git submodule --quiet init') homesick.stub(:system).exactly(2).times - .with('git submodule --quiet update --init --recursive ' \ - '>/dev/null 2>&1') + .with('git submodule --quiet update --init --recursive >/dev/null 2>&1') Capture.stdout do Capture.stderr { homesick.invoke 'pull', [], all: true } end @@ -478,12 +467,10 @@ describe 'homesick' do homesick.push 'castle_repo' end - it 'should print an error message when trying to push a non-existant '\ - 'castle' do + it 'should print an error message when trying to push a non-existant castle' do homesick.should_receive('say_status').once .with(:error, - Regexp.new('Could not push castle_repo, expected ' \ - '/tmp/construct_container.* exist and contain dotfiles'), + %r{Could not push castle_repo, expected /tmp/construct_container.* exist and contain dotfiles}, :red) expect { homesick.push 'castle_repo' }.to raise_error(SystemExit) end @@ -595,8 +582,7 @@ describe 'homesick' do end end - it 'should remove the parent of a tracked file from the subdir_file ' \ - 'if the parent itself is tracked' do + it 'should remove the parent of a tracked file from the subdir_file if the parent itself is tracked' do castle = given_castle('castle_repo') some_nested_file = home.file('some/nested/file.txt') @@ -614,8 +600,7 @@ describe 'homesick' do describe 'destroy' do it 'removes the symlink files' do - expect_any_instance_of(Thor::Shell::Basic).to \ - receive(:yes?).and_return('y') + expect_any_instance_of(Thor::Shell::Basic).to receive(:yes?).and_return('y') given_castle('stronghold') some_rc_file = home.file '.some_rc_file' homesick.track(some_rc_file.to_s, 'stronghold') @@ -625,8 +610,7 @@ describe 'homesick' do end it 'deletes the cloned repository' do - expect_any_instance_of(Thor::Shell::Basic).to \ - receive(:yes?).and_return('y') + expect_any_instance_of(Thor::Shell::Basic).to receive(:yes?).and_return('y') castle = given_castle('stronghold') some_rc_file = home.file '.some_rc_file' homesick.track(some_rc_file.to_s, 'stronghold') @@ -647,8 +631,7 @@ describe 'homesick' do it 'returns an error message when the given castle does not exist' do homesick.should_receive('say_status').once .with(:error, - Regexp.new('Could not cd castle_repo, expected ' \ - '/tmp/construct_container.* exist and contain dotfiles'), + %r{Could not cd castle_repo, expected /tmp/construct_container.* exist and contain dotfiles}, :red) expect { homesick.cd 'castle_repo' }.to raise_error(SystemExit) end @@ -666,14 +649,12 @@ describe 'homesick' do Capture.stdout { homesick.open 'castle_repo' } end - it 'returns an error message when the $EDITOR environment variable is ' \ - 'not set' do + it 'returns an error message when the $EDITOR environment variable is not set' do # Set the default editor to make sure it fails. ENV.stub(:[]).with('EDITOR').and_return(nil) homesick.should_receive('say_status').once .with(:error, - 'The $EDITOR environment variable must be set to use '\ - 'this command', + 'The $EDITOR environment variable must be set to use this command', :red) expect { homesick.open 'castle_repo' }.to raise_error(SystemExit) end @@ -683,8 +664,7 @@ describe 'homesick' do ENV.stub(:[]).with('EDITOR').and_return('vim') homesick.should_receive('say_status').once .with(:error, - Regexp.new('Could not open castle_repo, expected ' \ - '/tmp/construct_container.* exist and contain dotfiles'), + %r{Could not open castle_repo, expected /tmp/construct_container.* exist and contain dotfiles}, :red) expect { homesick.open 'castle_repo' }.to raise_error(SystemExit) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index aed4112..e594897 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -24,8 +24,7 @@ RSpec.configure do |config| system 'git init >/dev/null 2>&1' system 'git config user.email "test@test.com"' system 'git config user.name "Test Name"' - system "git remote add origin " \ - "git://github.com/technicalpickles/#{name}.git >/dev/null 2>&1" + system "git remote add origin git://github.com/technicalpickles/#{name}.git >/dev/null 2>&1" if subdirs subdir_file = castle.join(Homesick::SUBDIR_FILENAME) subdirs.each do |subdir| From c2cb6081e19a6ddbb125aa6fef31fff1b3e0965c Mon Sep 17 00:00:00 2001 From: Nicolas McCurdy Date: Mon, 20 Jan 2014 23:26:29 -0500 Subject: [PATCH 18/18] Fix some more code style issues with block params being in the wrong place --- spec/homesick_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/homesick_spec.rb b/spec/homesick_spec.rb index 1b7b7a0..4874d4f 100644 --- a/spec/homesick_spec.rb +++ b/spec/homesick_spec.rb @@ -18,8 +18,8 @@ describe 'homesick' do somewhere = create_construct local_repo = somewhere.directory('some_repo') local_repo.file('.homesickrc') do |file| - file << "File.open(Dir.pwd + '/testing', 'w') do - |f| f.print 'testing' + file << "File.open(Dir.pwd + '/testing', 'w') do |f| + f.print 'testing' end" end @@ -126,8 +126,8 @@ describe 'homesick' do it 'executes the .homesickrc' do castle.file('.homesickrc') do |file| - file << "File.open(Dir.pwd + '/testing', 'w') do - |f| f.print 'testing' + file << "File.open(Dir.pwd + '/testing', 'w') do |f| + f.print 'testing' end" end @@ -146,8 +146,8 @@ describe 'homesick' do it 'does not execute the .homesickrc' do castle.file('.homesickrc') do |file| - file << "File.open(Dir.pwd + '/testing', 'w') do - |f| f.print 'testing' + file << "File.open(Dir.pwd + '/testing', 'w') do |f| + f.print 'testing' end" end