Module: Gity::Operation::Commit

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

Instance Method Summary collapse

Methods included from Common

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

Instance Method Details

#commit(ws, files) ⇒ Object



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

def commit(ws, files)

  _cls
  print_header
  _prmt.puts
  print_workspace_items(ws, files, skip_other_files: true)
  _prmt.puts
  efiles = files.modified[:files] + files.modified[:dirs] + files.new[:files] + files.new[:dirs] + files.deleted[:files] + files.deleted[:dirs]

  begin
    sels = _prmt.multi_select(_fmt("Please select all files to be committed in this session : "), filter: true, per_page: 10) do |m|
      efiles.sort.each do |f|
        m.choice f,f.path
      end
    end

    if not_empty?(sels)
      st, res = ws.add_to_staging(*sels)
      raise OperationError, "Adding files to staging failed with error #{res}" if not st
    end

    _cls
    print_overview(ws, skip_other_files: true) do |ws, files, opts|

      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

      st, res = ws.commit(msg)
      raise OperationError, "Commit all failed with error : #{res}" if not st

    end

  rescue TTY::Reader::InputInterrupt
    _prmt.puts _fmt "Commit aborted"
  end

end