gitflash 0.1.2.alpha → 0.3.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: 3e2ab919eb4408a42c7bbd519e063a8f749e5c76802f078a410934bd6bf0faec
4
- data.tar.gz: e821bb291632e98b292a0b6df49ede8836566904342026e9aa6693c8a0367ca6
3
+ metadata.gz: 37431db670588b8025d973c045532de047b33a667fc1c86152e1180d2d0a01a6
4
+ data.tar.gz: 307fe7991415b2bedce69a08f7b0e09e591be3cbcb6be692c1d46c87c79019b1
5
5
  SHA512:
6
- metadata.gz: 5f855639bd9cee9d4761198e37e86a5b76e3ce6641a35be10602aaeb2698524aedf6c0fb4df761f3fcb3e306629ced9816586c8f5c0adea7e9acdcacca3636f5
7
- data.tar.gz: 8a90c367cea30c5bbc242bb73eced1907e773a6e6cbad0d3673f4cf07a27bbcc1c972256d60eafde834cdc1134de2fcc3142ee2c4c8d7aad1faaa7e2c1dfa48d
6
+ metadata.gz: dcc8b7a6a6c740c46c78d29766bc78b99fa9949217482a71e47070a077a51759903c74a82adbcbe24590e27dbc04f5db5501175efda1a2a624f7b84211e72579
7
+ data.tar.gz: 541587b9f335e4ccd47f4cb0e7ec9806d1e4a2abb06d8811e81e8c483c2eba2126c26f7cbaebe5074d07d968d4e156b6ea751ccfbff08b6128a6239af0cd4272
data/README.md CHANGED
@@ -24,7 +24,7 @@ Or install it yourself as:
24
24
 
25
25
  ## Requirements
26
26
 
27
- This gem requires Ruby 2.7+.
27
+ This gem requires Ruby 3.3.2+.
28
28
  ## Usage
29
29
 
30
30
  Run `gitflash` to get a list with the available commands and their description.
@@ -37,7 +37,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
37
37
 
38
38
  ## Contributing
39
39
 
40
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/git_flash. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/git_flash/blob/master/CODE_OF_CONDUCT.md).
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Kleanthismits/git_flash. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/Kleanthismits/git_flash/blob/main/CODE_OF_CONDUCT.md).
41
41
 
42
42
  ## License
43
43
 
@@ -45,4 +45,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
45
45
 
46
46
  ## Code of Conduct
47
47
 
48
- Everyone interacting in the GitFlash project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/git_flash/blob/master/CODE_OF_CONDUCT.md).
48
+ Everyone interacting in the GitFlash project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Kleanthismits/git_flash/blob/main/CODE_OF_CONDUCT.md).
@@ -0,0 +1,33 @@
1
+ checkout:
2
+ short: 'Checkout the selected branch'
3
+ long: |
4
+ Presents a list with all the available local branches.
5
+
6
+ You can use the arrow keys to navigate through the branches.
7
+ Type for quick searching a specific branch.
8
+ Press `enter` to choose and checkout the branch.
9
+ Press `ctrl+c` to cancel the operation.
10
+
11
+ delete:
12
+ short: 'Delete the selected branches'
13
+ long: |
14
+ Presents a list with all the available local branches (without current or main/master).
15
+
16
+ You can use the arrow keys to navigate through the branches.
17
+ Type for quick searching a specific branch.
18
+ Press `space` to choose multiple branches.
19
+ Press `enter` to confirm selection and delete branches.
20
+ Press `ctrl+c` to cancel the operation.
21
+
22
+ reset:
23
+ short: 'Reset your code to the selected commit'
24
+ long: |
25
+ Accepts an optional parameter (hard) if you want to hard reset.
26
+
27
+ Presents a list with all the available commits.
28
+
29
+ You can use the arrow keys to navigate through the commits.
30
+ Type for quick searching a specific commit.
31
+ Press `space` to choose multiple commits.
32
+ Press `enter` to confirm selection and reset to that commit.
33
+ Press `ctrl+c` to cancel the operation.
data/lib/gitflash/cli.rb CHANGED
@@ -4,43 +4,34 @@ require 'thor'
4
4
 
5
5
  module Gitflash
6
6
  class Cli < Thor
7
+ extend Configuration::Descriptions
8
+
7
9
  def self.exit_on_failure?
8
10
  true
9
11
  end
10
12
 
11
- desc 'checkout', 'Checkout the selected branch'
12
- long_desc <<-TEXT
13
-
14
- Presents a list with all the available local branches.
15
-
16
- You can use the arrow keys to navigate through the branches.
17
- Type for quick searching a specific branch.
18
- Press `enter` to choose and checkout the branch.
19
- Press `ctrl+c` to cancel the operation.
20
- TEXT
13
+ desc 'checkout', descriptions.checkout.short
14
+ long_desc descriptions.checkout.long
21
15
 
22
16
  def checkout
23
17
  branches? ? checkout_branch : prompt.ok('You only have one branch!')
24
18
  end
25
19
 
26
- desc 'delete', 'Delete the selected branches'
27
- long_desc <<-TEXT
28
-
29
- Presents a list with all the available local branches(without current or main/master).
30
-
31
- You can use the arrow keys to navigate through the branches.
32
- Type for quick searching a specific branch.
33
- Press `space` to choose multiple branches.
34
- Press `enter` to confirm selection and delete branches.
35
- Press `ctrl+c` to cancel the operation.
36
-
37
- WARNING: The branches will be deleted even if they have unmerged changes!!
38
- TEXT
20
+ desc 'delete', descriptions.delete.short
21
+ long_desc descriptions.delete.long
39
22
 
40
23
  def delete
41
24
  branches? ? delete_branch : prompt.ok('You only have one branch!')
42
25
  end
43
26
 
27
+ desc 'reset', descriptions.reset.short
28
+ long_desc descriptions.reset.long
29
+
30
+ option :hard, type: :boolean, default: false, desc: 'Perform a hard reset'
31
+ def reset
32
+ commits? ? reset_to_commit : prompt.ok('You only have one branch!')
33
+ end
34
+
44
35
  private
45
36
 
46
37
  def checkout_branch
@@ -59,24 +50,45 @@ module Gitflash
59
50
  branches(options: { master: false, current: false })
60
51
  )
61
52
 
62
- prompt.warn(<<~TEXT
53
+ warning_message = <<~TEXT
63
54
  You are about to permanently delete the following branches even if they have unmerged changes:
64
55
 
65
56
  #{selection.map { |br| "* #{br}" }.join("\n")}
66
57
  TEXT
67
- )
68
- answer = prompt.yes?('Do you want to proceed?')
69
- puts answer ? git.delete(selection) : 'Exited'
58
+
59
+ prompt_proceed_warning(warning_message) { git.delete(selection) }
60
+ end
61
+
62
+ def reset_to_commit
63
+ selection = prompt.select('Select a commit to reset to', branch_commits)
64
+ reset_options = { commit_hash: selection, hard: options[:hard] }
65
+
66
+ if options[:hard]
67
+ warning_message = 'You are about to reset your branch and lose all your current changes'
68
+ prompt.proceed_with_warning(warning_message) { git.reset(**reset_options) }
69
+ else
70
+ git.reset(**reset_options)
71
+ end
70
72
  end
71
73
 
72
74
  def branches?
73
75
  all_branches && all_branches.size > 1
74
76
  end
75
77
 
78
+ def commits?
79
+ branch_commits && branch_commits.size > 1
80
+ end
81
+
76
82
  def prompt
77
83
  @prompt ||= Prompt.create
78
84
  end
79
85
 
86
+ def prompt_proceed_warning(message)
87
+ prompt.warn(message)
88
+ answer = prompt.yes?('Do you want to proceed?')
89
+ puts answer ? yield : 'Exited'
90
+ end
91
+
80
92
  def checkout_options
81
93
  {}.tap do |opt|
82
94
  opt[:default] = current unless current.nil?
@@ -95,6 +107,10 @@ module Gitflash
95
107
  @current ||= git.current_branch
96
108
  end
97
109
 
110
+ def branch_commits
111
+ @branch_commits = git.branch_commits
112
+ end
113
+
98
114
  def git
99
115
  Gitflash::Git::Wrapper
100
116
  end
@@ -0,0 +1,29 @@
1
+ require 'yaml'
2
+
3
+ module Gitflash
4
+ module Configuration
5
+ module Descriptions
6
+ def descriptions
7
+ @descriptions ||= load_descriptions
8
+ end
9
+
10
+ private
11
+
12
+ def load_descriptions
13
+ file = File.expand_path('../../command_descriptions.yml', __dir__)
14
+ transform_to_struct(YAML.load_file(file))
15
+ end
16
+
17
+ def transform_to_struct(data)
18
+ return data unless data.is_a? Hash
19
+
20
+ keys = data.keys.map(&:to_sym)
21
+ Struct.new(*keys).new(*data.values).tap do |st|
22
+ keys.each do |method|
23
+ st.send("#{method}=".to_sym, transform_to_struct(st.send(method)))
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Gitflash
3
4
  module Git
4
5
  class Wrapper
@@ -23,8 +24,29 @@ module Gitflash
23
24
  bash.system_exec('git', 'checkout', branch)
24
25
  end
25
26
 
26
- def delete(selection)
27
- bash.system_exec('git', 'branch', '-D', *selection)
27
+ def delete(branch)
28
+ bash.system_exec('git', 'branch', '-D', *branch)
29
+ end
30
+
31
+ def reset(commit_hash:, hard:)
32
+ params = [].tap do |ar|
33
+ ar << '--hard' if hard
34
+ end
35
+
36
+ bash.system_exec('git', 'reset', *params, commit_hash)
37
+ end
38
+
39
+ def branch_commits
40
+ commits_string = bash.exec('git log --oneline')
41
+ {}.tap do |hsh|
42
+ commits_string.each_line do |line|
43
+ parts = line.strip.split
44
+ commit_code = parts[0]
45
+ commit_name = parts[1..].join(' ')
46
+ label = "#{commit_code} - #{commit_name}"
47
+ hsh[label] = commit_code
48
+ end
49
+ end
28
50
  end
29
51
 
30
52
  private
@@ -23,9 +23,15 @@ module Gitflash
23
23
  super(message, collection, default_select_options(options))
24
24
  end
25
25
 
26
- private
26
+ def proceed_with_warning(message, &block)
27
+ raise ArgumentError, 'A block is required for this method' unless block_given?
28
+
29
+ warn(message)
30
+ answer = yes?('Do you want to proceed?')
31
+ answer ? block.call : 'Exited'
32
+ end
27
33
 
28
- attr_reader :prompt
34
+ private
29
35
 
30
36
  def default_create_options(options)
31
37
  {
@@ -37,7 +43,6 @@ module Gitflash
37
43
  def default_select_options(options)
38
44
  {
39
45
  cycle: true,
40
- per_page: 50,
41
46
  filter: true,
42
47
  symbols: { marker: '>' }
43
48
  }.merge(options)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gitflash
4
- VERSION = '0.1.2.alpha'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/gitflash.rb CHANGED
@@ -5,7 +5,6 @@ original_verbose = $VERBOSE
5
5
  $VERBOSE = nil
6
6
 
7
7
  require 'zeitwerk'
8
- require 'pry'
9
8
 
10
9
  loader = Zeitwerk::Loader.for_gem
11
10
  loader.setup
metadata CHANGED
@@ -1,15 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitflash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2.alpha
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kleanthis Mitsioulis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-04 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2025-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: tty-prompt
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.23'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.23'
41
+ - !ruby/object:Gem::Dependency
42
+ name: zeitwerk
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '13.0'
13
69
  description: This gem allows you to perform a number of git commands using interactive
14
70
  cli prompts
15
71
  email:
@@ -25,8 +81,10 @@ files:
25
81
  - bin/console
26
82
  - bin/gitflash
27
83
  - bin/setup
84
+ - command_descriptions.yml
28
85
  - lib/gitflash.rb
29
86
  - lib/gitflash/cli.rb
87
+ - lib/gitflash/configuration.rb
30
88
  - lib/gitflash/git/bash_command.rb
31
89
  - lib/gitflash/git/wrapper.rb
32
90
  - lib/gitflash/prompt.rb
@@ -47,14 +105,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
47
105
  requirements:
48
106
  - - ">="
49
107
  - !ruby/object:Gem::Version
50
- version: 2.7.0
108
+ version: '3.0'
51
109
  required_rubygems_version: !ruby/object:Gem::Requirement
52
110
  requirements:
53
- - - ">"
111
+ - - ">="
54
112
  - !ruby/object:Gem::Version
55
- version: 1.3.1
113
+ version: '0'
56
114
  requirements: []
57
- rubygems_version: 3.2.15
115
+ rubygems_version: 3.5.9
58
116
  signing_key:
59
117
  specification_version: 4
60
118
  summary: Simplified usage of some git cli commands