Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Library/Homebrew/dev-cmd/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,8 @@ def audit_urls
end
elsif strategy <= SubversionDownloadStrategy
next unless DevelopmentTools.subversion_handles_most_https_certificates?
unless Utils.svn_remote_exists url
next unless Utils.svn_available?
if Utils.svn_remote_exists url
problem "The URL #{url} is not a valid svn URL"
end
end
Expand Down
39 changes: 39 additions & 0 deletions Library/Homebrew/test/utils/svn_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require "utils/svn"

describe Utils do
describe "#self.svn_available?" do
before(:each) do
described_class.clear_svn_version_cache
end

it "returns svn version if svn available" do
expect(described_class.svn_available?).to be_truthy
end
end

describe "#self.svn_remote_exists" do
it "returns true when svn is not available" do
allow(Utils).to receive(:svn_available?).and_return(false)
expect(described_class.svn_remote_exists("blah")).to be_truthy
end

context "when svn is available" do
before do
allow(Utils).to receive(:svn_available?).and_return(true)
end

it "returns false when remote does not exist" do
expect(described_class.svn_remote_exists(HOMEBREW_CACHE/"install")).to be_falsey
end

it "returns true when remote exists", :needs_network do
remote = "http://github.com/Homebrew/install"
svn = HOMEBREW_SHIMS_PATH/"scm/svn"

HOMEBREW_CACHE.cd { system svn, "checkout", remote }

expect(described_class.svn_remote_exists(HOMEBREW_CACHE/"install")).to be_truthy
end
end
end
end
4 changes: 4 additions & 0 deletions Library/Homebrew/utils/svn.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module Utils
def self.clear_svn_version_cache
remove_instance_variable(:@svn) if instance_variable_defined?(:@svn)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never needed, except in tests, so this shouldn‘t exist in the actual code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reitermarkus I'm not sure how this gets resolved without adding a method here. What would you propose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding a method in one of the support modules for tests to clear any instance variable? As in a method whose argument is the instance variable to be cleared. @MikeMcQuaid @reitermarkus @mistydemeo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mansimarkaur If by support modules you mean in the spec_helper or something then: yeh, that could work. @reitermarkus?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, there's probably some times this method should be called anyway such as e.g. after a new installation of svn (and same thing for git)

Copy link
Contributor Author

@mansimarkaur mansimarkaur Aug 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MikeMcQuaid Yes, I meant adding a method in the spec_helper but if we want to call this cache clear method after a new installation, then we don't need to add it in the spec_helper. Which is a better alternative? Also, utils/git.rb already has a Utils.clear_git_available_cache to remove @git, @git_path and @git_version: https://github.com/Homebrew/brew/blob/master/Library/Homebrew/utils/git.rb#L66

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mansimarkaur I think this is fine as-is, then, thanks.

end

def self.svn_available?
return @svn if instance_variable_defined?(:@svn)
@svn = quiet_system HOMEBREW_SHIMS_PATH/"scm/svn", "--version"
Expand Down