git-switcher 1.0.4 → 1.0.5
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/git/switcher/menu.rb +44 -47
- data/lib/git/switcher/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1034e1e575b8cdf55bdaf978c135fdff155d716a161498c4aa58a6b45b4e6361
|
4
|
+
data.tar.gz: 43ed44115e64374da365049cb952b3e3f922fe30c95700de292801a677ca8795
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d80b503cd74f5600b49215dd5596f99c562dbff260da62d4035993f23d6a6eabadd21bd1278de5b13e0921e5cda709a5bd846809f104e64c41078b6799c9cf3b
|
7
|
+
data.tar.gz: 057f568046ed72af9901349a0fa0c9364f3fd1973aed86cd29e6f25a5a820d8ba903566997d72526e1aa65c3b66ac50398290709d6a4a4c197ba1823d0392aaf
|
data/Gemfile.lock
CHANGED
data/lib/git/switcher/menu.rb
CHANGED
@@ -1,53 +1,41 @@
|
|
1
1
|
module Git
|
2
2
|
module Switcher
|
3
|
-
class Menu
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
Submenu = Struct.new(:label, :menu_items) do
|
5
|
+
def to_s
|
6
|
+
header = Rainbow(label).steelblue
|
7
|
+
"\n\t#{header}\n\n" + menu_items.join("\n")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
MenuItem = Struct.new(:repo, :shortcut, :reference, :next) do
|
12
|
+
HEAD = Rainbow(' <- HEAD ***').bold.aquamarine.freeze
|
13
|
+
|
14
|
+
def head?
|
15
|
+
reference.targets?(repo.head)
|
10
16
|
end
|
11
17
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
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
|
18
|
+
def to_s
|
19
|
+
name = reference.name
|
20
|
+
label = format('[%2s]', shortcut)
|
21
|
+
format(
|
22
|
+
" %<label>s\t%<name>s%<head>s",
|
23
|
+
label: head? ? Rainbow(label).bold : label,
|
24
|
+
name: head? ? Rainbow(name).inverse : name,
|
25
|
+
head: head? ? HEAD : '',
|
26
|
+
)
|
29
27
|
end
|
28
|
+
end
|
30
29
|
|
30
|
+
class Menu
|
31
31
|
def self.for(repo)
|
32
32
|
new(repo)
|
33
33
|
end
|
34
34
|
|
35
35
|
def initialize(repo)
|
36
36
|
@repo = repo
|
37
|
-
|
38
|
-
remote_branches = @repo.branches.find_all(&:remote?)
|
39
|
-
local_branches = @repo.branches.find_all(&:local?)
|
40
|
-
|
41
|
-
shortcuts = (1..Float::INFINITY).each
|
42
|
-
|
43
|
-
@submenus = [
|
44
|
-
submenu_for('REMOTE BRANCHES', remote_branches, shortcuts),
|
45
|
-
submenu_for('LOCAL BRANCHES', local_branches, shortcuts),
|
46
|
-
submenu_for('TAGS', @repo.tags, shortcuts),
|
47
|
-
].compact
|
48
|
-
|
37
|
+
@submenus = submenus
|
49
38
|
@menu_items = @submenus.map(&:menu_items).flatten
|
50
|
-
|
51
39
|
@lookup = Hash[@menu_items.map(&:shortcut).zip(@menu_items)]
|
52
40
|
end
|
53
41
|
|
@@ -69,17 +57,26 @@ module Git
|
|
69
57
|
|
70
58
|
private
|
71
59
|
|
72
|
-
def
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
60
|
+
def remote_branches
|
61
|
+
@repo.branches.find_all(&:remote?)
|
62
|
+
end
|
63
|
+
|
64
|
+
def local_branches
|
65
|
+
@repo.branches.find_all(&:local?)
|
66
|
+
end
|
67
|
+
|
68
|
+
def tags
|
69
|
+
@repo.tags # TODO: distinguish between annotated and lightweight tags
|
70
|
+
end
|
71
|
+
|
72
|
+
def submenus
|
73
|
+
shortcuts = (1..Float::INFINITY).each
|
74
|
+
|
75
|
+
[
|
76
|
+
submenu_for('REMOTE BRANCHES', remote_branches, shortcuts),
|
77
|
+
submenu_for('LOCAL BRANCHES', local_branches, shortcuts),
|
78
|
+
submenu_for('TAGS', tags, shortcuts),
|
79
|
+
].compact
|
83
80
|
end
|
84
81
|
|
85
82
|
def submenu_for(label, references, shortcuts)
|
data/lib/git/switcher/version.rb
CHANGED