Skip to content

Commit

Permalink
Remove Grit, which is massive overkill for what we need.
Browse files Browse the repository at this point in the history
This speeds up the ey binary by a significant amount.

Patch 2: EY::Repo specs

Change-Id: Ia20055a3faecb7b1a432e908a05ed7fc08fe2cdb
Reviewed-on: http://review.engineyard.com/36
Reviewed-by: Andy Delcambre <adelcambre@engineyard.com>
Tested-by: Andy Delcambre <adelcambre@engineyard.com>
  • Loading branch information
indirect authored and Andy Delcambre committed Feb 8, 2010
1 parent 93f55e7 commit 169f486
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 10 deletions.
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -12,7 +12,6 @@ end
gem 'highline'
gem 'rest-client', :require_as => 'rest_client'
gem 'json'
gem 'grit'

disable_system_gems
bin_path "gbin"
2 changes: 2 additions & 0 deletions lib/engineyard/cli.rb
@@ -1,3 +1,5 @@
$:.unshift File.expand_path('../../vendor/thor/lib', __FILE__)
require 'thor'
require 'highline'

require 'cli/command'
Expand Down
18 changes: 11 additions & 7 deletions lib/engineyard/repo.rb
@@ -1,17 +1,21 @@
require 'grit'

module EY
class Repo
def initialize(path=File.expand_path('.'))
@repo = Grit::Repo.new(path)
@path = path
end

def current_branch
@repo.head.name
head = File.read(File.join(@path, ".git/HEAD")).chomp
if head.gsub!("ref: refs/heads/", "")
head
else
nil
end
end

def repo_url
@repo.config["remote.origin.url"]
config = `git config -f #{@path}/.git/config remote.origin.url`.strip
config.empty? ? nil : config
end
end
end
end # Repo
end # EY
49 changes: 49 additions & 0 deletions spec/engineyard/repo_spec.rb
@@ -0,0 +1,49 @@
require 'spec_helper'

describe EY::Repo do
before(:all) do
@path = "/tmp/ey-test/.git/"
@r = EY::Repo.new("/tmp/ey-test")
end

describe "current_branch method" do
it "returns the name of the current branch" do
set_head "ref: refs/heads/master"
@r.current_branch.should == "master"
end

it "returns nil if there is no current branch" do
set_head "20bf478ab6a91ec5771130aa4c8cfd3d150c4146"
@r.current_branch.should be_nil
end

def set_head(head)
File.open(@path+"HEAD", "w"){|f| f.write(head) }
end
end # current_branch

describe "repo_url method" do
it "returns the url of the origin remote" do
origin_url = "git@github.com/engineyard/engineyard.git"
set_repo_url origin_url
@r.repo_url.should == origin_url
end

it "returns nil if there is no origin remote" do
set_repo_url nil
@r.repo_url.should be_nil
end

def set_repo_url(url)
@config_path = @path+"config"
# This has to all shell out because FakeFS is enabled
if url
system("mkdir -p #{@path} && cd #{@path} && git init -q")
system("git config -f #{@config_path} remote.origin.url #{url}")
else
system("rm -rf #{@config_path}")
end
end
end # repo_url

end # EY::Repo
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -7,7 +7,7 @@
require 'spec'
require 'spec/autorun'

require 'support/capture_stdout'
require 'support/helpers'

Spec::Runner.configure do |config|
config.before(:each) do
Expand Down
14 changes: 13 additions & 1 deletion spec/support/capture_stdout.rb → spec/support/helpers.rb
Expand Up @@ -24,4 +24,16 @@ def capture_stdio(&block)
end
return [stdout, stderr]
end
end
end

def ey(cmd = nil, options = {})
require "open3"
args = options.map { |k,v| " --#{k} #{v}"}.join
eybin = File.expand_path('../../../bin/ey', __FILE__)
@in, @out, @err = Open3.popen3("#{eybin} #{cmd}#{args}")
@err = @err.read.strip

puts @err unless @err.empty?

@out = @out.read.strip
end

0 comments on commit 169f486

Please sign in to comment.