Skip to content

Commit

Permalink
DRY up the SCM classes
Browse files Browse the repository at this point in the history
  • Loading branch information
cpjolicoeur committed Aug 4, 2009
1 parent b558606 commit 3ee4c50
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 55 deletions.
19 changes: 19 additions & 0 deletions lib/cerberus/scm/base.rb
@@ -0,0 +1,19 @@
module Cerberus
module SCM
class Base

def initialize(path, config = {})
raise "Path can't be nil" unless path

@path, @config = path.strip, config
@encoded_path = (@path.include?(' ') ? "\"#{@path}\"" : @path)
end

def url
@path
end

end
end
end

14 changes: 2 additions & 12 deletions lib/cerberus/scm/bzr.rb
@@ -1,14 +1,8 @@
require 'cerberus/utils'
require 'cerberus/scm/base'
require 'time'

class Cerberus::SCM::Bazaar

def initialize(path, config = {})
raise "Path can't be nil" unless path

@path, @config = path.strip, config
@encoded_path = (@path.include?(' ') ? "\"#{@path}\"" : @path)
end
class Cerberus::SCM::Bazaar < Cerberus::SCM::Base

def installed?
exec_successful? "#{@config[:bin_path]}bzr --version"
Expand Down Expand Up @@ -37,10 +31,6 @@ def current_revision
@revision
end

def url
@path
end

def last_commit_message
@message
end
Expand Down
9 changes: 2 additions & 7 deletions lib/cerberus/scm/cvs.rb
@@ -1,12 +1,7 @@
require 'cerberus/utils'
require 'cerberus/scm/base'

class Cerberus::SCM::CVS
def initialize(path, config = {})
raise "Path can't be nil" unless path

@path, @config = path.strip, config
@encoded_path = (@path.include?(' ') ? "\"#{@path}\"" : @path)
end
class Cerberus::SCM::CVS < Cerberus::SCM::Base

def installed?
exec_successful? "#{@config[:bin_path]}cvs --version"
Expand Down
13 changes: 2 additions & 11 deletions lib/cerberus/scm/darcs.rb
@@ -1,12 +1,7 @@
require 'cerberus/utils'
require 'cerberus/scm/base'

class Cerberus::SCM::Darcs
def initialize(path, config = {})
raise "Path can't be nil" unless path

@path, @config = path.strip, config
@encoded_path = (@path.include?(' ') ? "\"#{@path}\"" : @path)
end
class Cerberus::SCM::Darcs < Cerberus::SCM::Base

def installed?
exec_successful? "#{@config[:bin_path]}darcs --version"
Expand Down Expand Up @@ -37,10 +32,6 @@ def current_revision
@date
end

def url
@path
end

def last_commit_message
@message
end
Expand Down
19 changes: 5 additions & 14 deletions lib/cerberus/scm/git.rb
@@ -1,19 +1,14 @@
require 'cerberus/utils'
require 'cerberus/scm/base'

class Cerberus::SCM::Git
def initialize(path, config = {})
raise "Path can't be nil" unless path

@path, @config = path.strip, config
@encoded_path = (@path.include?(' ') ? "\"#{@path}\"" : @path)
end

class Cerberus::SCM::Git < Cerberus::SCM::Base

def installed?
exec_successful? "#{@config[:bin_path]}git --version"
end

def update!
if test(?d, @path + '/.git')
if test( ?d, File.join( @path,'.git' ) )
get_updates
execute("reset", "--hard #{remote_head}")
else
Expand Down Expand Up @@ -42,10 +37,6 @@ def current_revision( _full=false )
_full ? @revision : @revision.slice(0,8)
end

def url
@path
end

def last_commit_message
@message
end
Expand Down Expand Up @@ -81,7 +72,7 @@ def execute(command, parameters = nil, with_path = true)

def extract_commit_info( commit=remote_head )
message = execute("show", "#{ commit } --pretty='format:%an(%ae)|%ai|%H|%s'").split("|")
{ :author => message[0], :date => message[1], :revision => message[2], :message => message[3] }
return { :author => message[0], :date => message[1], :revision => message[2], :message => message[3] }
end

def last_tested_revision
Expand Down
8 changes: 4 additions & 4 deletions lib/cerberus/scm/perforce.rb
@@ -1,12 +1,12 @@
require 'cerberus/utils'
require 'cerberus/scm/base'

class Cerberus::SCM::Perforce
class Cerberus::SCM::Perforce < Cerberus::SCM::Base

CHANGES_LOG_REGEXP = /^Change (\d+) on (.*) by (.*)\n\n(.*)/m

def initialize(path, config = {})
@config = config
@path = path.strip

super
@p4_view = @config[:scm, :view]
@client_name = Socket.gethostname + ":" + @path.gsub(' ', ':')
end
Expand Down
9 changes: 2 additions & 7 deletions lib/cerberus/scm/svn.rb
@@ -1,12 +1,7 @@
require 'cerberus/utils'
require 'cerberus/scm/base'

class Cerberus::SCM::SVN
def initialize(path, config = {})
raise "Path can't be nil" unless path

@path, @config = path.strip, config
@encoded_path = (@path.include?(' ') ? "\"#{@path}\"" : @path)
end
class Cerberus::SCM::SVN < Cerberus::SCM::Base

def installed?
exec_successful? "#{@config[:bin_path]}svn --version"
Expand Down

0 comments on commit 3ee4c50

Please sign in to comment.