Module: RubyMaat::VcsDetector

Defined in:
lib/ruby_maat/vcs_detector.rb

Class Method Summary collapse

Class Method Details

.detect_vcs(path = ".") ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ruby_maat/vcs_detector.rb', line 5

def self.detect_vcs(path = ".")
  expanded_path = File.expand_path(path)

  # Check for Git
  git_dir = File.join(expanded_path, ".git")
  if Dir.exist?(git_dir) || File.exist?(git_dir)
    return "git"
  end

  # Check for SVN
  svn_dir = File.join(expanded_path, ".svn")
  if Dir.exist?(svn_dir)
    return "svn"
  end

  # Check for Mercurial
  hg_dir = File.join(expanded_path, ".hg")
  if Dir.exist?(hg_dir)
    return "hg"
  end

  # Check for Perforce (look for .p4config or ask p4)
  p4config = File.join(expanded_path, ".p4config")
  if File.exist?(p4config)
    return "p4"
  end

  # Try to detect by running commands (if they exist)
  begin
    Dir.chdir(expanded_path) do
      # Check git status
      `git status 2>/dev/null`
      return "git" if $?.exitstatus == 0

      # Check svn info
      `svn info 2>/dev/null`
      return "svn" if $?.exitstatus == 0

      # Check hg status
      `hg status 2>/dev/null`
      return "hg" if $?.exitstatus == 0

      # Check p4 info
      `p4 info 2>/dev/null`
      return "p4" if $?.exitstatus == 0
    end
  rescue
    # If we can't change directory or run commands, continue
  end

  nil # No VCS detected
end

.vcs_description(vcs) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ruby_maat/vcs_detector.rb', line 58

def self.vcs_description(vcs)
  case vcs
  when "git"
    "Git repository"
  when "svn"
    "Subversion repository"
  when "hg"
    "Mercurial repository"
  when "p4"
    "Perforce repository"
  when "tfs"
    "Team Foundation Server"
  else
    "Unknown VCS"
  end
end