git_toolbox 0.6.0 → 0.7.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 15a670824481b1eacf235aeb9fefced3bc5f6febb2674ff11d272013aad665d5
4
- data.tar.gz: 54be78886d9fa0ec1a2650cbcfbcc6028c7cc0b2f54f85398aa8649d2061d22b
3
+ metadata.gz: 0bb05b8ed627b884189e6b9c17eddc7284f20f4e2bce598dd24f154b6f717c99
4
+ data.tar.gz: bf1d78a1e32c113cb00cb0b0c9150f09359d4743927505d0ea34dd0d9fa48f20
5
5
  SHA512:
6
- metadata.gz: 3ac823eedff5a76c6808ff2615a2a1f1fce8ed1508a868e0f73fdb66616ac23dc2344412d842c775700850a2290d075a495a304beea99ceccc0e74236102d52b
7
- data.tar.gz: bd690477114dbf9ccf127ebb89531ca8204ccca483a2fe2fa87a97ff841cac9ae99dbd78b6793f46b68a3bd384de5b51e7baec1b3ed7a54d14c7f67fffc4fc90
6
+ metadata.gz: 949501f9b215d45757904e2201675539a9601a65e88e5418cb97ced39f3fa343aba3a53d34a45caefe490e46095d43318465634bc70d5b55bdda704676fd5333
7
+ data.tar.gz: 79f86d45ac90f0be948fd36948314aa0e5b27d1b596bdd8d36b661983660986ca1a91199b9698a5d5bce0947d70e0ffd8665f8506ee19ebaad7c5b99acdbea21
@@ -77,10 +77,10 @@ class Commit < Command
77
77
 
78
78
  def initialize
79
79
  super(@@usage, @@description) do
80
- Common.error 'commit need to be run inside a git repository' unless Git.in_repo?
81
80
  @options = Common.with_subcommand_exception_handling @@option_parser do
82
81
  @@option_parser.parse
83
82
  end
83
+ Common.error 'commit need to be run inside a git repository' unless Git.in_repo?
84
84
 
85
85
  message = full_commit_message
86
86
  puts message
@@ -112,10 +112,10 @@ class Describe < Command
112
112
 
113
113
  def initialize
114
114
  super(@@usage, @@description) do
115
- Common.error 'describe need to be run inside a git repository' unless Git.in_repo?
116
115
  @options = Common.with_subcommand_exception_handling @@option_parser do
117
116
  @@option_parser.parse
118
117
  end
118
+ Common.error 'describe need to be run inside a git repository' unless Git.in_repo?
119
119
  set_options
120
120
 
121
121
  if ARGV.length.positive?
