From 02e51ce26eba77f40e4108083e6b217dbd1581a9 Mon Sep 17 00:00:00 2001 From: Suyeol Jeon Date: Mon, 19 Oct 2015 00:24:38 +0900 Subject: [PATCH 1/2] Raise an exception when failed to install seeds. --- lib/cocoaseeds/core.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/cocoaseeds/core.rb b/lib/cocoaseeds/core.rb index f99e9c3..11615bd 100644 --- a/lib/cocoaseeds/core.rb +++ b/lib/cocoaseeds/core.rb @@ -345,16 +345,18 @@ def install_seed(seed, dirname) not_found = output.include?("not found") if not_found and output.include?("repository") - say "[!] #{seed.name}: Couldn't find the repository.".red + raise Seeds::Exception.new\ + "#{seed.name}: Couldn't find the repository." elsif not_found and output.include?("upstream") - say "[!] #{seed.name}: Couldn't find the tag `#{seed.version}`.".red + raise Seeds::Exception.new\ + "#{seed.name}: Couldn't find the tag `#{seed.version}`." end if seed.commit and not seed.version # checkout to commit output = `cd #{dirname} 2>&1 && git checkout #{seed.commit} 2>&1` if output.include?("did not match any") - say "[!] #{seed.name}: Couldn't find the commit "\ - "`#{seed.commit}`.".red + raise Seeds::Exception.new\ + "#{seed.name}: Couldn't find the commit `#{seed.commit}`." end end @@ -383,10 +385,9 @@ def install_seed(seed, dirname) output = `cd #{dirname} 2>&1 &&\ git fetch origin #{seed.version} --tags 2>&1 &&\ git checkout #{seed.version} 2>&1` - puts output if output.include?("Couldn't find") - say "[!] #{seed.name}: Couldn't find the tag or branch named "\ - "`#{seed.commit}`.".red + raise Seeds::Exception.new\ + "#{seed.name}: Couldn't find the tag or branch `#{seed.version}`." end elsif seed.commit @@ -397,8 +398,8 @@ def install_seed(seed, dirname) git pull 2>&1 && git checkout #{seed.commit} 2>&1` if output.include?("did not match any") - say "[!] #{seed.name}: Couldn't find the commit "\ - "`#{seed.commit}`.".red + raise Seeds::Exception.new\ + "#{seed.name}: Couldn't find the commit `#{seed.commit}`.".red end end From c5348aaa519b2e53c8f9578c14771c031477e450 Mon Sep 17 00:00:00 2001 From: Suyeol Jeon Date: Mon, 19 Oct 2015 00:30:46 +0900 Subject: [PATCH 2/2] Add test code to test raising exceptions for invalid tag and commits. --- test/test_install.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/test_install.rb b/test/test_install.rb index dee43e3..ecc8abb 100644 --- a/test/test_install.rb +++ b/test/test_install.rb @@ -91,6 +91,22 @@ def test_raise_github_both_tag_and_commit assert_raises Seeds::Exception do @seed.install end end + + def test_raise_invalid_tag + seedfile %{ + github "JLToast", "Hello, World!" + } + assert_raises Seeds::Exception do @seed.install end + end + + + def test_raise_invalid_commit + seedfile %{ + github "JLToast", :commit => "Hello, World!" + } + assert_raises Seeds::Exception do @seed.install end + end + end