Skip to content

Commit 2fb51f1

Browse files
author
Peter Degen-Portnoy
committed
Merge pull request #14 from blackducksw/Normalize_Branch_Name
Normalize_Branch_Name: Correct condition in recalc_branch_name
2 parents ec277f1 + 2e5d88f commit 2fb51f1

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
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') if self.branch_name
38+
self.branch_name = File.join(self.branch_name, 'trunk')
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]) if self.branch_name
41+
self.branch_name = File.join(self.branch_name, list.first[0..-2])
4242
return restrict_url_to_trunk
4343
end
4444
self.url

lib/scm/adapters/svn/validation.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ def normalize
1212
super
1313
@url = path_to_file_url(@url)
1414
@url = force_https_if_sourceforge(@url)
15-
@branch_name = recalc_branch_name
15+
if @branch_name
16+
clean_branch_name
17+
else
18+
@branch_name = recalc_branch_name
19+
end
1620
self
1721
end
1822

@@ -57,11 +61,10 @@ def recalc_branch_name
5761
begin
5862
@branch_name = @url ? @url[root.length..-1] : @branch_name
5963
rescue RuntimeError => exception
60-
exception.message =~ /svn:*is not a working copy/ # we have a file system
61-
@branch_name = ''
64+
@branch_name = '' if exception.message =~ /(svn:*is not a working copy|Unable to open an ra_local session to URL)/ # we have a file system
6265
end
63-
@branch_name = @branch_name[0..-2] if @branch_name[-1..-1] == '/'
64-
@branch_name
66+
clean_branch_name
67+
@branch_name
6568
end
6669

6770
def guess_forge
@@ -74,5 +77,11 @@ def guess_forge
7477
u
7578
end
7679
end
80+
81+
private
82+
def clean_branch_name
83+
return unless @branch_name
84+
@branch_name.chop! if @branch_name.end_with?('/')
85+
end
7786
end
7887
end

test/unit/svn_validation_test.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,18 @@ def test_recalc_branch_name
159159
assert_equal '', svn_trunk.branch_name
160160
end
161161
end
162-
end
163162

164-
def test_strip_trailing_whack_from_branch_name
165-
assert_equal '/trunk', SvnAdapter.new(:branch_name => "/trunk/").normalize.branch_name
163+
def test_strip_trailing_whack_from_branch_name
164+
with_svn_repository('svn') do |svn|
165+
assert_equal '/trunk', SvnAdapter.new(:url => svn.root, :branch_name => "/trunk/").normalize.branch_name
166+
end
167+
end
168+
169+
def test_empty_branch_name_with_file_system
170+
Scm::ScratchDir.new do |dir|
171+
svn = SvnAdapter.new(:url => dir).normalize
172+
assert_equal '', svn.branch_name
173+
end
174+
end
166175
end
167176
end

0 commit comments

Comments
 (0)