Module: SCM

Defined in:
lib/scm/hg.rb,
lib/scm/git.rb,
lib/scm/scm.rb,
lib/scm/svn.rb,
lib/scm/util.rb,
lib/scm/version.rb,
lib/scm/commits/hg.rb,
lib/scm/repository.rb,
lib/scm/commits/git.rb,
lib/scm/commits/svn.rb,
lib/scm/commits/commit.rb

Defined Under Namespace

Modules: Commits, Util Classes: Git, Hg, Repository, SVN

Constant Summary collapse

DIRS =

SCM control directories and the SCM classes

{
  '.git' => Git,
  '.hg'  => Hg,
  '.svn' => SVN
}
SCHEMES =

Common URI schemes used to denote the SCM

{
  'git'     => Git,
  'hg'      => Hg,
  'svn'     => SVN,
  'svn+ssh' => SVN
}
EXTENSIONS =

Common file extensions used to denote the SCM of a URI

{
  '.git' => Git,
  '.hg'  => Hg,
  '.svn' => SVN
}
VERSION =

SCM version

"0.1.0.pre2"

Class Method Summary collapse

Class Method Details

.clone(uri, options = {}) ⇒ Repository

Determines the SCM used for a repository URI and clones it.

Parameters:

  • uri (URI, String)

    The URI to the repository.

  • options (Hash) (defaults to: {})

    Additional SCM specific clone options.

Returns:

Raises:

  • (ArgumentError)

    The exact SCM could not be determined.


69
70
71
72
73
74
75
76
77
78
# File 'lib/scm/scm.rb', line 69

def SCM.clone(uri,options={})
  uri = URI(uri) unless uri.kind_of?(URI)
  scm = (SCHEMES[uri.scheme] || EXTENSIONS[File.extname(uri.path)])

  unless scm
    raise(ArgumentError,"could not determine the SCM of #{uri}")
  end

  return scm.clone(uri,options)
end

.new(path) ⇒ Repository

Determines the SCM used for a repository.

Parameters:

  • path (String)

    The path of the repository.

Returns:

Raises:

  • (ArgumentError)

    The exact SCM could not be determined.


42
43
44
45
46
47
48
49
50
51
52
# File 'lib/scm/scm.rb', line 42

def SCM.new(path)
  path = File.expand_path(path)

  DIRS.each do |name,repo|
    dir = File.join(path,name)

    return repo.new(path) if File.directory?(dir)
  end

  raise(ArgumentError,"could not determine the SCM of #{path.dump}")
end