Class: Repository::PendingCommit

Inherits:
Object
  • Object
show all
Defined in:
lib/repository/pending_commit.rb

Constant Summary collapse

Error =
Class.new(StandardError)
HEAD_FILES =
{
  :merge       => "MERGE_HEAD",
  :cherry_pick => "CHERRY_PICK_HEAD",
  :revert      => "REVERT_HEAD"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pathname) ⇒ PendingCommit

Returns a new instance of PendingCommit.



14
15
16
17
# File 'lib/repository/pending_commit.rb', line 14

def initialize(pathname)
  @pathname     = pathname
  @message_path = pathname.join("MERGE_MSG")
end

Instance Attribute Details

#message_pathObject (readonly)

Returns the value of attribute message_path.



12
13
14
# File 'lib/repository/pending_commit.rb', line 12

def message_path
  @message_path
end

Instance Method Details

#clear(type = :merge) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/repository/pending_commit.rb', line 50

def clear(type = :merge)
  head_path = @pathname.join(HEAD_FILES.fetch(type))
  File.unlink(head_path)
  File.unlink(@message_path)
rescue Errno::ENOENT
  name = head_path.basename
  raise Error, "There is no merge to abort (#{ name } missing)."
end

#in_progress?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/repository/pending_commit.rb', line 25

def in_progress?
  merge_type != nil
end

#merge_messageObject



46
47
48
# File 'lib/repository/pending_commit.rb', line 46

def merge_message
  File.read(@message_path)
end

#merge_oid(type = :merge) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/repository/pending_commit.rb', line 38

def merge_oid(type = :merge)
  head_path = @pathname.join(HEAD_FILES.fetch(type))
  File.read(head_path).strip
rescue Errno::ENOENT
  name = head_path.basename
  raise Error, "There is no merge in progress (#{ name } missing)."
end

#merge_typeObject



29
30
31
32
33
34
35
36
# File 'lib/repository/pending_commit.rb', line 29

def merge_type
  HEAD_FILES.each do |type, name|
    path = @pathname.join(name)
    return type if File.file?(path)
  end

  nil
end

#start(oid, type = :merge) ⇒ Object



19
20
21
22
23
# File 'lib/repository/pending_commit.rb', line 19

def start(oid, type = :merge)
  path  = @pathname.join(HEAD_FILES.fetch(type))
  flags = File::WRONLY | File::CREAT | File::EXCL
  File.open(path, flags) { |f| f.puts(oid) }
end