git-switcher 0.0.2 → 1.0.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 +7 -0
- data/.gitignore +8 -19
- data/.pryrc +8 -0
- data/.rubocop.yml +41 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -4
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +0 -7
- data/Gemfile.lock +49 -0
- data/LICENSE.txt +17 -18
- data/README.md +7 -5
- data/Rakefile +21 -20
- data/bin/console +9 -0
- data/bin/setup +15 -0
- data/exe/git-switcher +55 -0
- data/git-switcher.gemspec +30 -48
- data/lib/ext/rugged.rb +15 -0
- data/lib/git/switcher/menu.rb +102 -0
- data/lib/git/switcher/version.rb +10 -0
- data/lib/git/switcher.rb +15 -0
- metadata +47 -277
- data/Guardfile +0 -17
- data/bin/git-switcher +0 -63
- data/features/help_and_version.feature +0 -20
- data/features/step_definitions/git-switcher_steps.rb +0 -21
- data/features/support/env.rb +0 -7
- data/lib/git-switcher/banner.rb +0 -13
- data/lib/git-switcher/copyright.rb +0 -6
- data/lib/git-switcher/menu.rb +0 -99
- data/lib/git-switcher/repo.rb +0 -93
- data/lib/git-switcher/version.rb +0 -5
- data/lib/git-switcher.rb +0 -17
- data/spec/lib/git-switcher/repo_spec.rb +0 -9
- data/spec/lib/git-switcher_spec.rb +0 -7
- data/spec/spec_helper.rb +0 -8
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 480d3361397c05f135cbdc8a6f2b2fad1b7b0938
|
4
|
+
data.tar.gz: 96a290408fd6ec990e78afb6e607732564a2227e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4da53fa155489463e202bbf1b282ee0460666d79853a3f15e21bb24868bdef95331dff2042f904346e6ffac2953e5a4c74cff6ea61aca8b5e93739846796a46d
|
7
|
+
data.tar.gz: bf26043f75fcbe49e946ba15b30879f042c182d4d751aa5bedcb7a366d871241ede8e9dea75e1ee8bbe4896c2d141dcfc439eda3d14e01f792bc4a5feafac9c8
|
data/.gitignore
CHANGED
@@ -1,19 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
coverage
|
10
|
-
doc/
|
11
|
-
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
|
-
spec/reports
|
15
|
-
test/tmp
|
16
|
-
test/version_tmp
|
17
|
-
tmp
|
18
|
-
*.sublime-*
|
19
|
-
vcr_debug.log
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
data/.pryrc
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- 'doc/*'
|
4
|
+
- 'tmp/*'
|
5
|
+
- 'pkg/*'
|
6
|
+
|
7
|
+
Layout/EmptyLinesAroundClassBody:
|
8
|
+
Enabled: false
|
9
|
+
Layout/EmptyLinesAroundModuleBody:
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Lint/HandleExceptions:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Metrics/AbcSize:
|
16
|
+
Enabled: false
|
17
|
+
Metrics/MethodLength:
|
18
|
+
Enabled: false
|
19
|
+
Metrics/ModuleLength:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/BlockDelimiters:
|
23
|
+
Enabled: false
|
24
|
+
Style/Documentation:
|
25
|
+
Enabled: false
|
26
|
+
Style/FrozenStringLiteralComment:
|
27
|
+
Enabled: false
|
28
|
+
Style/Lambda:
|
29
|
+
Enabled: false
|
30
|
+
Style/NestedTernaryOperator:
|
31
|
+
Enabled: false
|
32
|
+
Style/RedundantBegin:
|
33
|
+
Enabled: false
|
34
|
+
Style/SingleLineMethods:
|
35
|
+
Enabled: false
|
36
|
+
Style/TrailingCommaInArguments:
|
37
|
+
Enabled: false
|
38
|
+
Style/TrailingCommaInArrayLiteral:
|
39
|
+
Enabled: false
|
40
|
+
Style/TrailingCommaInHashLiteral:
|
41
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.8
|
data/.travis.yml
CHANGED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at peter.vandenberk@simplybusiness.co.uk. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
git-switcher (1.0.0)
|
5
|
+
rainbow (~> 3.0)
|
6
|
+
rugged (~> 0.27)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.0)
|
12
|
+
coderay (1.1.2)
|
13
|
+
jaro_winkler (1.5.2)
|
14
|
+
method_source (0.9.2)
|
15
|
+
parallel (1.13.0)
|
16
|
+
parser (2.6.0.0)
|
17
|
+
ast (~> 2.4.0)
|
18
|
+
powerpack (0.1.2)
|
19
|
+
pry (0.12.2)
|
20
|
+
coderay (~> 1.1.0)
|
21
|
+
method_source (~> 0.9.0)
|
22
|
+
psych (3.1.0)
|
23
|
+
rainbow (3.0.0)
|
24
|
+
rake (12.3.2)
|
25
|
+
rubocop (0.65.0)
|
26
|
+
jaro_winkler (~> 1.5.1)
|
27
|
+
parallel (~> 1.10)
|
28
|
+
parser (>= 2.5, != 2.5.1.1)
|
29
|
+
powerpack (~> 0.1)
|
30
|
+
psych (>= 3.1.0)
|
31
|
+
rainbow (>= 2.2.2, < 4.0)
|
32
|
+
ruby-progressbar (~> 1.7)
|
33
|
+
unicode-display_width (~> 1.4.0)
|
34
|
+
ruby-progressbar (1.10.0)
|
35
|
+
rugged (0.27.7)
|
36
|
+
unicode-display_width (1.4.1)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
bundler
|
43
|
+
git-switcher!
|
44
|
+
pry
|
45
|
+
rake
|
46
|
+
rubocop
|
47
|
+
|
48
|
+
BUNDLED WITH
|
49
|
+
2.0.1
|
data/LICENSE.txt
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
|
3
|
+
Copyright (c) 2012-2019 Peter Vandenberk (pvandenberk@mac.com)
|
4
4
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
the following conditions:
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
12
11
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
15
14
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
OF
|
22
|
-
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -86,10 +86,12 @@ For example, if you previously selected `11` to switch to the local `master` bra
|
|
86
86
|
|
87
87
|
To quickly switch to the `pvandenb` branch, just press `enter` *(without having to enter the corresponding shortcut key)*.
|
88
88
|
|
89
|
+
## Development
|
90
|
+
|
91
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
92
|
+
|
93
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
94
|
+
|
89
95
|
## Contributing
|
90
96
|
|
91
|
-
|
92
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
93
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
94
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
95
|
-
5. Create new Pull Request
|
97
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pvdb/git-switcher.
|
data/Rakefile
CHANGED
@@ -1,32 +1,33 @@
|
|
1
|
-
|
1
|
+
# rubocop:disable Style/SymbolArray
|
2
|
+
# rubocop:disable Style/HashSyntax
|
2
3
|
|
3
|
-
|
4
|
-
task :test => [:spec, :features]
|
4
|
+
require 'bundler/gem_tasks'
|
5
5
|
|
6
|
-
task :
|
7
|
-
|
6
|
+
task :validate_gemspec do
|
7
|
+
Bundler.load_gemspec('git-switcher.gemspec').validate
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
@gemspec.validate
|
10
|
+
task :version => :validate_gemspec do
|
11
|
+
puts Git::Switcher.version
|
13
12
|
end
|
14
13
|
|
15
|
-
require '
|
16
|
-
require 'rspec/core/rake_task'
|
14
|
+
require 'rubocop/rake_task'
|
17
15
|
|
18
|
-
|
19
|
-
t.rspec_opts = "--format d --color"
|
20
|
-
end
|
21
|
-
|
22
|
-
task :rspec => [:spec]
|
16
|
+
RuboCop::RakeTask.new(:rubocop)
|
23
17
|
|
24
|
-
require '
|
25
|
-
require 'cucumber/rake/task'
|
18
|
+
require 'rake/testtask'
|
26
19
|
|
27
|
-
|
28
|
-
t.
|
20
|
+
Rake::TestTask.new(:test) do |t|
|
21
|
+
t.libs << 'test'
|
22
|
+
t.libs << 'lib'
|
23
|
+
t.test_files = FileList['test/**/*_test.rb']
|
29
24
|
end
|
30
25
|
|
31
|
-
task :
|
26
|
+
task :default => [:version, :rubocop, :test]
|
27
|
+
|
28
|
+
task :documentation
|
29
|
+
|
30
|
+
Rake::Task['build'].enhance([:default, :documentation])
|
32
31
|
|
32
|
+
# rubocop:enable Style/HashSyntax
|
33
|
+
# rubocop:enable Style/SymbolArray
|
data/bin/console
ADDED
data/bin/setup
ADDED
data/exe/git-switcher
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'git/switcher'
|
6
|
+
|
7
|
+
def putm(message, color = :to_s)
|
8
|
+
return if message.strip.empty?
|
9
|
+
|
10
|
+
puts '', Rainbow(message).send(color)
|
11
|
+
print Rainbow('Press ⏎ to continue ... ').italic
|
12
|
+
$stdin.gets
|
13
|
+
end
|
14
|
+
|
15
|
+
repo = Rugged::Repository.new(Dir.pwd)
|
16
|
+
menu = Git::Switcher::Menu.for(repo)
|
17
|
+
|
18
|
+
# (optional) script to run after every checkout
|
19
|
+
switcher = File.join(repo.workdir, '.switcher')
|
20
|
+
|
21
|
+
loop do
|
22
|
+
print "\e[H\e[2J", menu, "\n", "\n" # clear the screen first (^L)
|
23
|
+
|
24
|
+
if (default_menu_item = menu.default_menu_item)
|
25
|
+
default_shortcut = format('⏎ [%2s]', default_menu_item.shortcut)
|
26
|
+
print Rainbow(default_shortcut).bold.steelblue, ' '
|
27
|
+
end
|
28
|
+
print "\t", Rainbow('your selection =>').steelblue, ' '
|
29
|
+
|
30
|
+
response = begin
|
31
|
+
$stdin.gets&.strip
|
32
|
+
rescue Interrupt
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
|
36
|
+
break unless response # ^C and ^D
|
37
|
+
|
38
|
+
menu_item = if response.empty?
|
39
|
+
default_menu_item
|
40
|
+
else
|
41
|
+
menu[response]
|
42
|
+
end
|
43
|
+
|
44
|
+
next unless menu_item
|
45
|
+
|
46
|
+
err_msg = `2>&1 git checkout --quiet #{menu_item.reference.name}`
|
47
|
+
if $CHILD_STATUS.success? && File.executable?(switcher)
|
48
|
+
cmd_msg = `2>&1 #{switcher}`
|
49
|
+
putm(cmd_msg, :green)
|
50
|
+
else
|
51
|
+
putm(err_msg, :red)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# That's all Folks!
|
data/git-switcher.gemspec
CHANGED
@@ -1,50 +1,32 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'git
|
5
|
-
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
# for testing
|
34
|
-
gem.add_development_dependency('rspec')
|
35
|
-
gem.add_development_dependency('cucumber')
|
36
|
-
gem.add_development_dependency('aruba')
|
37
|
-
|
38
|
-
# for monitoring
|
39
|
-
gem.add_development_dependency('guard')
|
40
|
-
gem.add_development_dependency('growl')
|
41
|
-
gem.add_development_dependency('rb-fsevent')
|
42
|
-
gem.add_development_dependency('rb-readline')
|
43
|
-
|
44
|
-
# for TDD/BDD/CI
|
45
|
-
gem.add_development_dependency('guard-rspec')
|
46
|
-
gem.add_development_dependency('guard-cucumber')
|
47
|
-
gem.add_development_dependency('rspec-pride')
|
48
|
-
gem.add_development_dependency('cucumber-pride')
|
49
|
-
|
3
|
+
require 'git/switcher/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = Git::Switcher::NAME
|
7
|
+
spec.version = Git::Switcher::VERSION
|
8
|
+
spec.authors = ['Peter Vandenberk']
|
9
|
+
spec.email = ['pvandenberk@mac.com']
|
10
|
+
|
11
|
+
spec.summary = 'The ultimate CLI git branch and tag switcher'
|
12
|
+
spec.description = 'Easily switch between git tags and branches'
|
13
|
+
spec.homepage = 'https://github.com/pvdb/git-switcher'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
17
|
+
`git ls-files -z`
|
18
|
+
.split("\x0")
|
19
|
+
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_dependency 'rainbow', '~> 3.0'
|
26
|
+
spec.add_dependency 'rugged', '~> 0.27'
|
27
|
+
|
28
|
+
spec.add_development_dependency 'bundler'
|
29
|
+
spec.add_development_dependency 'pry'
|
30
|
+
spec.add_development_dependency 'rake'
|
31
|
+
spec.add_development_dependency 'rubocop'
|
50
32
|
end
|
data/lib/ext/rugged.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
module Git
|
2
|
+
module Switcher
|
3
|
+
class Menu
|
4
|
+
|
5
|
+
Submenu = Struct.new(:label, :menu_items) do
|
6
|
+
def to_s
|
7
|
+
header = Rainbow(label).steelblue
|
8
|
+
"\n\t#{header}\n\n" + menu_items.join("\n")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
MenuItem = Struct.new(:repo, :shortcut, :reference, :next) do
|
13
|
+
HEAD = Rainbow(' <- HEAD ***').bold.aquamarine.freeze
|
14
|
+
|
15
|
+
def head?
|
16
|
+
reference.targets?(repo.head)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
name = reference.name
|
21
|
+
label = format('[%2s]', shortcut)
|
22
|
+
format(
|
23
|
+
" %<label>s\t%<name>s%<head>s",
|
24
|
+
label: head? ? Rainbow(label).bold : label,
|
25
|
+
name: head? ? Rainbow(name).inverse : name,
|
26
|
+
head: head? ? HEAD : '',
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.for(repo)
|
32
|
+
new(repo)
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(repo)
|
36
|
+
@repo = repo
|
37
|
+
|
38
|
+
remote_branches = @repo.branches.find_all(&:remote?)
|
39
|
+
local_branches = @repo.branches.find_all(&:local?)
|
40
|
+
|
41
|
+
@submenus = [
|
42
|
+
submenu_for('REMOTE BRANCHES', remote_branches, shortcuts('a')),
|
43
|
+
submenu_for('LOCAL BRANCHES', local_branches, shortcuts(1)),
|
44
|
+
submenu_for('TAGS', @repo.tags, shortcuts(100)),
|
45
|
+
].compact
|
46
|
+
|
47
|
+
@menu_items = @submenus.map(&:menu_items).flatten
|
48
|
+
|
49
|
+
@lookup = Hash[@menu_items.map(&:shortcut).zip(@menu_items)]
|
50
|
+
end
|
51
|
+
|
52
|
+
def [](shortcut)
|
53
|
+
@lookup[shortcut]
|
54
|
+
end
|
55
|
+
|
56
|
+
def head_menu_item
|
57
|
+
@menu_items.find(&:head?)
|
58
|
+
end
|
59
|
+
|
60
|
+
def default_menu_item
|
61
|
+
head_menu_item&.next
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_s
|
65
|
+
@submenus.join("\n")
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def shortcuts(initial)
|
71
|
+
shortcut = initial
|
72
|
+
Enumerator.new do |yielder|
|
73
|
+
loop do
|
74
|
+
yielder << shortcut
|
75
|
+
shortcut = case shortcut
|
76
|
+
when Integer then shortcut + 1
|
77
|
+
when String then (shortcut.ord + 1).chr
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def submenu_for(label, references, shortcuts)
|
84
|
+
return unless references.any?
|
85
|
+
|
86
|
+
Submenu.new(label, menu_items_for(references, shortcuts))
|
87
|
+
end
|
88
|
+
|
89
|
+
def menu_items_for(references, shortcuts)
|
90
|
+
previous_menu_item = nil
|
91
|
+
references.sort_by(&:time).map { |reference|
|
92
|
+
shortcut = shortcuts.next.to_s
|
93
|
+
next_menu_item = MenuItem.new(@repo, shortcut, reference, nil)
|
94
|
+
previous_menu_item&.next = next_menu_item
|
95
|
+
previous_menu_item = next_menu_item
|
96
|
+
next_menu_item
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/lib/git/switcher.rb
ADDED