Skip to content

Commit

Permalink
[FIX] Incorrect syntax for hg via ssh://... not the same as git...
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Luckey committed Jan 22, 2009
1 parent 1df6b35 commit f3550c8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
20 changes: 16 additions & 4 deletions lib/scm/adapters/hg/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,28 @@ def push(to, &block)

def local?
return true if hostname == Socket.gethostname
return false if url =~ /:/
true
return true if url =~ /^file:\/\//
return true if url !~ /:/
false
end

def hostname
url =~ /^([^:^\/]+):(.+)/ ? $1 : nil
$1 if url =~ /^ssh:\/\/([^\/]+)/
end

def path
url =~ /^([^:^\/]+):(.+)/ ? $2 : nil
case url
when /^file:\/\/(.+)$/
$1
when /^ssh:\/\/[^\/]+(\/.+)$/
$1
when /^[^:]*$/
url
end
end

def hg_path
path && File.join(path, '.hg')
end
end
end
27 changes: 20 additions & 7 deletions test/unit/hg_push_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,34 @@ module Scm::Adapters
class HgPushTest < Scm::Test

def test_hostname
assert_equal "foo", HgAdapter.new(:url => 'foo:/bar').hostname
assert_equal "/bar", HgAdapter.new(:url => 'foo:/bar').path

assert !HgAdapter.new.hostname
assert !HgAdapter.new(:url => '/bar').hostname
assert_equal 'http', HgAdapter.new(:url => 'http://www.ohloh.net/bar').hostname
assert !HgAdapter.new(:url => "http://www.ohloh.net/test").hostname
assert !HgAdapter.new(:url => "/Users/robin/foo").hostname
assert_equal "foo", HgAdapter.new(:url => 'ssh://foo/bar').hostname
end

def test_local
assert !HgAdapter.new(:url => "foo:/bar").local? # Assuming your machine is not named "foo" :-)
assert !HgAdapter.new(:url => "http://www.ohloh.net/foo").local?
assert !HgAdapter.new(:url => "ssh://host/Users/robin/src").local?
assert HgAdapter.new(:url => "src").local?
assert HgAdapter.new(:url => "/Users/robin/src").local?
assert HgAdapter.new(:url => "#{Socket.gethostname}:src").local?
assert HgAdapter.new(:url => "#{Socket.gethostname}:/Users/robin/src").local?
assert HgAdapter.new(:url => "file:///Users/robin/src").local?
assert HgAdapter.new(:url => "ssh://#{Socket.gethostname}/Users/robin/src").local?
end

def test_path
assert_equal nil, HgAdapter.new().path
assert_equal nil, HgAdapter.new(:url => "http://ohloh.net/foo").path
assert_equal nil, HgAdapter.new(:url => "https://ohloh.net/foo").path
assert_equal "/Users/robin/foo", HgAdapter.new(:url => "file:///Users/robin/foo").path
assert_equal "/Users/robin/foo", HgAdapter.new(:url => "ssh://localhost/Users/robin/foo").path
assert_equal "/Users/robin/foo", HgAdapter.new(:url => "/Users/robin/foo").path
end

def test_hg_path
assert_equal nil, HgAdapter.new().hg_path
assert_equal "/Users/robin/src/.hg", HgAdapter.new(:url => "/Users/robin/src").hg_path
end

def test_push
Expand Down

0 comments on commit f3550c8

Please sign in to comment.