Skip to content

Commit ec277f1

Browse files
author
Peter Degen-Portnoy
committed
Merge pull request #13 from blackducksw/Normalize_Branch_Name
Normalize_Branch_Name: set the branch name when normalizing an SvnAdapter
2 parents d20a8de + f310453 commit ec277f1

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

lib/scm/adapters/svn/misc.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ def restrict_url_to_trunk
3535

3636
if list.include? 'trunk/'
3737
self.url = File.join(self.url, 'trunk')
38-
self.branch_name = File.join(self.branch_name, 'trunk')
38+
self.branch_name = File.join(self.branch_name, 'trunk') if self.branch_name
3939
elsif list.size == 1 and list.first[-1..-1] == '/'
4040
self.url = File.join(self.url, list.first[0..-2])
41-
self.branch_name = File.join(self.branch_name, list.first[0..-2])
41+
self.branch_name = File.join(self.branch_name, list.first[0..-2]) if self.branch_name
4242
return restrict_url_to_trunk
4343
end
4444
self.url

lib/scm/adapters/svn/validation.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def normalize
1212
super
1313
@url = path_to_file_url(@url)
1414
@url = force_https_if_sourceforge(@url)
15-
@branch_name = @branch_name[0..-2] if @branch_name && @branch_name[-1..-1] == '/'
15+
@branch_name = recalc_branch_name
1616
self
1717
end
1818

@@ -32,7 +32,7 @@ def path_to_file_url(path)
3232

3333
def force_https_if_sourceforge(url)
3434
# SourceForge requires https for svnsync
35-
url =~ /http(:\/\/.*svn\.sourceforge\.net.*)/ ? "https#{$1}" : url
35+
url =~ /http(:\/\/.*svn\.(sourceforge|code\.sf)\.net.*)/ ? "https#{$1}" : url
3636
end
3737

3838
def validate_server_connection
@@ -54,7 +54,12 @@ def validate_server_connection
5454
# From the given URL, determine which part of it is the root and which part of it is the branch_name.
5555
# The current branch_name is overwritten.
5656
def recalc_branch_name
57-
@branch_name = @url ? @url[root.length..-1] : @branch_name
57+
begin
58+
@branch_name = @url ? @url[root.length..-1] : @branch_name
59+
rescue RuntimeError => exception
60+
exception.message =~ /svn:*is not a working copy/ # we have a file system
61+
@branch_name = ''
62+
end
5863
@branch_name = @branch_name[0..-2] if @branch_name[-1..-1] == '/'
5964
@branch_name
6065
end

test/unit/svn_validation_test.rb

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ def test_guess_forge
9595
svn = SvnAdapter.new(:url => 'https://vegastrike.svn.sourceforge.net/svnroot/vegastrike/trunk')
9696
assert_equal 'sourceforge.net', svn.guess_forge
9797

98+
svn = SvnAdapter.new(:url => 'https://svn.code.sf.net/p/gallery/code/trunk/gallery2')
99+
assert_equal 'code.sf.net', svn.guess_forge
100+
98101
svn = SvnAdapter.new(:url => 'https://appfuse.dev.java.net/svn/appfuse/trunk')
99102
assert_equal 'java.net', svn.guess_forge
100103

@@ -106,14 +109,13 @@ def test_guess_forge
106109
end
107110

108111
def test_sourceforge_requires_https
109-
assert_equal 'https://gallery.svn.sourceforge.net/svnroot/gallery/trunk/gallery2',
110-
SvnAdapter.new(:url => 'http://gallery.svn.sourceforge.net/svnroot/gallery/trunk/gallery2').normalize.url
112+
url = '://svn.code.sf.net/p/gallery/code/trunk/gallery2'
113+
assert_equal "https#{url}", SvnAdapter.new(:url => "http#{url}").normalize.url
111114

112-
assert_equal 'https://gallery.svn.sourceforge.net/svnroot/gallery/trunk/gallery2',
113-
SvnAdapter.new(:url => 'https://gallery.svn.sourceforge.net/svnroot/gallery/trunk/gallery2').normalize.url
115+
assert_equal "https#{url}", SvnAdapter.new(:url => "https#{url}").normalize.url
114116

115-
assert_equal 'http://pianosa.googlecode.com/svn/trunk',
116-
SvnAdapter.new(:url => 'http://pianosa.googlecode.com/svn/trunk').normalize.url
117+
url = 'https://github.com/blackducksw/ohloh_scm/trunk'
118+
assert_equal url, SvnAdapter.new(:url => url).normalize.url
117119
end
118120

119121
def test_validate_server_connection
@@ -145,6 +147,16 @@ def test_recalc_branch_name
145147
assert !svn_trunk_with_whack.branch_name
146148
assert_equal '/trunk', svn_trunk_with_whack.recalc_branch_name
147149
assert_equal '/trunk', svn_trunk_with_whack.branch_name
150+
151+
svn_trunk = SvnAdapter.new(:url => svn.root + '/trunk')
152+
assert !svn_trunk.branch_name
153+
svn_trunk.normalize # only normalize to ensure branch_name is populated correctly
154+
assert_equal '/trunk', svn_trunk.branch_name
155+
156+
svn_trunk = SvnAdapter.new(:url => svn.root)
157+
assert !svn_trunk.branch_name
158+
svn_trunk.normalize
159+
assert_equal '', svn_trunk.branch_name
148160
end
149161
end
150162
end

0 commit comments

Comments
 (0)