Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better regex for #name_from_git #6

Merged
merged 2 commits into from Mar 31, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ors/config.rb
Expand Up @@ -58,7 +58,7 @@ def git
private

def name_from_git
git.config["remote.origin.url"].gsub /.*?:(.*?).git/, '\1'
git.config["remote.origin.url"].gsub(/^[\w]*(@|:\/\/)[^\/:]*(\/|:)([a-zA-Z0-9\/]*)(.git)?$/i, '\3')
end

end
Expand Down
17 changes: 17 additions & 0 deletions spec/ors/config_spec.rb
Expand Up @@ -97,4 +97,21 @@ class ORS::ConfigTest; include ORS::Config; end
end
end

context "#name_from_git" do
{
"git://github.com/testing/github.git" => "testing/github",
"git://example.com/testing/gitlabhq.git" => "testing/gitlabhq",
"git://github.com/testing/github" => "testing/github",
"git@github.com:testing/github" => "testing/github",
"git@ghub.com:testing/gitlabhq.git" => "testing/gitlabhq",
"git@ghub.com:gitlabhq.git" => "gitlabhq",
"git://ghub.com/gitlabhq.git" => "gitlabhq"
}.each do |remote, name|
it "should handle a remote origin url such as #{remote}" do
mock(ORS::Config).git { mock!.config { {"remote.origin.url" => remote} }}
ORS::Config.send(:name_from_git).should == name
end
end
end

end