gity 0.1.0 → 0.1.1

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: 8ad3e13e041d3318b74c725c85b3e54ba508e8137339e3f2ca2ef1510360363d
4
+ data.tar.gz: 7bc3e2fd3dc5a4b62e32cdb3c5a8f83cf63a225b7516a38c84de7d9d934c85c2
5
5
  SHA512:
6
- metadata.gz: 2a0a18d09953679b1ab908419988e6b57bda938dc258c8df20ebd760f78e1f56303ecbb6aac60377195cfc7eadf606efe2512827d54cc15c8155c4f41b340e45
7
- data.tar.gz: fbac989ab76565cfe87eba0c22c64c5ff4af538238dc47ff4f035f521fe0710fd0f6b4896143f43dc7604eaec4a208353f8dcf12ce0f863204bb0737d1ff6557
6
+ metadata.gz: d3573cbd151944bc04fc435929f59ac27d165016122fe03a38ef3318299a96fe0ca164a17aaa8eea96e6de45c700765fa14f41ec353e350c668deedb2610577e
7
+ data.tar.gz: 47ada26af980984dac10826dcac61bf5b310d8a02ca6c0f4df595fce432467e99b95016c42d06c04d205dd33f058e1af731fc2510cc1d2d65ab9bd6f7758bc5a
data/lib/gity/common.rb CHANGED
@@ -29,6 +29,15 @@ module Gity
29
29
  " #{res}"
30
30
  end
31
31
 
32
+ def _operation_done(no_exit = false)
33
+ no_exit = false if no_exit.nil?
34
+ if no_exit
35
+ raise OperationCompleted
36
+ else
37
+ exit(0)
38
+ end
39
+ end
40
+
32
41
  def _cls
33
42
  print "\e[2J\e[f"
34
43
  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,18 +21,21 @@ 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
+ prompt_operation(ws, files, optts, &block)
33
+ end
33
34
 
34
35
 
35
- break if not opts[:loop] or res.clean?
36
+ break if not opts[:loop] or res.clean?
37
+ end
38
+ rescue OperationCompleted
36
39
  end
37
40
 
38
41
  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
@@ -8,7 +8,7 @@ module Gity
8
8
  module Commit
9
9
  include Common
10
10
 
11
- def commit(ws, files)
11
+ def commit(ws, files, &block)
12
12
 
13
13
  _cls
14
14
  print_header
@@ -25,7 +25,9 @@ module Gity
25
25
  end
26
26
 
27
27
  if not_empty?(sels)
28
+ block.call(:before_add_to_staging, sels) if block
28
29
  st, res = ws.add_to_staging(*sels)
30
+ block.call(:after_add_to_staging, st, res) if block
29
31
  raise OperationError, "Adding files to staging failed with error #{res}" if not st
30
32
  end
31
33
 
@@ -41,7 +43,11 @@ module Gity
41
43
  end
42
44
  end
43
45
 
46
+ oldMsg = msg.clone
47
+ msg = block.call(:before_commit_message, msg) if block
48
+ _logger.debug "Commit message changed by listener. Old '#{oldMsg}' / New '#{msg}' "
44
49
  st, res = ws.commit(msg)
50
+ block.call(:after_commit_message, st, res) if block
45
51
  raise OperationError, "Commit all failed with error : #{res}" if not st
46
52
 
47
53
  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]
@@ -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/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.1"
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.1
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