Module: Gity::Operation::CommitAll

Includes:
Common
Included in:
Gity::Operation
Defined in:
lib/gity/operation/commit_all.rb

Instance Method Summary collapse

Methods included from Common

#_cls, #_flash, #_fmt, #_logger, #_operation_done, #_pastel, #_prmt, #print_header

Instance Method Details

#commit_all(ws, files, &block) ⇒ Object



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
# File 'lib/gity/operation/commit_all.rb', line 9

def commit_all(ws, files, &block)
  _prmt.puts _fmt("Files eligible to be committed : ")
  [:staged, :modified, :deleted].each do |cat|
    files.send(cat).each do |k,v|
      v.each do |vv|
        _prmt.puts _fmt(vv, :magenta)
      end
    end
  end

  begin
    msg = ""
    loop do
      msg = _prmt.ask(_fmt("\n Commit message (Ctrl-c to go back) : "), required: true)
      confirm = _prmt.yes?(_fmt(" Commit message : #{msg}\n Proceed? No to provide a new commit message "))
      if confirm
        break
      end
    end

    oldMsg = msg.clone
    msg = block.call(:before_commit_all_message, msg) if block
    _logger.debug "Commit all message changed by listener. Old '#{oldMsg}' / New '#{msg}' "
    st, res = ws.commit_all(msg)
    block.call(:after_commit_all_message, st, res) if block
    raise OperationError, "Commit all failed with error : #{res}" if not st
  rescue TTY::Reader::InputInterrupt
    _prmt.puts _fmt "Commit all aborted"
  end
end