@@ -0,0 +1,118 @@
1
+ # Get is a toolbox based on git which simplifies the adoption of conventions and some git commands.
2
+ # Copyright (C) 2023 Alex Speranza
3
+
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU Lesser General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program and the additional permissions granted by
16
+ # the Lesser GPL. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ # frozen_string_literal: true
19
+
20
+ require 'English'
21
+ require 'get/commons/common'
22
+ require 'get/commons/git'
23
+ require 'get/subcommand/command'
24
+
25
+ # Class length is disabled as most of its length is given by formatting.
26
+ # rubocop:disable Metrics/ClassLength
27
+ # Subcommand, it allow to create a new repository and add an initial, empty commit to it.
28
+ class Tree < Command
29
+ def self.command
30
+ @@command ||= new
31
+ @@command
32
+ end
33
+
34
+ private_class_method :new
35
+
36
+ private
37
+
38
+ @@command = nil
39
+
40
+ @@usage = 'tree -h|(<subcommand> [<subcommand-options])'
41
+ @@description = 'Print the tree of commits.'
42
+ @@subcommands = {}
43
+ # This block is Optimist configuration. It is as long as the number of options of the command.
44
+ # rubocop:disable Metrics/BlockLength
45
+ @@option_parser = Optimist::Parser.new do
46
+ subcommand_max_length = @@subcommands.keys.map { |k| k.to_s.length }.max
47
+ subcommand_section = <<~SUBCOMMANDS unless @@subcommands.empty?
48
+ Subcommands:
49
+ #{@@subcommands.keys.map { |k| " #{k.to_s.ljust(subcommand_max_length)} => #{@@subcommands[k].description}" }.join("\n")}
50
+ SUBCOMMANDS
51
+ usage @@usage
52
+ synopsis @@description + (subcommand_section.nil? ? '' : "\n") + subcommand_section.to_s
53
+ educate_on_error
54
+ stop_on @@subcommands.keys.map(&:to_s)
55
+ end
56
+ # rubocop:enable Metrics/BlockLength
57
+
58
+ def initialize
59
+ super(@@usage, @@description) do
60
+ @options = Common.with_subcommand_exception_handling @@option_parser do
61
+ @@option_parser.parse
62
+ end
63
+ Common.error 'tree need to be run inside a git repository' unless Git.in_repo?
64
+
65
+ view_tree
66
+ end
67
+ end
68
+
69
+ def view_tree
70
+ page_log(transform_log(log))
71
+ end
72
+
73
+ TREE_FORMAT = '%C(bold blue)%h%C(reset)§%C(dim normal)(%cr)%C(reset)§%C(auto)%d%C(reset)§§%n' \
74
+ '§§§ %C(normal)%an%C(reset)%C(dim normal): %s%C(reset)'
75
+
76
+ def log
77
+ `git log --all --graph --decorate=short --date-order --color --pretty=format:"#{TREE_FORMAT}"`
78
+ end
79
+
80
+ TIME_REGEX = /(\([a-z0-9 ,]+\))/
81
+ TIME_MINIMUM_PADDING = 2
82
+
83
+ def transform_log(text)
84
+ split_lines = text.split("\n").map { |element| element.split('§') }
85
+ # The first line is always a commit line, so it always have a time reference
86
+ first_line_time = split_lines.first[1]
87
+ # calc color escape codes length
88
+ time_color_length = first_line_time.length - first_line_time.match(TIME_REGEX)[1].length
89
+
90
+ # calc max length of time references
91
+ time_padding = 0
92
+ split_lines.each { |element| time_padding = [time_padding, element[1].length - time_color_length].max }
93
+
94
+ # format strings
95
+ split_lines
96
+ .map do |element|
97
+ # Only lines with the date reference have the color escape codes,
98
+ # the other lines do not need the additional padding
99
+ left_padding = TIME_MINIMUM_PADDING + time_padding +
100
+ (element[1].match?(TIME_REGEX) ? time_color_length : 0)
101
+ format(
102
+ '%<date>s %<tree_mark>s %<pointers>s %<commit_text>s',
103
+ {
104
+ date: element[1].rjust(left_padding),
105
+ tree_mark: element[0],
106
+ pointers: element[2],
107
+ commit_text: element[3]
108
+ }
109
+ )
110
+ end
111
+ .join("\n")
112
+ end
113
+
114
+ def page_log(text)
115
+ system("less -RfS <(echo -e '#{text}')")
116
+ end
117
+ end
118
+ # rubocop:enable Metrics/ClassLength
data/lib/get/version.rb CHANGED
@@ -18,5 +18,5 @@
18
18
  # frozen_string_literal: true
19
19
 
20
20
  module Get
21
- VERSION = '0.6.0'
21
+ VERSION = '0.7.0'
22
22
  end
data/lib/get.rb CHANGED
@@ -25,6 +25,7 @@ require 'get/subcommand/init/init'
25
25
  require 'get/subcommand/license/license'
26
26
  require 'get/subcommand/complete/complete'
27
27
  require 'get/subcommand/changelog/changelog'
28
+ require 'get/subcommand/tree/tree'
28
29
  require 'get/version'
29
30
  require 'get/commons/common'
30
31
 
@@ -39,6 +40,7 @@ module Get
39
40
  license: License.command,
40
41
  complete: Complete.command,
41
42
  changelog: Changelog.command,
43
+ tree: Tree.command,
42
44
  }
43
45
  @@option_parser = Optimist::Parser.new do
44
46
  subcommand_max_length = @@subcommands.keys.map { |k| k.to_s.length }.max
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_toolbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Speranza
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-20 00:00:00.000000000 Z
11
+ date: 2023-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: optimist
@@ -76,6 +76,7 @@ files:
76
76
  - lib/get/subcommand/license/offline_licenses/GNU General Public License v3.0/LICENSE
77
77
  - lib/get/subcommand/license/offline_licenses/MIT License/LICENSE
78
78
  - lib/get/subcommand/license/offline_licenses/Mozilla Public License 2.0/LICENSE
79
+ - lib/get/subcommand/tree/tree.rb
79
80
  - lib/get/version.rb
80
81
  homepage: https://github.com/asperan/get
81
82
  licenses: