Module: Gity::Operation::Add

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

Instance Method Summary collapse

Methods included from Common

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

Instance Method Details

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



8
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
39
40
41
42
43
44
45
46
# File 'lib/gity/operation/add.rb', line 8

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

  begin
    sels = _prmt.multi_select(_fmt("Please select all files to add to staging : "), filter: true, per_page: 10) do |m|
      m.choice _fmt("All"), "."
      efiles.sort.each do |f|
        m.choice _fmt(f),f.path
      end

      efiles2.sort.each do |f|
        if f.is_a?(GitCli::Delta::NewDir)
          m.choice _fmt(f),f.path if f.has_files?
        else
          m.choice _fmt(f),f.path
        end
      end

      m.choice "Done", :done
    end

    if sels.length == 0 or (sels.length == 1 and sels.first == :done)
      # user not selected any files
    else
      block.call(:before_add_to_staging, sels) if block
      st, res = ws.add_to_staging(*sels)
      block.call(:after_add_to_staging, st, res) if block
      raise OperationError, "Add to staging failed with error : #{res}" if not st
    end

  rescue TTY::Reader::InputInterrupt
  end
end