gity 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/README.md +31 -0
- data/Rakefile +9 -0
- data/exe/gity +6 -0
- data/lib/gity/common.rb +71 -0
- data/lib/gity/git_log.rb +38 -0
- data/lib/gity/landing.rb +41 -0
- data/lib/gity/operation/add.rb +33 -0
- data/lib/gity/operation/commit.rb +57 -0
- data/lib/gity/operation/commit_all.rb +38 -0
- data/lib/gity/operation/delete.rb +52 -0
- data/lib/gity/operation/diff.rb +38 -0
- data/lib/gity/operation/ignore.rb +32 -0
- data/lib/gity/operation/remove_staged.rb +29 -0
- data/lib/gity/operation.rb +108 -0
- data/lib/gity/overview.rb +91 -0
- data/lib/gity/status.rb +35 -0
- data/lib/gity/status_list.rb +38 -0
- data/lib/gity/version.rb +5 -0
- data/lib/gity.rb +20 -0
- data/sig/gity.rbs +4 -0
- metadata +162 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d1d759aad76467ded2633edabaea4c77a4b0c81992dc5a01d5b3194665419642
|
4
|
+
data.tar.gz: b001c69f4ea53f7651702c355ab3cc038d0f90848e63b42bead2cc27f0b90c43
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2a0a18d09953679b1ab908419988e6b57bda938dc258c8df20ebd760f78e1f56303ecbb6aac60377195cfc7eadf606efe2512827d54cc15c8155c4f41b340e45
|
7
|
+
data.tar.gz: fbac989ab76565cfe87eba0c22c64c5ff4af538238dc47ff4f035f521fe0710fd0f6b4896143f43dc7604eaec4a208353f8dcf12ce0f863204bb0737d1ff6557
|
data/.rspec
ADDED
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Gity
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gity`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gity.
|
data/Rakefile
ADDED
data/exe/gity
ADDED
data/lib/gity/common.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Gity
|
4
|
+
module Common
|
5
|
+
|
6
|
+
def _pastel
|
7
|
+
if @_pastel.nil?
|
8
|
+
@_pastel = Pastel.new
|
9
|
+
end
|
10
|
+
@_pastel
|
11
|
+
end
|
12
|
+
|
13
|
+
def _prmt
|
14
|
+
if @_prmt.nil?
|
15
|
+
@_prmt = TTY::Prompt.new
|
16
|
+
end
|
17
|
+
@_prmt
|
18
|
+
end
|
19
|
+
|
20
|
+
def _fmt(msg, *opts)
|
21
|
+
res = msg
|
22
|
+
|
23
|
+
if not_empty?(opts)
|
24
|
+
opts.each do |f|
|
25
|
+
res = _pastel.send(f, res)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
" #{res}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def _cls
|
33
|
+
print "\e[2J\e[f"
|
34
|
+
end
|
35
|
+
|
36
|
+
def print_header
|
37
|
+
_prmt.puts _fmt "gity version #{Gity::VERSION}"
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def _logger(tag = nil, &block)
|
42
|
+
if @_logger.nil?
|
43
|
+
if ENV['GITY_LOG_TO_STDOUT'] == "true"
|
44
|
+
@_logger = TeLogger::Tlogger.new
|
45
|
+
else
|
46
|
+
@_logger = TeLogger::Tlogger.new("gity.log",5, 5*1024*1024)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
if block
|
51
|
+
if not_empty?(tag)
|
52
|
+
@_logger.with_tag(tag, &block)
|
53
|
+
else
|
54
|
+
@_logger.with_tag(@_logger.tag, &block)
|
55
|
+
end
|
56
|
+
else
|
57
|
+
if is_empty?(tag)
|
58
|
+
@_logger.tag = :gity
|
59
|
+
@_logger
|
60
|
+
else
|
61
|
+
# no block but tag is given? hmm
|
62
|
+
@_logger.tag = tag
|
63
|
+
@_logger
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end # _logger
|
68
|
+
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
data/lib/gity/git_log.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Gity
|
4
|
+
class GitLogEntry
|
5
|
+
attr_accessor :id, :timestamp, :commit_by, :commit_notes
|
6
|
+
end
|
7
|
+
|
8
|
+
class GitLogParser
|
9
|
+
def initialize(logs)
|
10
|
+
@logs = logs
|
11
|
+
parse(logs)
|
12
|
+
end
|
13
|
+
|
14
|
+
def entries
|
15
|
+
if @_entries.nil?
|
16
|
+
@_entries = []
|
17
|
+
end
|
18
|
+
@_entries
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def parse(logs)
|
23
|
+
# this follows standard format as in GitCli
|
24
|
+
# log format
|
25
|
+
logs.each_line do |l|
|
26
|
+
ll = l.split("|")
|
27
|
+
entry = GitLogEntry.new
|
28
|
+
entry.id = ll[0]
|
29
|
+
entry.timestamp = ll[1]
|
30
|
+
by = ll[2].split(",")
|
31
|
+
entry.commit_by = "#{by[0]} <#{by[1]}>"
|
32
|
+
entry.commit_notes = ll[3]
|
33
|
+
entries << entry
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/lib/gity/landing.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
require 'git_cli'
|
3
|
+
|
4
|
+
require_relative 'common'
|
5
|
+
require_relative 'overview'
|
6
|
+
require_relative 'operation'
|
7
|
+
|
8
|
+
module Gity
|
9
|
+
class Landing
|
10
|
+
include TR::CondUtils
|
11
|
+
|
12
|
+
include Overview
|
13
|
+
include Operation
|
14
|
+
include Common
|
15
|
+
|
16
|
+
def run(root, opts = {})
|
17
|
+
|
18
|
+
@ws = GitCli::Workspace.new(root)
|
19
|
+
raise Error, "Given path '#{root}' is not a workspace" if not @ws.is_workspace?
|
20
|
+
|
21
|
+
opts = {} if opts.nil?
|
22
|
+
opts[:loop] = true if is_empty?(opts[:loop])
|
23
|
+
|
24
|
+
loop do
|
25
|
+
|
26
|
+
_cls
|
27
|
+
print_header
|
28
|
+
_prmt.puts
|
29
|
+
res = print_overview(@ws, opts) do |ws, files, optts|
|
30
|
+
_prmt.puts
|
31
|
+
prompt_operation(ws, files, optts)
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
break if not opts[:loop] or res.clean?
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
require_relative '../common'
|
3
|
+
module Gity
|
4
|
+
module Operation
|
5
|
+
module Add
|
6
|
+
include Common
|
7
|
+
|
8
|
+
def add(ws, files)
|
9
|
+
_cls
|
10
|
+
print_header
|
11
|
+
_prmt.puts
|
12
|
+
print_workspace_items(ws, files, skip_other_files: true)
|
13
|
+
_prmt.puts
|
14
|
+
efiles = files.modified[:files] + files.new[:files] + files.deleted[:files]
|
15
|
+
|
16
|
+
begin
|
17
|
+
sels = _prmt.multi_select(_fmt("Please select all files to add to staging : "), filter: true, per_page: 10) do |m|
|
18
|
+
m.choice "All", "."
|
19
|
+
efiles.sort.each do |f|
|
20
|
+
m.choice f,f.path
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
st, res = ws.add_to_staging(*sels)
|
25
|
+
raise OperationError, "Add to staging failed with error : #{res}" if not st
|
26
|
+
|
27
|
+
rescue TTY::Reader::InputInterrupt
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
|
2
|
+
require_relative '../common'
|
3
|
+
|
4
|
+
require_relative '../overview'
|
5
|
+
|
6
|
+
module Gity
|
7
|
+
module Operation
|
8
|
+
module Commit
|
9
|
+
include Common
|
10
|
+
|
11
|
+
def commit(ws, files)
|
12
|
+
|
13
|
+
_cls
|
14
|
+
print_header
|
15
|
+
_prmt.puts
|
16
|
+
print_workspace_items(ws, files, skip_other_files: true)
|
17
|
+
_prmt.puts
|
18
|
+
efiles = files.modified[:files] + files.modified[:dirs] + files.new[:files] + files.new[:dirs] + files.deleted[:files] + files.deleted[:dirs]
|
19
|
+
|
20
|
+
begin
|
21
|
+
sels = _prmt.multi_select(_fmt("Please select all files to be committed in this session : "), filter: true, per_page: 10) do |m|
|
22
|
+
efiles.sort.each do |f|
|
23
|
+
m.choice f,f.path
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if not_empty?(sels)
|
28
|
+
st, res = ws.add_to_staging(*sels)
|
29
|
+
raise OperationError, "Adding files to staging failed with error #{res}" if not st
|
30
|
+
end
|
31
|
+
|
32
|
+
_cls
|
33
|
+
print_overview(ws, skip_other_files: true) do |ws, files, opts|
|
34
|
+
|
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
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
st, res = ws.commit(msg)
|
45
|
+
raise OperationError, "Commit all failed with error : #{res}" if not st
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
rescue TTY::Reader::InputInterrupt
|
50
|
+
_prmt.puts _fmt "Commit aborted"
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
require_relative '../common'
|
3
|
+
|
4
|
+
module Gity
|
5
|
+
module Operation
|
6
|
+
module CommitAll
|
7
|
+
include Common
|
8
|
+
|
9
|
+
def commit_all(ws, files)
|
10
|
+
_prmt.puts _fmt("Files eligible to be committed : ")
|
11
|
+
[:staged, :modified, :deleted].each do |cat|
|
12
|
+
files.send(cat).each do |k,v|
|
13
|
+
v.each do |vv|
|
14
|
+
_prmt.puts _fmt(vv, :magenta)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
begin
|
20
|
+
msg = ""
|
21
|
+
loop do
|
22
|
+
msg = _prmt.ask(_fmt("\n Commit message (Ctrl-c to go back) : "), required: true)
|
23
|
+
confirm = _prmt.yes?(_fmt(" Commit message : #{msg}\n Proceed? No to provide a new commit message "))
|
24
|
+
if confirm
|
25
|
+
break
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
st, res = ws.commit_all(msg)
|
30
|
+
raise OperationError, "Commit all failed with error : #{res}" if not st
|
31
|
+
rescue TTY::Reader::InputInterrupt
|
32
|
+
_prmt.puts _fmt "Commit all aborted"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
require_relative '../common'
|
3
|
+
module Gity
|
4
|
+
module Operation
|
5
|
+
module Delete
|
6
|
+
include Common
|
7
|
+
|
8
|
+
def delete(ws, files)
|
9
|
+
_cls
|
10
|
+
print_header
|
11
|
+
_prmt.puts
|
12
|
+
print_workspace_items(ws, files, skip_other_files: true)
|
13
|
+
_prmt.puts
|
14
|
+
efiles = files.modified[:files] + files.new[:files] + files.staged[:files]
|
15
|
+
|
16
|
+
begin
|
17
|
+
sels = _prmt.multi_select(_fmt("Please select all applicable files to be deleted : "), filter: true, per_page: 10) do |m|
|
18
|
+
efiles.sort.each do |f|
|
19
|
+
m.choice f,f
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
sels.each do |s|
|
24
|
+
|
25
|
+
if s.is_a?(GitCli::Delta::NewFile)
|
26
|
+
skip = _prmt.no? _fmt "Proceed to delete regular file '#{s}'? "
|
27
|
+
if not skip
|
28
|
+
FileUtils.rm(s.path)
|
29
|
+
end
|
30
|
+
|
31
|
+
elsif s.is_a?(GitCli::Delta::ModifiedFile)
|
32
|
+
# not staged
|
33
|
+
skip = _prmt.no? _fmt "Proceed to delete modified file '#{s}'? "
|
34
|
+
if not skip
|
35
|
+
ws.remove_from_vcs(s.path)
|
36
|
+
end
|
37
|
+
elsif s.is_a?(GitCli::Delta::StagedFile)
|
38
|
+
skip = _prmt.no? "Proceed to delete staged file '#{s}'? "
|
39
|
+
if not skip
|
40
|
+
ws.remove_from_staging(s.path)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
rescue TTY::Reader::InputInterrupt
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
require_relative '../common'
|
3
|
+
module Gity
|
4
|
+
module Operation
|
5
|
+
module Diff
|
6
|
+
include Common
|
7
|
+
|
8
|
+
def diff(ws, files)
|
9
|
+
_cls
|
10
|
+
print_header
|
11
|
+
_prmt.puts
|
12
|
+
print_workspace_items(ws, files, skip_other_files: true)
|
13
|
+
_prmt.puts
|
14
|
+
efiles = files.modified[:files] + files.staged[:files] + files.deleted[:files]
|
15
|
+
|
16
|
+
begin
|
17
|
+
sel = _prmt.select(_fmt("Please select file to diff : "), filter: true, per_page: 10) do |m|
|
18
|
+
efiles.sort.each do |f|
|
19
|
+
m.choice f,f.path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
st, res = ws.diff_file(sel)
|
24
|
+
raise OperationError, "Diff file '#{sel}' failed with error : #{res}" if not st
|
25
|
+
|
26
|
+
_prmt.puts _fmt "Diff file result for '#{sel}'"
|
27
|
+
_prmt.puts _fmt res, :bright_blue
|
28
|
+
_prmt.puts
|
29
|
+
_prmt.puts _fmt "[Enter to close]", :inverse
|
30
|
+
STDIN.gets
|
31
|
+
|
32
|
+
rescue TTY::Reader::InputInterrupt
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
require_relative '../common'
|
3
|
+
module Gity
|
4
|
+
module Operation
|
5
|
+
module Ignore
|
6
|
+
include Common
|
7
|
+
|
8
|
+
def ignore(ws, files)
|
9
|
+
_cls
|
10
|
+
print_header
|
11
|
+
_prmt.puts
|
12
|
+
print_workspace_items(ws, files, skip_other_files: true)
|
13
|
+
_prmt.puts
|
14
|
+
efiles = files.new[:files]
|
15
|
+
|
16
|
+
begin
|
17
|
+
sels = _prmt.multi_select(_fmt("Please select all files be ignored by git : "), filter: true, per_page: 10) do |m|
|
18
|
+
efiles.sort.each do |f|
|
19
|
+
m.choice f,f.path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
st, res = ws.ignore(*sels)
|
24
|
+
raise OperationError, "Ignore operation failed with error : #{res}" if not st
|
25
|
+
rescue TTY::Reader::InputInterrupt
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
require_relative '../common'
|
3
|
+
module Gity
|
4
|
+
module Operation
|
5
|
+
module RemoveStaged
|
6
|
+
include Common
|
7
|
+
|
8
|
+
def remove_staged(ws, files)
|
9
|
+
_cls
|
10
|
+
print_header
|
11
|
+
_prmt.puts
|
12
|
+
print_workspace_items(ws, files, skip_other_files: true)
|
13
|
+
_prmt.puts
|
14
|
+
efiles = files.staged[:files] + files.staged[:dirs]
|
15
|
+
|
16
|
+
sels = _prmt.multi_select(_fmt("Please select all files to be removed from staging : "), filter: true, per_page: 10) do |m|
|
17
|
+
efiles.sort.each do |f|
|
18
|
+
m.choice f,f.path
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
st, res = ws.remove_from_staging(*sels)
|
23
|
+
raise OperationError, "Remove from staging failed with error : #{res}" if not st
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
|
2
|
+
require_relative 'common'
|
3
|
+
|
4
|
+
require_relative 'operation/commit_all'
|
5
|
+
require_relative 'operation/commit'
|
6
|
+
require_relative 'operation/add'
|
7
|
+
require_relative 'operation/ignore'
|
8
|
+
require_relative 'operation/remove_staged'
|
9
|
+
require_relative 'operation/diff'
|
10
|
+
require_relative 'operation/delete'
|
11
|
+
|
12
|
+
module Gity
|
13
|
+
module Operation
|
14
|
+
include Common
|
15
|
+
include CommitAll
|
16
|
+
include Commit
|
17
|
+
include Add
|
18
|
+
include Ignore
|
19
|
+
include RemoveStaged
|
20
|
+
include Diff
|
21
|
+
include Delete
|
22
|
+
|
23
|
+
def prompt_operation(ws, files, opts = {})
|
24
|
+
|
25
|
+
opts = {} if opts.nil?
|
26
|
+
defOps = [:commit_all, :commit, :add, :ignore, :remove_staged, :diff, :delete]
|
27
|
+
|
28
|
+
selOpts = {}
|
29
|
+
defOps.each do |o|
|
30
|
+
case o
|
31
|
+
when :commit_all
|
32
|
+
selOpts["Commit all"] = o if files.has_staged? or files.has_modified? or files.has_deleted?
|
33
|
+
when :commit
|
34
|
+
selOpts["Commit staged"] = o if files.has_staged?
|
35
|
+
when :add
|
36
|
+
selOpts["Add"] = o if files.has_new?
|
37
|
+
when :ignore
|
38
|
+
selOpts["Ignore"] = o if files.has_new?
|
39
|
+
when :remove_staged
|
40
|
+
selOpts["Remove Staged"] = o if files.has_staged?
|
41
|
+
when :diff
|
42
|
+
selOpts["Diff"] = o if files.has_modified?
|
43
|
+
when :delete
|
44
|
+
selOpts["Delete"] = o if files.has_staged? or files.has_modified? or files.has_deleted?
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
selOpts["Quit"] = :quit
|
49
|
+
|
50
|
+
begin
|
51
|
+
sel = _prmt.select(_fmt("Please select one of the operations : ", :magenta), filter: true) do |m|
|
52
|
+
selOpts.each do |k,v|
|
53
|
+
m.choice k, v
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
case sel
|
58
|
+
when :commit_all
|
59
|
+
_cls
|
60
|
+
_prmt.puts
|
61
|
+
commit_all(ws, files)
|
62
|
+
|
63
|
+
when :commit
|
64
|
+
_cls
|
65
|
+
_prmt.puts
|
66
|
+
commit(ws, files)
|
67
|
+
|
68
|
+
when :add
|
69
|
+
_cls
|
70
|
+
_prmt.puts
|
71
|
+
add(ws, files)
|
72
|
+
|
73
|
+
when :ignore
|
74
|
+
_cls
|
75
|
+
_prmt.puts
|
76
|
+
ignore(ws, files)
|
77
|
+
|
78
|
+
when :remove_staged
|
79
|
+
_cls
|
80
|
+
_prmt.puts
|
81
|
+
remove_staged(ws, files)
|
82
|
+
|
83
|
+
when :diff
|
84
|
+
_cls
|
85
|
+
_prmt.puts
|
86
|
+
diff(ws, files)
|
87
|
+
|
88
|
+
when :delete
|
89
|
+
_cls
|
90
|
+
_prmt.puts
|
91
|
+
delete(ws, files)
|
92
|
+
|
93
|
+
when :quit
|
94
|
+
exit(0)
|
95
|
+
end
|
96
|
+
|
97
|
+
rescue TTY::Reader::InputInterrupt
|
98
|
+
_prmt.puts
|
99
|
+
_prmt.puts
|
100
|
+
_prmt.puts _fmt "Operation aborted", :bright_yellow
|
101
|
+
_prmt.puts
|
102
|
+
exit(0)
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
|
2
|
+
require_relative 'common'
|
3
|
+
require_relative 'status'
|
4
|
+
|
5
|
+
require_relative 'git_log'
|
6
|
+
|
7
|
+
module Gity
|
8
|
+
module Overview
|
9
|
+
include Common
|
10
|
+
include Status
|
11
|
+
|
12
|
+
def print_overview(ws, opts = {}, &block)
|
13
|
+
|
14
|
+
res = status(ws)
|
15
|
+
print_workspace_items(ws, res, opts)
|
16
|
+
|
17
|
+
if block and not res.clean?
|
18
|
+
block.call(ws, res, opts)
|
19
|
+
end
|
20
|
+
|
21
|
+
res
|
22
|
+
end
|
23
|
+
|
24
|
+
def print_workspace_items(ws, itm, opts = {})
|
25
|
+
|
26
|
+
opts = {} if opts.nil?
|
27
|
+
title = opts[:title] || "Workspace Status : "
|
28
|
+
_prmt.puts _fmt title
|
29
|
+
branch = ws.current_branch
|
30
|
+
_prmt.puts _fmt "Branch : #{branch}" if not_empty?(branch)
|
31
|
+
|
32
|
+
mfiles = itm
|
33
|
+
|
34
|
+
_prmt.puts _fmt "Staged Files : ", :bold, :underline
|
35
|
+
files = mfiles.staged[:dirs] + mfiles.staged[:files]
|
36
|
+
if files.length > 0
|
37
|
+
files.sort.each do |v|
|
38
|
+
_prmt.puts _fmt("* #{v}", :on_yellow)
|
39
|
+
end
|
40
|
+
else
|
41
|
+
_prmt.puts _fmt "** No staged file found", :yellow
|
42
|
+
end
|
43
|
+
|
44
|
+
res = []
|
45
|
+
skipOtherFile = opts[:skip_other_files] || false
|
46
|
+
if not skipOtherFile
|
47
|
+
|
48
|
+
_prmt.puts ""
|
49
|
+
_prmt.puts _fmt "Other Files : ", :bold, :underline
|
50
|
+
res = mfiles.modified[:dirs].sort + mfiles.modified[:files].sort + mfiles.deleted[:dirs].sort + mfiles.deleted[:files].sort + mfiles.new[:dirs].sort + mfiles.new[:files].sort
|
51
|
+
|
52
|
+
if res.length > 0
|
53
|
+
res.each do |vv|
|
54
|
+
case vv
|
55
|
+
when GitCli::Delta::NewFile
|
56
|
+
_prmt.puts _fmt(vv)
|
57
|
+
when GitCli::Delta::ModifiedFile
|
58
|
+
_prmt.puts _fmt(vv, :bright_yellow)
|
59
|
+
when GitCli::Delta::DeletedFile
|
60
|
+
_prmt.puts _fmt(vv, :strikethrough)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
else
|
65
|
+
_prmt.puts _fmt("** No other file found", :yellow)
|
66
|
+
end
|
67
|
+
|
68
|
+
end # not skipOtherFile
|
69
|
+
|
70
|
+
if mfiles.clean?
|
71
|
+
_prmt.puts
|
72
|
+
_prmt.puts _fmt("Workspace is clean", :inverse)
|
73
|
+
_prmt.puts
|
74
|
+
st, logs = ws.logs(limit: 3)
|
75
|
+
en = GitLogParser.new(logs)
|
76
|
+
_prmt.puts _fmt "Last 3 last commit : "
|
77
|
+
en.entries.each do |e|
|
78
|
+
_prmt.puts _fmt "#{e.commit_by}\n #{e.timestamp}\n #{e.commit_notes}"
|
79
|
+
_prmt.puts _fmt "**** ****"
|
80
|
+
end
|
81
|
+
_prmt.puts
|
82
|
+
true
|
83
|
+
else
|
84
|
+
false
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
end # print_workspace_items
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
data/lib/gity/status.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
require_relative 'status_list'
|
3
|
+
|
4
|
+
module Gity
|
5
|
+
module Status
|
6
|
+
|
7
|
+
def status(ws)
|
8
|
+
|
9
|
+
stgDir, stgFiles = ws.staged_files
|
10
|
+
modDir, modFiles = ws.modified_files
|
11
|
+
newDir, newFiles = ws.new_files
|
12
|
+
delDir, delFiles = ws.deleted_files
|
13
|
+
|
14
|
+
modFiles.delete_if { |f| stgFiles.include?(f) }
|
15
|
+
modDir.delete_if { |f| stgDir.include?(f) }
|
16
|
+
|
17
|
+
newFiles.delete_if { |f| stgFiles.include?(f) }
|
18
|
+
newDir.delete_if { |f| stgDir.include?(f) }
|
19
|
+
|
20
|
+
delFiles.delete_if { |f| stgFiles.include?(f) }
|
21
|
+
delDir.delete_if { |f| stgDir.include?(f) }
|
22
|
+
|
23
|
+
res = {
|
24
|
+
modified: { files: modFiles, dirs: modDir },
|
25
|
+
new: { files: newFiles, dirs: newDir },
|
26
|
+
deleted: { files: delFiles, dirs: delDir },
|
27
|
+
staged: { files: stgFiles, dirs: stgDir }
|
28
|
+
}
|
29
|
+
|
30
|
+
StatusList.new(res)
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Gity
|
4
|
+
class StatusList
|
5
|
+
include TR::CondUtils
|
6
|
+
|
7
|
+
def initialize(list)
|
8
|
+
@list = list || {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def has_modified?
|
12
|
+
@list[:modified].nil? ? false : (not_empty?(@list[:modified][:files]) or not_empty?(@list[:modified][:dirs]))
|
13
|
+
end
|
14
|
+
|
15
|
+
def has_new?
|
16
|
+
@list[:new].nil? ? false : (not_empty?(@list[:new][:files]) or not_empty?(@list[:new][:dirs]))
|
17
|
+
end
|
18
|
+
|
19
|
+
def has_deleted?
|
20
|
+
@list[:deleted].nil? ? false : (not_empty?(@list[:deleted][:files]) or not_empty?(@list[:deleted][:dirs]))
|
21
|
+
end
|
22
|
+
|
23
|
+
def has_staged?
|
24
|
+
@list[:staged].nil? ? false : (not_empty?(@list[:staged][:files]) or not_empty?(@list[:staged][:dirs]))
|
25
|
+
end
|
26
|
+
|
27
|
+
def clean?
|
28
|
+
not has_modified? and not has_new? and not has_deleted? and not has_staged?
|
29
|
+
end
|
30
|
+
|
31
|
+
def method_missing(mtd, *args, &block)
|
32
|
+
if [:modified, :new, :deleted, :staged].include?(mtd)
|
33
|
+
@list[mtd.to_sym]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/lib/gity/version.rb
ADDED
data/lib/gity.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'toolrack'
|
4
|
+
require 'teLogger'
|
5
|
+
|
6
|
+
require 'tty/prompt'
|
7
|
+
require 'tty/command'
|
8
|
+
require 'pastel'
|
9
|
+
|
10
|
+
require_relative "gity/version"
|
11
|
+
require_relative 'gity/landing'
|
12
|
+
|
13
|
+
module Gity
|
14
|
+
include TR::CondUtils
|
15
|
+
|
16
|
+
class Error < StandardError; end
|
17
|
+
class OperationError < Error; end
|
18
|
+
# Your code goes here...
|
19
|
+
|
20
|
+
end
|
data/sig/gity.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gity
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: toolrack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.23'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.23'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: teLogger
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tty-prompt
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.23'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.23'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: tty-command
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.10'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pastel
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.8'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.8'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: git_cli
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.13'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.13'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: release-gem
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.3.3
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.3.3
|
111
|
+
description: ''
|
112
|
+
email:
|
113
|
+
- chris@antrapol.com
|
114
|
+
executables:
|
115
|
+
- gity
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".rspec"
|
120
|
+
- README.md
|
121
|
+
- Rakefile
|
122
|
+
- exe/gity
|
123
|
+
- lib/gity.rb
|
124
|
+
- lib/gity/common.rb
|
125
|
+
- lib/gity/git_log.rb
|
126
|
+
- lib/gity/landing.rb
|
127
|
+
- lib/gity/operation.rb
|
128
|
+
- lib/gity/operation/add.rb
|
129
|
+
- lib/gity/operation/commit.rb
|
130
|
+
- lib/gity/operation/commit_all.rb
|
131
|
+
- lib/gity/operation/delete.rb
|
132
|
+
- lib/gity/operation/diff.rb
|
133
|
+
- lib/gity/operation/ignore.rb
|
134
|
+
- lib/gity/operation/remove_staged.rb
|
135
|
+
- lib/gity/overview.rb
|
136
|
+
- lib/gity/status.rb
|
137
|
+
- lib/gity/status_list.rb
|
138
|
+
- lib/gity/version.rb
|
139
|
+
- sig/gity.rbs
|
140
|
+
homepage: ''
|
141
|
+
licenses: []
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: 2.6.0
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubygems_version: 3.4.6
|
159
|
+
signing_key:
|
160
|
+
specification_version: 4
|
161
|
+
summary: ''
|
162
|
+
test_files: []
|