better regex for #name_from_git #6

Merged
merged 2 commits into from Mar 31, 2012
View
2 lib/ors/config.rb
@@ -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
View
17 spec/ors/config_spec.rb
@@ -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