git_switch 0.2.0 → 0.2.1
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/lib/git_switch.rb +1 -0
- data/lib/git_switch/options.rb +42 -0
- data/lib/git_switch/switcher.rb +42 -53
- data/lib/git_switch/version.rb +1 -1
- metadata +3 -16
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b1c118538687a8e712df595736aa99fb7a792ee0be38c9815bae263bbbbe74ef
|
|
4
|
+
data.tar.gz: 5697514a46453a8a389ee3f9aabb44fc4c5d99a99b1beaf9a9f1437fe68ee505
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 739310cbbdf7ffea8df39641c12a99f524dd06b1948ddf7b9fabf95d4dae71b32ad0acd723dc8663144a65e84d77f1c20d468ac2046b0ea6731db8b8910ef3c2
|
|
7
|
+
data.tar.gz: 79adbfc5a56e137e32a7556014c57687dceb8b535b61054e7e8e2e12e96c6160c7b6dcf382528a3307d13800ec42eb534c13b0491618a07dc2a96116ace862eb
|
data/lib/git_switch.rb
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module GitSwitch
|
|
2
|
+
class Options
|
|
3
|
+
attr_reader :args
|
|
4
|
+
def initialize(args)
|
|
5
|
+
@args = args
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def valid_args?
|
|
9
|
+
if list? && args.count > 1
|
|
10
|
+
puts "Invalid args"
|
|
11
|
+
return false
|
|
12
|
+
elsif no_flags?(args) || one_flag?(args)
|
|
13
|
+
return true
|
|
14
|
+
else
|
|
15
|
+
puts "Invalid args"
|
|
16
|
+
return false
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def list?
|
|
21
|
+
(args.include? '-l') || (args.include? '--list')
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def global?
|
|
25
|
+
(args.include? '-g') || (args.include? '--global')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def no_flags?(args)
|
|
31
|
+
args.length == 1 && flag_count(args) == 0
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def one_flag?(args)
|
|
35
|
+
args.length == 2 && flag_count(args) == 1
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def flag_count(args)
|
|
39
|
+
args.count {|a| a.start_with? '-'}
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
data/lib/git_switch/switcher.rb
CHANGED
|
@@ -3,51 +3,31 @@ require_relative './version'
|
|
|
3
3
|
|
|
4
4
|
module GitSwitch
|
|
5
5
|
class Switcher
|
|
6
|
-
attr_reader :
|
|
6
|
+
attr_reader :config, :profile, :options
|
|
7
7
|
|
|
8
8
|
def initialize(args)
|
|
9
9
|
raise ArgumentError unless args.is_a? Array
|
|
10
|
-
@args = args
|
|
11
10
|
@config = load_config
|
|
12
|
-
@
|
|
11
|
+
@options = GitSwitch::Options.new(args)
|
|
13
12
|
@profile = get_profile(args)
|
|
14
|
-
@list = check_list(args)
|
|
15
13
|
end
|
|
16
14
|
|
|
17
15
|
def run
|
|
18
|
-
list ? print_list : set!
|
|
16
|
+
list? ? print_list : set!
|
|
19
17
|
end
|
|
20
18
|
|
|
21
|
-
def
|
|
22
|
-
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def check_global(args)
|
|
26
|
-
(args.include? '-g') || (args.include? '--global')
|
|
19
|
+
def list?
|
|
20
|
+
options.list?
|
|
27
21
|
end
|
|
28
22
|
|
|
29
|
-
def
|
|
30
|
-
|
|
23
|
+
def global?
|
|
24
|
+
options.global?
|
|
31
25
|
end
|
|
32
26
|
|
|
33
27
|
def get_profile(args)
|
|
34
|
-
# TODO: RCR - Verify profile exists in config file
|
|
35
|
-
# TODO: RCR - Handle missing or empty config file
|
|
36
28
|
args.detect {|a| !a.start_with? '-'}
|
|
37
29
|
end
|
|
38
30
|
|
|
39
|
-
def valid_args?
|
|
40
|
-
if check_list(args) && args.count > 1
|
|
41
|
-
puts "Invalid args"
|
|
42
|
-
return false
|
|
43
|
-
elsif no_flags?(args) || one_flag?(args)
|
|
44
|
-
return true
|
|
45
|
-
else
|
|
46
|
-
puts "Invalid args"
|
|
47
|
-
return false
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
31
|
def valid_profile?
|
|
52
32
|
if config.has_key?(profile)
|
|
53
33
|
return true
|
|
@@ -61,7 +41,7 @@ module GitSwitch
|
|
|
61
41
|
if GitHelper.git_repo?
|
|
62
42
|
return true
|
|
63
43
|
else
|
|
64
|
-
if global
|
|
44
|
+
if global?
|
|
65
45
|
return true
|
|
66
46
|
else
|
|
67
47
|
puts "Not a git repo. Please run from a git repo or run with `-g` to update global settings."
|
|
@@ -70,42 +50,36 @@ module GitSwitch
|
|
|
70
50
|
end
|
|
71
51
|
end
|
|
72
52
|
|
|
73
|
-
def no_flags?(args)
|
|
74
|
-
args.length == 1 && flag_count(args) == 0
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def one_flag?(args)
|
|
78
|
-
args.length == 2 && flag_count(args) == 1
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def flag_count(args)
|
|
82
|
-
args.count {|a| a.start_with? '-'}
|
|
83
|
-
end
|
|
84
|
-
|
|
85
53
|
def set!
|
|
86
|
-
return unless valid_args? && valid_profile?
|
|
54
|
+
return unless options.valid_args? && valid_profile?
|
|
87
55
|
return unless git_repo?
|
|
88
56
|
|
|
89
|
-
flag = global ? '--global' : ''
|
|
90
|
-
|
|
91
|
-
puts "\nGit Config:"
|
|
92
|
-
`git config #{flag} user.name "#{name}"`
|
|
93
|
-
`git config #{flag} user.username "#{username}"`
|
|
94
|
-
`git config #{flag} user.email "#{email}"`
|
|
95
|
-
puts `git config #{flag} -l --show-origin | grep user`
|
|
57
|
+
flag = global? ? '--global' : ''
|
|
96
58
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
`ssh-add #{ssh}`
|
|
100
|
-
puts `ssh-add -l`
|
|
59
|
+
set_git_config(flag)
|
|
60
|
+
set_ssh
|
|
101
61
|
end
|
|
102
62
|
|
|
103
63
|
def print_list
|
|
104
|
-
|
|
64
|
+
profiles = config.map do |key, value|
|
|
65
|
+
prefix = value["username"] == current_git_username ? "=>" : " "
|
|
66
|
+
"#{prefix} #{key}"
|
|
67
|
+
end
|
|
68
|
+
puts profiles
|
|
69
|
+
puts "\n# => - current" if config.any? {|key, value| value["username"] == current_git_username}
|
|
105
70
|
end
|
|
106
71
|
|
|
107
72
|
private
|
|
108
73
|
|
|
74
|
+
def load_config
|
|
75
|
+
# TODO: RCR - Handle missing or empty config file
|
|
76
|
+
YAML.load_file(File.expand_path('~/.gitswitch')) || {}
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def current_git_username
|
|
80
|
+
`git config user.username`.chomp
|
|
81
|
+
end
|
|
82
|
+
|
|
109
83
|
def name
|
|
110
84
|
config[profile]["name"]
|
|
111
85
|
end
|
|
@@ -121,5 +95,20 @@ module GitSwitch
|
|
|
121
95
|
def ssh
|
|
122
96
|
config[profile]["ssh"]
|
|
123
97
|
end
|
|
98
|
+
|
|
99
|
+
def set_git_config(flag)
|
|
100
|
+
puts "\nGit Config:"
|
|
101
|
+
`git config #{flag} user.name "#{name}"`
|
|
102
|
+
`git config #{flag} user.username "#{username}"`
|
|
103
|
+
`git config #{flag} user.email "#{email}"`
|
|
104
|
+
puts `git config #{flag} -l --show-origin | grep user`
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def set_ssh
|
|
108
|
+
puts "\nSSH:"
|
|
109
|
+
`ssh-add -D`
|
|
110
|
+
`ssh-add #{ssh}`
|
|
111
|
+
puts `ssh-add -l`
|
|
112
|
+
end
|
|
124
113
|
end
|
|
125
114
|
end
|
data/lib/git_switch/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: git_switch
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Randall Reed, Jr.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-
|
|
11
|
+
date: 2018-09-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -66,20 +66,6 @@ dependencies:
|
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: 0.4.1
|
|
69
|
-
- !ruby/object:Gem::Dependency
|
|
70
|
-
name: byebug
|
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
|
72
|
-
requirements:
|
|
73
|
-
- - "~>"
|
|
74
|
-
- !ruby/object:Gem::Version
|
|
75
|
-
version: '10.0'
|
|
76
|
-
type: :development
|
|
77
|
-
prerelease: false
|
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
-
requirements:
|
|
80
|
-
- - "~>"
|
|
81
|
-
- !ruby/object:Gem::Version
|
|
82
|
-
version: '10.0'
|
|
83
69
|
description: Easily switch between git profiles (name, username, email) and ssh keys
|
|
84
70
|
email:
|
|
85
71
|
- randallreedjr@gmail.com
|
|
@@ -91,6 +77,7 @@ files:
|
|
|
91
77
|
- bin/git-switch
|
|
92
78
|
- lib/git_switch.rb
|
|
93
79
|
- lib/git_switch/git_helper.rb
|
|
80
|
+
- lib/git_switch/options.rb
|
|
94
81
|
- lib/git_switch/switcher.rb
|
|
95
82
|
- lib/git_switch/version.rb
|
|
96
83
|
homepage: https://www.github.com/randallreedjr/git_switch
|