Skip to content

Commit cefd60f

Browse files
committed
Added Git::Utils class. Added URL to SSH repo address converter
1 parent ffbb460 commit cefd60f

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

git.gemspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.authors = ['Scott Chacon']
3-
s.date = '2015-01-13'
3+
s.date = '2015-01-13'
44
s.email = 'schacon@gmail.com'
55
s.homepage = 'http://github.com/schacon/ruby-git'
66
s.license = 'MIT'
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
1515
s.add_development_dependency 'rake'
1616
s.add_development_dependency 'rdoc'
1717
s.add_development_dependency 'test-unit', '>=2', '< 4'
18-
18+
1919
s.extra_rdoc_files = ['README.md']
2020
s.rdoc_options = ['--charset=UTF-8']
2121

@@ -43,6 +43,7 @@ Gem::Specification.new do |s|
4343
'lib/git/stashes.rb',
4444
'lib/git/status.rb',
4545
'lib/git/version.rb',
46-
'lib/git/working_directory.rb'
46+
'lib/git/working_directory.rb',
47+
'lib/git/utils.rb'
4748
]
4849
end

lib/git.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
require 'git/stash'
2121
require 'git/stashes'
2222
require 'git/working_directory'
23+
require 'git/utils'
2324

2425
lib = Git::Lib.new(nil, nil)
2526
unless lib.meets_required_version?

lib/git/utils.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require 'uri'
2+
3+
module Git
4+
class Utils
5+
def self.url_to_ssh( url )
6+
uri = URI( url )
7+
"git@#{uri.host}:#{uri.path[1..-1]}"
8+
end
9+
end
10+
end

tests/units/test_utils.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env ruby
2+
3+
require File.dirname(__FILE__) + '/../test_helper'
4+
5+
class TestUtils < Test::Unit::TestCase
6+
7+
def test_uri_to_ssh
8+
assert_equal('git@github.com:user/repo.git', Git::Utils.url_to_ssh('https://github.com/user/repo.git'))
9+
assert_equal('git@bitbucket.org:user/repo.git', Git::Utils.url_to_ssh('https://bitbucket.org/user/repo.git'))
10+
end
11+
12+
end

0 commit comments

Comments
 (0)