gity 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/gity/common.rb +14 -0
- data/lib/gity/flash.rb +59 -0
- data/lib/gity/git_log.rb +1 -1
- data/lib/gity/landing.rb +36 -9
- data/lib/gity/operation/add.rb +3 -1
- data/lib/gity/operation/commit.rb +35 -13
- data/lib/gity/operation/commit_all.rb +5 -1
- data/lib/gity/operation/delete.rb +7 -1
- data/lib/gity/operation/ignore.rb +3 -1
- data/lib/gity/operation/remove_staged.rb +3 -1
- data/lib/gity/operation.rb +13 -10
- data/lib/gity/overview.rb +2 -2
- data/lib/gity/version.rb +1 -1
- data/lib/gity.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7b88428dddbf037a5df49d58554541add9012728a718fb0af4f746915d7f329
|
4
|
+
data.tar.gz: 1f9f993d3c332212a3e2e2e3d2a18447c98ae6cced9bea174ad3b9d80b77bf9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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
|
-
|
24
|
+
begin
|
25
|
+
loop do
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
_prmt.puts
|
29
|
-
res = print_overview(@ws, opts) do |ws, files, optts|
|
27
|
+
_cls
|
28
|
+
print_header
|
30
29
|
_prmt.puts
|
31
|
-
|
32
|
-
|
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
|
-
|
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
|
data/lib/gity/operation/add.rb
CHANGED
@@ -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
|
-
|
33
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
45
|
-
|
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
|
-
|
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
|
data/lib/gity/operation.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
-
|
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}
|
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
data/lib/gity.rb
CHANGED
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.
|
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-
|
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
|