Module: Gity::Operation::Commit
Instance Method Summary collapse
Methods included from Status
Methods included from Common
#_cls, #_flash, #_fmt, #_logger, #_operation_done, #_pastel, #_prmt, #print_header
Instance Method Details
#commit(ws, files, &block) ⇒ Object
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/gity/operation/commit.rb', line 14 def commit(ws, files, &block) _cls print_header _prmt.puts print_workspace_items(ws, files, skip_other_files: true) _prmt.puts efiles = files.modified[:files] + files.modified[:dirs] + files.deleted[:files] + files.deleted[:dirs] efiles2 = files.new[:files] + files.new[: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 _fmt(f),f.path end efiles2.sort.each do |f| case f when GitCli::Delta::NewDir m.choice _fmt(f),f.path if f.has_files? else m.choice _fmt(f),f.path end end # allow to exit without selecting any files m.choice "Done", :done end sels.delete(:done) # possible no files available to be add to staging as all files already in staging if not_empty?(sels) 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, "Adding files to staging failed with error #{res}" if not st end st = status(ws) if st.has_staged? _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 oldMsg = msg.clone msg = block.call(:before_commit_message, msg) if block _logger.debug "Commit message changed by listener. Old '#{oldMsg}' / New '#{msg}' " st, res = ws.commit(msg) block.call(:after_commit_message, st, res) if block raise OperationError, "Commit all failed with error : #{res}" if not st end else _flash.add_info "No staged file(s) to be committed" end rescue TTY::Reader::InputInterrupt _flash.add_info "Commit aborted" end end |