gity 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d1d759aad76467ded2633edabaea4c77a4b0c81992dc5a01d5b3194665419642
4
- data.tar.gz: b001c69f4ea53f7651702c355ab3cc038d0f90848e63b42bead2cc27f0b90c43
3
+ metadata.gz: a7b88428dddbf037a5df49d58554541add9012728a718fb0af4f746915d7f329
4
+ data.tar.gz: 1f9f993d3c332212a3e2e2e3d2a18447c98ae6cced9bea174ad3b9d80b77bf9e
5
5
  SHA512:
6
- metadata.gz: 2a0a18d09953679b1ab908419988e6b57bda938dc258c8df20ebd760f78e1f56303ecbb6aac60377195cfc7eadf606efe2512827d54cc15c8155c4f41b340e45
7
- data.tar.gz: fbac989ab76565cfe87eba0c22c64c5ff4af538238dc47ff4f035f521fe0710fd0f6b4896143f43dc7604eaec4a208353f8dcf12ce0f863204bb0737d1ff6557
6
+ metadata.gz: 4f9c78b33bc01121878c0424f7b7755154719fd801e1a334f889372b5694d27df9207a4a8e7bb064390a5ba60b861fb98c6b3f225b41cd0c11337617fc226aef
7
+ data.tar.gz: c67f13bb05a7f2c157e495d07ea1d68f99022b360da5479ad8cf6eeab69b5b51c9c621828824995c3f7fbe3bf56e186d27c704a63ea5b28c26ca906155990ccb
data/lib/gity/common.rb CHANGED
@@ -1,4 +1,5 @@
1
1
 
2
+ require_relative 'flash'
2
3
 
3
4
  module Gity
4
5
  module Common
@@ -29,6 +30,19 @@ module Gity
29
30
  " #{res}"
30
31
  end
31
32
 
33
+ def _flash
34
+ Flash.instance
35
+ end
36
+
37
+ def _operation_done(no_exit = false)
38
+ no_exit = false if no_exit.nil?
39
+ if no_exit
40
+ raise OperationCompleted
41
+ else
42
+ exit(0)
43
+ end
44
+ end
45
+
32
46
  def _cls
33
47
  print "\e[2J\e[f"
34
48
  end
data/lib/gity/flash.rb ADDED
@@ -0,0 +1,59 @@
1
+
2
+ require 'singleton'
3
+
4
+ module Gity
5
+ class Flash
6
+ include Singleton
7
+ include TR::CondUtils
8
+
9
+ def add_info(msg)
10
+ info_msg << msg if not_empty?(msg)
11
+ end
12
+
13
+ def add_error(msg)
14
+ error_msg << msg if not_empty?(msg)
15
+ end
16
+
17
+ def add_warning(msg)
18
+ warning_msg << msg if not_empty?(msg)
19
+ end
20
+
21
+ def has_messages?
22
+ not_empty?(info_msg) or not_empty?(error_msg) or not_empty?(warning_msg)
23
+ end
24
+
25
+ def has_info_msg?
26
+ not_empty?(info_msg)
27
+ end
28
+
29
+ def has_err_msg?
30
+ not_empty?(error_msg)
31
+ end
32
+
33
+ def has_warning_msg?
34
+ not_empty?(warning_msg)
35
+ end
36
+
37
+ def info_msg
38
+ if @_infoMsg.nil?
39
+ @_infoMsg = []
40
+ end
41
+ @_infoMsg
42
+ end
43
+
44
+ def error_msg
45
+ if @_errMsg.nil?
46
+ @_errMsg = []
47
+ end
48
+ @_errMsg
49
+ end
50
+
51
+ def warning_msg
52
+ if @_warnMsg.nil?
53
+ @_warnMsg = []
54
+ end
55
+ @_warnMsg
56
+ end
57
+
58
+ end
59
+ end
data/lib/gity/git_log.rb CHANGED
@@ -28,7 +28,7 @@ module Gity
28
28
  entry.id = ll[0]
29
29
  entry.timestamp = ll[1]
30
30
  by = ll[2].split(",")
31
- entry.commit_by = "#{by[0]} <#{by[1]}>"
31
+ entry.commit_by = "#{by[0]} <#{by[1].strip}>"
32
32
  entry.commit_notes = ll[3]
33
33
  entries << entry
34
34
  end
data/lib/gity/landing.rb CHANGED
@@ -13,7 +13,7 @@ module Gity
13
13
  include Operation
14
14
  include Common
15
15
 
16
- def run(root, opts = {})
16
+ def run(root, opts = {}, &block)
17
17
 
18
18
  @ws = GitCli::Workspace.new(root)
19
19
  raise Error, "Given path '#{root}' is not a workspace" if not @ws.is_workspace?
@@ -21,21 +21,48 @@ module Gity
21
21
  opts = {} if opts.nil?
22
22
  opts[:loop] = true if is_empty?(opts[:loop])
23
23
 
24
- loop do
24
+ begin
25
+ loop do
25
26
 
26
- _cls
27
- print_header
28
- _prmt.puts
29
- res = print_overview(@ws, opts) do |ws, files, optts|
27
+ _cls
28
+ print_header
30
29
  _prmt.puts
31
- prompt_operation(ws, files, optts)
32
- end
30
+ res = print_overview(@ws, opts) do |ws, files, optts|
31
+ _prmt.puts
32
+ process_flash
33
+ _prmt.puts
34
+ prompt_operation(ws, files, optts, &block)
35
+ end
33
36
 
34
37
 
35
- break if not opts[:loop] or res.clean?
38
+ break if not opts[:loop] or res.clean?
39
+ end
40
+ rescue OperationCompleted
36
41
  end
37
42
 
38
43
  end
39
44
 
45
+ def process_flash
46
+ if Flash.instance.has_messages?
47
+ if Flash.instance.has_info_msg?
48
+ while Flash.instance.has_info_msg?
49
+ _prmt.puts _fmt Flash.instance.info_msg.pop, :magenta
50
+ end
51
+ end
52
+
53
+ if Flash.instance.has_err_msg?
54
+ while Flash.instance.has_err_msg?
55
+ _prmt.puts _fmt Flash.instance.err_msg.pop, :red
56
+ end
57
+ end
58
+
59
+ if Flash.instance.has_warning_msg?
60
+ while Flash.instance.has_warning_msg?
61
+ _prmt.puts _fmt Flash.instance.warning_msg.pop, :bright_yellow
62
+ end
63
+ end
64
+ end
65
+ end
66
+
40
67
  end
41
68
  end
@@ -5,7 +5,7 @@ module Gity
5
5
  module Add
6
6
  include Common
7
7
 
8
- def add(ws, files)
8
+ def add(ws, files, &block)
9
9
  _cls
10
10
  print_header
11
11
  _prmt.puts
@@ -21,7 +21,9 @@ module Gity
21
21
  end
22
22
  end
23
23
 
24
+ block.call(:before_add_to_staging, sels) if block
24
25
  st, res = ws.add_to_staging(*sels)
26
+ block.call(:after_add_to_staging, st, res) if block
25
27
  raise OperationError, "Add to staging failed with error : #{res}" if not st
26
28
 
27
29
  rescue TTY::Reader::InputInterrupt
@@ -3,12 +3,15 @@ require_relative '../common'
3
3
 
4
4
  require_relative '../overview'
5
5
 
6
+ require_relative '../status'
7
+
6
8
  module Gity
7
9
  module Operation
8
10
  module Commit
9
11
  include Common
12
+ include Status
10
13
 
11
- def commit(ws, files)
14
+ def commit(ws, files, &block)
12
15
 
13
16
  _cls
14
17
  print_header
@@ -22,32 +25,51 @@ module Gity
22
25
  efiles.sort.each do |f|
23
26
  m.choice f,f.path
24
27
  end
28
+
29
+ # allow to exit without selecting any files
30
+ m.choice "Done", :done
25
31
  end
26
32
 
33
+ sels.delete(:done)
34
+
35
+ # possible no files available to be add to staging as all files already in staging
27
36
  if not_empty?(sels)
37
+ block.call(:before_add_to_staging, sels) if block
28
38
  st, res = ws.add_to_staging(*sels)
39
+ block.call(:after_add_to_staging, st, res) if block
29
40
  raise OperationError, "Adding files to staging failed with error #{res}" if not st
30
41
  end
31
42
 
32
- _cls
33
- print_overview(ws, skip_other_files: true) do |ws, files, opts|
43
+ st = status(ws)
44
+ if st.has_staged?
45
+
46
+ _cls
47
+ print_overview(ws, skip_other_files: true) do |ws, files, opts|
34
48
 
35
- msg = ""
36
- loop do
37
- msg = _prmt.ask(_fmt("\n Commit message (Ctrl-c to go back) : "), required: true)
38
- confirm = _prmt.yes?(_fmt(" Commit message : #{msg}\n Proceed? No to provide a new commit message "))
39
- if confirm
40
- break
49
+ msg = ""
50
+ loop do
51
+ msg = _prmt.ask(_fmt("\n Commit message (Ctrl-c to go back) : "), required: true)
52
+ confirm = _prmt.yes?(_fmt(" Commit message : #{msg}\n Proceed? No to provide a new commit message "))
53
+ if confirm
54
+ break
55
+ end
41
56
  end
42
- end
43
57
 
44
- st, res = ws.commit(msg)
45
- raise OperationError, "Commit all failed with error : #{res}" if not st
58
+ oldMsg = msg.clone
59
+ msg = block.call(:before_commit_message, msg) if block
60
+ _logger.debug "Commit message changed by listener. Old '#{oldMsg}' / New '#{msg}' "
61
+ st, res = ws.commit(msg)
62
+ block.call(:after_commit_message, st, res) if block
63
+ raise OperationError, "Commit all failed with error : #{res}" if not st
64
+
65
+ end
46
66
 
67
+ else
68
+ _flash.add_info "No staged file(s) to be committed"
47
69
  end
48
70
 
49
71
  rescue TTY::Reader::InputInterrupt
50
- _prmt.puts _fmt "Commit aborted"
72
+ _flash.add_info "Commit aborted"
51
73
  end
52
74
 
53
75
  end
@@ -6,7 +6,7 @@ module Gity
6
6
  module CommitAll
7
7
  include Common
8
8
 
9
- def commit_all(ws, files)
9
+ def commit_all(ws, files, &block)
10
10
  _prmt.puts _fmt("Files eligible to be committed : ")
11
11
  [:staged, :modified, :deleted].each do |cat|
12
12
  files.send(cat).each do |k,v|
@@ -26,7 +26,11 @@ module Gity
26
26
  end
27
27
  end
28
28
 
29
+ oldMsg = msg.clone
30
+ msg = block.call(:before_commit_all_message, msg) if block
31
+ _logger.debug "Commit all message changed by listener. Old '#{oldMsg}' / New '#{msg}' "
29
32
  st, res = ws.commit_all(msg)
33
+ block.call(:after_commit_all_message, st, res) if block
30
34
  raise OperationError, "Commit all failed with error : #{res}" if not st
31
35
  rescue TTY::Reader::InputInterrupt
32
36
  _prmt.puts _fmt "Commit all aborted"
@@ -5,7 +5,7 @@ module Gity
5
5
  module Delete
6
6
  include Common
7
7
 
8
- def delete(ws, files)
8
+ def delete(ws, files, &block)
9
9
  _cls
10
10
  print_header
11
11
  _prmt.puts
@@ -25,19 +25,25 @@ module Gity
25
25
  if s.is_a?(GitCli::Delta::NewFile)
26
26
  skip = _prmt.no? _fmt "Proceed to delete regular file '#{s}'? "
27
27
  if not skip
28
+ block.call(:before_delete_new_file, s) if block
28
29
  FileUtils.rm(s.path)
30
+ block.call(:after_delete_new_file, s) if block
29
31
  end
30
32
 
31
33
  elsif s.is_a?(GitCli::Delta::ModifiedFile)
32
34
  # not staged
33
35
  skip = _prmt.no? _fmt "Proceed to delete modified file '#{s}'? "
34
36
  if not skip
37
+ block.call(:before_delete_modified_file, s) if block
35
38
  ws.remove_from_vcs(s.path)
39
+ block.call(:after_delete_modified_file, s) if block
36
40
  end
37
41
  elsif s.is_a?(GitCli::Delta::StagedFile)
38
42
  skip = _prmt.no? "Proceed to delete staged file '#{s}'? "
39
43
  if not skip
44
+ block.call(:before_delete_staged_file, s) if block
40
45
  ws.remove_from_staging(s.path)
46
+ block.call(:after_delete_staged_file, s) if block
41
47
  end
42
48
  end
43
49
 
@@ -5,7 +5,7 @@ module Gity
5
5
  module Ignore
6
6
  include Common
7
7
 
8
- def ignore(ws, files)
8
+ def ignore(ws, files, &block)
9
9
  _cls
10
10
  print_header
11
11
  _prmt.puts
@@ -20,7 +20,9 @@ module Gity
20
20
  end
21
21
  end
22
22
 
23
+ block.call(:before_ignore_file, sels) if block
23
24
  st, res = ws.ignore(*sels)
25
+ block.call(:after_ignore_file, sels) if block
24
26
  raise OperationError, "Ignore operation failed with error : #{res}" if not st
25
27
  rescue TTY::Reader::InputInterrupt
26
28
  end
@@ -5,7 +5,7 @@ module Gity
5
5
  module RemoveStaged
6
6
  include Common
7
7
 
8
- def remove_staged(ws, files)
8
+ def remove_staged(ws, files, &block)
9
9
  _cls
10
10
  print_header
11
11
  _prmt.puts
@@ -19,7 +19,9 @@ module Gity
19
19
  end
20
20
  end
21
21
 
22
+ block.call(:before_remove_staged_file, sels) if block
22
23
  st, res = ws.remove_from_staging(*sels)
24
+ block.call(:after_remove_staged_file, sels) if block
23
25
  raise OperationError, "Remove from staging failed with error : #{res}" if not st
24
26
 
25
27
  end
@@ -20,7 +20,7 @@ module Gity
20
20
  include Diff
21
21
  include Delete
22
22
 
23
- def prompt_operation(ws, files, opts = {})
23
+ def prompt_operation(ws, files, opts = {}, &block)
24
24
 
25
25
  opts = {} if opts.nil?
26
26
  defOps = [:commit_all, :commit, :add, :ignore, :remove_staged, :diff, :delete]
@@ -31,7 +31,7 @@ module Gity
31
31
  when :commit_all
32
32
  selOpts["Commit all"] = o if files.has_staged? or files.has_modified? or files.has_deleted?
33
33
  when :commit
34
- selOpts["Commit staged"] = o if files.has_staged?
34
+ selOpts["Commit"] = o if files.has_staged? or files.has_new? or files.has_modified?
35
35
  when :add
36
36
  selOpts["Add"] = o if files.has_new?
37
37
  when :ignore
@@ -58,27 +58,27 @@ module Gity
58
58
  when :commit_all
59
59
  _cls
60
60
  _prmt.puts
61
- commit_all(ws, files)
61
+ commit_all(ws, files, &block)
62
62
 
63
63
  when :commit
64
64
  _cls
65
65
  _prmt.puts
66
- commit(ws, files)
66
+ commit(ws, files, &block)
67
67
 
68
68
  when :add
69
69
  _cls
70
70
  _prmt.puts
71
- add(ws, files)
71
+ add(ws, files, &block)
72
72
 
73
73
  when :ignore
74
74
  _cls
75
75
  _prmt.puts
76
- ignore(ws, files)
76
+ ignore(ws, files, &block)
77
77
 
78
78
  when :remove_staged
79
79
  _cls
80
80
  _prmt.puts
81
- remove_staged(ws, files)
81
+ remove_staged(ws, files, &block)
82
82
 
83
83
  when :diff
84
84
  _cls
@@ -88,10 +88,13 @@ module Gity
88
88
  when :delete
89
89
  _cls
90
90
  _prmt.puts
91
- delete(ws, files)
91
+ delete(ws, files, &block)
92
92
 
93
93
  when :quit
94
- exit(0)
94
+ block.call(:before_quit) if block
95
+ _operation_done(opts[:no_exit])
96
+ # no_exit will reach here
97
+ block.call(:after_quit) if block
95
98
  end
96
99
 
97
100
  rescue TTY::Reader::InputInterrupt
@@ -99,7 +102,7 @@ module Gity
99
102
  _prmt.puts
100
103
  _prmt.puts _fmt "Operation aborted", :bright_yellow
101
104
  _prmt.puts
102
- exit(0)
105
+ _operation_done(opts[:no_exit])
103
106
  end
104
107
 
105
108
  end
data/lib/gity/overview.rb CHANGED
@@ -75,8 +75,8 @@ module Gity
75
75
  en = GitLogParser.new(logs)
76
76
  _prmt.puts _fmt "Last 3 last commit : "
77
77
  en.entries.each do |e|
78
- _prmt.puts _fmt "#{e.commit_by}\n #{e.timestamp}\n #{e.commit_notes}"
79
- _prmt.puts _fmt "**** ****"
78
+ _prmt.puts _fmt "#{e.commit_by} @ #{e.timestamp}\n\n #{e.commit_notes}"
79
+ _prmt.puts _fmt "\n**** ****"
80
80
  end
81
81
  _prmt.puts
82
82
  true
data/lib/gity/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gity
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/gity.rb CHANGED
@@ -15,6 +15,7 @@ module Gity
15
15
 
16
16
  class Error < StandardError; end
17
17
  class OperationError < Error; end
18
+ class OperationCompleted < Error; end
18
19
  # Your code goes here...
19
20
 
20
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-08 00:00:00.000000000 Z
11
+ date: 2023-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: toolrack
@@ -122,6 +122,7 @@ files:
122
122
  - exe/gity
123
123
  - lib/gity.rb
124
124
  - lib/gity/common.rb
125
+ - lib/gity/flash.rb
125
126
  - lib/gity/git_log.rb
126
127
  - lib/gity/landing.rb
127
128
  - lib/gity/operation.rb