forked from engineyard/engineyard
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove Grit, which is massive overkill for what we need.
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
Showing
6 changed files
with
76 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters