Skip to content

Instantly share code, notes, and snippets.

@cgriego
Created December 9, 2009 22:49
Show Gist options
  • Save cgriego/252922 to your computer and use it in GitHub Desktop.
Save cgriego/252922 to your computer and use it in GitHub Desktop.
def detect(path)
git = File.directory?(File.join(path, '.git'))
svn = File.directory?(File.join(path, '.svn'))
hg = File.directory?(File.join(path, '.hg'))
bzr = File.directory?(File.join(path, '.bzr'))
case [git, svn, hg, bzr]
when [true, false, false, false] then SourceControl::Git.new(:path => path)
when [false, true, false, false] then SourceControl::Subversion.new(:path => path)
when [false, false, true, false] then SourceControl::Mercurial.new(:path => path)
when [false, false, false, true] then SourceControl::Bazaar.new(:path => path)
when [false, false, false, false] then raise "Could not detect the type of source control in #{path}"
else raise "More than one type of source control was detected in #{path}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment