Class: Tddium::Hg

Inherits:
Object
  • Object
show all
Extended by:
TddiumConstant
Includes:
TddiumConstant
Defined in:
lib/tddium/scm/hg.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.hg_changes?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/tddium/scm/hg.rb', line 114

def hg_changes?(options={})
  options[:exclude] ||= []
  options[:exclude] = [options[:exclude]] unless options[:exclude].is_a?(Array)
  cmd = "(hg status -mardu || echo HG_FAILED) < /dev/null 2>&1"
  p = IO.popen(cmd)
  changes = false
  while line = p.gets do
    if line =~ /HG_FAILED/
      warn(Text::Warning::SCM_UNABLE_TO_DETECT)
      return false
    end
    line = line.strip
    status, name = line.split(/\s+/)
    next if options[:exclude].include?(name)
    if status !~ /^\?/ then
      changes = true
      break
    end
  end
  return changes
end

.hg_push(this_branch, additional_refs = []) ⇒ Object



136
137
138
# File 'lib/tddium/scm/hg.rb', line 136

def hg_push(this_branch, additional_refs=[])
  raise "not implemented"
end

.version_okObject



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/tddium/scm/hg.rb', line 140

def version_ok
  version = nil
  begin
    version_string = `hg -q --version`
    m =  version_string.match(Dependency::VERSION_REGEXP)
    version = m[0] unless m.nil?
  rescue Errno
  rescue Exception
  end
  if version.nil? || version.empty? then
    abort Text::Error::SCM_NOT_FOUND
  end
  version_parts = version.split(".")
  if version_parts[0].to_i < 2 then
    warn(Text::Warning::HG_VERSION % version)
  end
  true
end

Instance Method Details

#changes?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/tddium/scm/hg.rb', line 64

def changes?(options={})
  return Tddium::Hg.hg_changes?(:exclude=>".hgignore")
end

#commitsObject



95
96
97
98
# File 'lib/tddium/scm/hg.rb', line 95

def commits
  commits = HgCommitLogParser.new(self.latest_commit).commits
  return commits
end

#current_branchObject



53
54
55
56
57
# File 'lib/tddium/scm/hg.rb', line 53

def current_branch
  branch = `hg branch`
  branch.chomp!
  return branch
end

#current_commitObject



89
90
91
92
93
# File 'lib/tddium/scm/hg.rb', line 89

def current_commit
  commit = `hg id -i`
  commit.chomp!
  return commit
end

#default_branchObject



59
60
61
62
# File 'lib/tddium/scm/hg.rb', line 59

def default_branch
  # NOTE: not necessarily quite right in HG 2.1+ with a default bookmark
  return "default"
end

#hg_push(uri) ⇒ Object



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

def hg_push(uri)
  cmd = "hg push -f -b #{self.current_branch} "
  cmd += " #{uri}"

  # git outputs something to stderr when it runs git push.
  # hg doesn't always ... so show the command that's being run and its
  # output to indicate progress.
  puts cmd
  puts `#{cmd}`
  return [0,1].include?( $?.exitstatus )
end

#ignore_pathObject



48
49
50
51
# File 'lib/tddium/scm/hg.rb', line 48

def ignore_path
  path = File.join(self.root, Config::HG_IGNORE)
  return path
end

#number_of_commits(id_from, id_to) ⇒ Object



100
101
102
103
# File 'lib/tddium/scm/hg.rb', line 100

def number_of_commits(id_from, id_to)
  result = `hg log --template='{node}\\n' #{id_from}..#{id_to}`
  result.split("\n").length
end

#origin_urlObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tddium/scm/hg.rb', line 36

def origin_url
  result = `(hg paths default || echo HG_FAILED) 2>/dev/null`
  return nil if result =~ /HG_FAILED/
  result.strip!
  u = URI.parse(result) rescue nil
  if u && u.host.nil? then
    warn(Text::Warning::HG_PATHS_DEFAULT_NOT_URI)
    return nil
  end
  return result
end

#push_latest(session_data, suite_details, options = {}) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/tddium/scm/hg.rb', line 80

def push_latest(session_data, suite_details, options={})
  uri = if options[:use_private_uri] then
          suite_details["git_repo_private_uri"] || suite_details["git_repo_uri"]
        else
          suite_details["git_repo_uri"]
        end
  self.hg_push(uri)
end

#repo?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
# File 'lib/tddium/scm/hg.rb', line 14

def repo?
  if File.directory?('.hg') then
    return true
  end
  ignore = `hg status 2>&1`
  ok = $?.success?
  return ok
end

#repo_nameObject



32
33
34
# File 'lib/tddium/scm/hg.rb', line 32

def repo_name
  return File.basename(self.root)
end

#rootObject



23
24
25
26
27
28
29
30
# File 'lib/tddium/scm/hg.rb', line 23

def root
  root = `hg root`
  if $?.exitstatus == 0 then
    root.chomp! if root
    return root
  end
  return Dir.pwd
end

#scm_nameObject



10
11
12
# File 'lib/tddium/scm/hg.rb', line 10

def scm_name
  return 'hg'
end