class BetweenMeals::Repo::Hg
Public Instance Methods
Source
# File lib/between_meals/repo/hg.rb, line 47 def changes(start_ref, end_ref) valid_ref?(start_ref) valid_ref?(end_ref) if end_ref stdout = @cmd.status(start_ref, end_ref).stdout begin parse_status(stdout).compact rescue StandardError => e # We've seen some weird non-reproducible failures here @logger.error( 'Something went wrong. Please report this output.', ) @logger.error(e) stdout.lines.each do |line| @logger.error(line.strip) end exit(1) end end
Return files changed between two revisions
Source
# File lib/between_meals/repo/hg.rb, line 42 def checkout(url) @cmd.clone(url, @repo_path) end
Source
# File lib/between_meals/repo/hg.rb, line 116 def email username[2] rescue StandardError nil end
Source
# File lib/between_meals/repo/hg.rb, line 34 def exists? Dir.exist?(Pathname.new(@repo_path).join('.hg')) end
Source
# File lib/between_meals/repo/hg.rb, line 75 def files @cmd.manifest.stdout.split("\n").map do |x| { :path => x, :status => :created } end end
Return all files
Source
# File lib/between_meals/repo/hg.rb, line 81 def head_parents [{ :time => Time.parse(@cmd.log('date|isodate', 'master').stdout), :rev => @cmd.log('node', 'master').stdout, }] rescue StandardError [{ :time => nil, :rev => nil, }] end
Source
# File lib/between_meals/repo/hg.rb, line 38 def head_rev @cmd.log('node').stdout end
Source
# File lib/between_meals/repo/hg.rb, line 104 def last_msg @cmd.log('desc').stdout rescue StandardError nil end
Source
# File lib/between_meals/repo/hg.rb, line 110 def last_msg=(msg) if last_msg.strip != msg.strip @cmd.amend(msg.strip) end end
Source
# File lib/between_meals/repo/hg.rb, line 122 def name username[1] rescue StandardError nil end
Source
# File lib/between_meals/repo/hg.rb, line 25 def setup @bin = 'hg' @cmd = BetweenMeals::Repo::Hg::Cmd.new( :bin => @bin, :cwd => @repo_path, :logger => @logger, ) end
Source
# File lib/between_meals/repo/hg.rb, line 66 def update @cmd.pull.stdout rescue StandardError => e @logger.error('Something went wrong with hg!') @logger.error(e) raise end
Source
# File lib/between_meals/repo/hg.rb, line 132 def upstream?(rev) # Check if commit is an ancestor of master # Returns the diff if common ancestor is found, # returns nothing if not if @cmd.rev("'ancestor(master,#{rev}) & #{rev}'").stdout.empty? return false else return true end end
Source
# File lib/between_meals/repo/hg.rb, line 143 def valid_ref?(ref) @cmd.rev(ref) return true rescue StandardError raise Changeset::ReferenceError end
Private Instance Methods
Source
# File lib/between_meals/repo/hg.rb, line 156 def parse_status(changes) # The codes used to show the status of files are: # # M = modified # A = added # R = removed # C = clean # ! = missing (deleted by non-hg command, but still tracked) # ? = not tracked # I = ignored # = origin of the previous file (with --copies) changes.lines.map do |line| parts = line.chomp.split(nil, 2) case parts[0] when 'A' { :status => :added, :path => parts[1], } when 'C' { :status => :clean, :path => parts[1], } when 'R' { :status => :deleted, :path => parts[1], } when 'M' { :status => :modified, :path => parts[1], } when '!' { :status => :missing, :path => parts[1], } when '?' { :status => :untracked, :path => parts[1], } when 'I' { :status => :ignored, :path => parts[1], } else fail 'Failed to parse repo diff line.' end end end
Source
# File lib/between_meals/repo/hg.rb, line 152 def username @cmd.username.stdout.lines.first.strip.match(/^(.*?)(?:\s<(.*)>)?$/) end