gitswitch 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/tests.yml +32 -0
- data/README.rdoc +1 -15
- data/Rakefile +0 -1
- data/bin/gitswitch +2 -1
- data/gitswitch.gemspec +14 -8
- data/lib/gitswitch.rb +5 -0
- data/lib/gitswitch/cli.rb +173 -130
- data/lib/gitswitch/commands.rb +18 -18
- data/lib/gitswitch/git.rb +8 -9
- data/lib/gitswitch/version.rb +3 -3
- data/spec/git_spec.rb +1 -2
- data/spec/gitswitch_spec.rb +0 -6
- data/spec/spec_helper.rb +5 -6
- metadata +42 -10
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e495045a498536c929c7ee81a01d0d4c2d2dde1622d9df5c4a09bf374fcee99e
|
4
|
+
data.tar.gz: 4f59cc61dec0c72ad4e0561743cd218b1e27af1d72750b97a1f533497cdeeeb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bcc6bed6d628b752034312cfbf58a30c9b7b8e0bc373b5d596538b7930de38f1f13e423171a9aeb2cf838da1430349797a93fed5c15c916fa0f5e835e7e6a0b
|
7
|
+
data.tar.gz: 6c0393c27ad23ddabc7d51e75616b63ef523006494303fab6176026c65acd0dbe5923fc741de46a8318ea047bb34a9cd9bb771485736958792abd43dc3484eb9
|
@@ -0,0 +1,32 @@
|
|
1
|
+
name: Ruby CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
paths-ignore:
|
8
|
+
- 'README.rdoc'
|
9
|
+
pull_request:
|
10
|
+
branches:
|
11
|
+
- main
|
12
|
+
paths-ignore:
|
13
|
+
- 'README.rdoc'
|
14
|
+
jobs:
|
15
|
+
test:
|
16
|
+
runs-on: ubuntu-latest
|
17
|
+
if: "contains(github.event.commits[0].message, '[ci skip]') == false"
|
18
|
+
|
19
|
+
strategy:
|
20
|
+
matrix:
|
21
|
+
ruby: [3.0.2, 2.7.4, 2.6.8, 2.5.9]
|
22
|
+
|
23
|
+
steps:
|
24
|
+
- name: Checkout
|
25
|
+
uses: actions/checkout@v2
|
26
|
+
- name: Setup Ruby
|
27
|
+
uses: ruby/setup-ruby@v1
|
28
|
+
with:
|
29
|
+
ruby-version: ${{ matrix.ruby }}
|
30
|
+
bundler-cache: true
|
31
|
+
- name: Test
|
32
|
+
run: bundle exec rake spec
|
data/README.rdoc
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
= gitswitch
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/joealba/gitswitch.svg?branch=master)](https://travis-ci.org/joealba/gitswitch)
|
4
|
-
|
5
3
|
Easily set/switch your current git user info for a git repo .git/config or your global ~/.gitconfig file.
|
6
4
|
|
7
5
|
This gem should come in handy if you have work and personal repositories. It also might help with switching between users while pair programming.
|
@@ -55,19 +53,7 @@ Delete a current entry. [TAG] parameter is optional. If omitted, you'll see a
|
|
55
53
|
# gitswitch delete [TAG]
|
56
54
|
|
57
55
|
Update your global .git user instead of your current repository
|
58
|
-
# gitswitch
|
56
|
+
# gitswitch switch work --global
|
59
57
|
|
60
58
|
Show your current git user info. If you are in a git repo directory, it will show you the info associated with the current repository. Outside a repo (or if you use the --global option), it will show you the info from your global .git config.
|
61
59
|
# gitswitch info
|
62
|
-
|
63
|
-
== What's with all the aliases for each task?
|
64
|
-
|
65
|
-
I initially wrote the gem using optparse and used the '-r' style params to keep the commands as short as possible. Now, I've decided to lean toward a rake-style descriptive method of passing commands -- which meshes well with the way Thor likes to do things. But the old command line options still work fine in case you got used to it.
|
66
|
-
|
67
|
-
== Recent changes (2012 edition)
|
68
|
-
|
69
|
-
I've learned a few things, taken some inspiration from David Copeland's "Build Awesome Command-Line Applications in Ruby" book, and stolen the idea of making everything a class method from Hashrocket's hitch gem.
|
70
|
-
|
71
|
-
In Ruby 1.9, command line argument strings get frozen, which makes gsub! unhappy. I wasn't on 1.9 two years ago, and my tests are far too incomplete for Travis CI to catch this bug. But alas, it is now fixed.
|
72
|
-
|
73
|
-
I've made the first steps toward returning reasonable exit status codes. A failed git command will not yet throw a proper exit code.
|
data/Rakefile
CHANGED
data/bin/gitswitch
CHANGED
data/gitswitch.gemspec
CHANGED
@@ -9,17 +9,23 @@ Gem::Specification.new do |s|
|
|
9
9
|
|
10
10
|
s.authors = ["Joe Alba"]
|
11
11
|
s.date = %q{2012-04-29}
|
12
|
-
s.
|
13
|
-
s.homepage = %q{http://github.com/joealba/gitswitch}
|
12
|
+
s.homepage = %q{https://github.com/joealba/gitswitch}
|
14
13
|
s.description = %q{Easily switch your git name/e-mail user info -- Handy for work vs. personal and for pair programming}
|
15
14
|
s.summary = %q{Easy git user switching}
|
16
15
|
s.email = %q{joe@joealba.com}
|
17
|
-
|
16
|
+
s.metadata = {
|
17
|
+
"bug_tracker_uri" => "#{s.homepage}/issues",
|
18
|
+
"changelog_uri" => "#{s.homepage}/blob/main/CHANGELOG.md",
|
19
|
+
"documentation_uri" => s.homepage.to_s,
|
20
|
+
"homepage_uri" => s.homepage.to_s,
|
21
|
+
"source_code_uri" => s.homepage.to_s
|
22
|
+
}
|
23
|
+
|
18
24
|
s.extra_rdoc_files = [
|
19
25
|
"LICENSE",
|
20
26
|
"README.rdoc"
|
21
27
|
]
|
22
|
-
|
28
|
+
|
23
29
|
s.files = `git ls-files`.split("\n")
|
24
30
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
25
31
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
@@ -27,9 +33,9 @@ Gem::Specification.new do |s|
|
|
27
33
|
|
28
34
|
s.rdoc_options = ["--charset=UTF-8"]
|
29
35
|
|
30
|
-
|
31
|
-
|
36
|
+
s.add_dependency('rake')
|
37
|
+
s.add_dependency('dry-cli')
|
38
|
+
s.add_dependency('tty-prompt')
|
32
39
|
s.add_development_dependency(%q<rspec>, [">= 3.3.0"])
|
33
|
-
|
40
|
+
s.add_development_dependency 'simplecov'
|
34
41
|
end
|
35
|
-
|
data/lib/gitswitch.rb
CHANGED
data/lib/gitswitch/cli.rb
CHANGED
@@ -1,164 +1,207 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
if yes?("Gitswitch users file ~/.gitswitch not found. Would you like to create one? (y/n): ")
|
14
|
-
Gitswitch.create_fresh_gitswitch_file
|
15
|
-
else
|
16
|
-
puts "Ok, that's fine. Exiting."
|
17
|
-
exit EXIT_OK
|
1
|
+
require "dry/cli"
|
2
|
+
require "tty-prompt"
|
3
|
+
|
4
|
+
module Gitswitch
|
5
|
+
module CLI
|
6
|
+
module Helpers
|
7
|
+
def prompt_for_email_and_name
|
8
|
+
prompt = TTY::Prompt.new
|
9
|
+
email = prompt.ask(" E-mail address: ").to_s.chomp
|
10
|
+
if email.empty?
|
11
|
+
puts "No e-mail address provided"
|
12
|
+
exit Gitswitch::EXIT_MISSING_INFO
|
18
13
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
|
15
|
+
default_name = Gitswitch::get_git_user_info({global: true})[:name]
|
16
|
+
name = prompt.ask(" Name: (ENTER to use \"" + default_name + "\") ").to_s.chomp
|
17
|
+
name = default_name if name.empty?
|
18
|
+
|
19
|
+
if name.empty?
|
20
|
+
puts "No name provided"
|
22
21
|
end
|
22
|
+
|
23
|
+
return [email, name]
|
23
24
|
end
|
25
|
+
end
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
module Commands
|
28
|
+
extend Dry::CLI::Registry
|
29
|
+
|
30
|
+
class Init < Dry::CLI::Command
|
31
|
+
desc "Initialize your .gitswitch file"
|
32
|
+
|
33
|
+
def call(*)
|
34
|
+
prompt = TTY::Prompt.new
|
35
|
+
|
36
|
+
if !Gitswitch::gitswitch_file_exists
|
37
|
+
if prompt.yes?("Gitswitch users file ~/.gitswitch not found. Would you like to create one? (y/n):")
|
38
|
+
Gitswitch.create_fresh_gitswitch_file
|
39
|
+
else
|
40
|
+
puts "Ok, that's fine. Exiting."
|
41
|
+
exit Gitswitch::EXIT_OK
|
42
|
+
end
|
43
|
+
else
|
44
|
+
if prompt.yes?("Gitswitch users file ~/.gitswitch already exists. Would you like to wipe it out and create a fresh one? (y/n):")
|
45
|
+
Gitswitch.create_fresh_gitswitch_file
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Grab the current global info to drop into the default slot -- if available
|
50
|
+
user = Gitswitch.get_git_user_info({global: true})
|
51
|
+
if user[:name].empty? && user[:email].empty?
|
52
|
+
puts "No global git user.name and user.email configurations were found. Set up a default now."
|
53
|
+
add('default')
|
54
|
+
else
|
55
|
+
puts "Adding your global .gitconfig user info to the \"default\" tag..."
|
56
|
+
Gitswitch.set_gitswitch_entry('default', user[:email], user[:name])
|
57
|
+
end
|
58
|
+
|
59
|
+
exit Gitswitch::EXIT_OK
|
60
|
+
end
|
33
61
|
end
|
34
62
|
|
35
|
-
|
36
|
-
|
63
|
+
class Info < Dry::CLI::Command
|
64
|
+
desc "Show the current git user"
|
65
|
+
option :global, type: :boolean, default: false, desc: "Show global config"
|
37
66
|
|
38
|
-
|
39
|
-
|
40
|
-
desc "version", "Show the gitswitch version"
|
41
|
-
map ["-v","--version"] => :version
|
42
|
-
def version
|
43
|
-
puts Gitswitch::VERSION
|
44
|
-
exit EXIT_OK
|
45
|
-
end
|
67
|
+
def call(**options)
|
68
|
+
puts Gitswitch.current_user_info(options)
|
46
69
|
|
70
|
+
exit Gitswitch::EXIT_OK
|
71
|
+
end
|
72
|
+
end
|
47
73
|
|
48
|
-
|
49
|
-
|
50
|
-
map "-i" => :info
|
51
|
-
method_option :global, :type => :boolean
|
52
|
-
def info
|
53
|
-
puts Gitswitch.current_user_info(options)
|
54
|
-
exit EXIT_OK
|
55
|
-
end
|
74
|
+
class List < Dry::CLI::Command
|
75
|
+
desc "Show all the git user tags you have configured"
|
56
76
|
|
77
|
+
def call(*)
|
78
|
+
puts Gitswitch.list_users
|
57
79
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
def list
|
62
|
-
puts Gitswitch.list_users
|
63
|
-
exit EXIT_OK
|
64
|
-
end
|
80
|
+
exit Gitswitch::EXIT_OK
|
81
|
+
end
|
82
|
+
end
|
65
83
|
|
84
|
+
class Switch < Dry::CLI::Command
|
85
|
+
desc "Switch git user"
|
86
|
+
argument :tag, desc: "Tag name"
|
87
|
+
option :global, type: :boolean, default: false, desc: "Set global config"
|
66
88
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
method_option :global, :type => :boolean, :aliases => ["-s","--global"] ## To support the deprecated behavior
|
71
|
-
method_option :repository, :type => :boolean, :aliases => "-r"
|
72
|
-
def switch(tag = 'default')
|
73
|
-
options[:global] ? global(tag) : Gitswitch.switch_repo_user(tag)
|
74
|
-
puts Gitswitch.current_user_info(options)
|
75
|
-
exit EXIT_OK
|
76
|
-
end
|
89
|
+
def call(tag: "default", **options)
|
90
|
+
options[:global] ? Gitswitch.switch_global_user(tag) : Gitswitch.switch_repo_user(tag)
|
91
|
+
puts Gitswitch.current_user_info(options)
|
77
92
|
|
93
|
+
exit Gitswitch::EXIT_OK
|
94
|
+
end
|
95
|
+
end
|
78
96
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
def global(tag = 'default')
|
83
|
-
Gitswitch.switch_global_user(tag)
|
84
|
-
exit EXIT_OK
|
85
|
-
end
|
97
|
+
class Global < Dry::CLI::Command
|
98
|
+
desc "Switch the global git user info (your ~/.gitconfig file)"
|
99
|
+
argument :tag, desc: "Tag name"
|
86
100
|
|
101
|
+
def call(tag: "default", **)
|
102
|
+
Gitswitch.switch_global_user(tag)
|
87
103
|
|
88
|
-
|
89
|
-
|
90
|
-
map ["-a","--add"] => :add
|
91
|
-
def add(tag = '')
|
92
|
-
# tag.gsub!(/\W+/,'') ## ARGV gets frozen, so gsub! will throw an error.
|
93
|
-
tag = tag.gsub(/\W+/,'')
|
94
|
-
tag = ask("Enter a tag to describe this git user entry: ").gsub(/\W+/,'') if (tag.nil? || tag.empty?)
|
95
|
-
|
96
|
-
if tag.empty?
|
97
|
-
puts "You must enter a short tag to describe the git user entry you would like to save."
|
98
|
-
exit EXIT_MISSING_INFO
|
104
|
+
exit Gitswitch::EXIT_OK
|
105
|
+
end
|
99
106
|
end
|
100
107
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
108
|
+
class Add < Dry::CLI::Command
|
109
|
+
include ::Gitswitch::CLI::Helpers
|
110
|
+
|
111
|
+
desc "Add a new tagged user entry"
|
112
|
+
argument :tag, desc: "Tag name"
|
106
113
|
|
114
|
+
def call(tag: "", **)
|
115
|
+
tag = tag.gsub(/\W+/,'')
|
116
|
+
if (tag.nil? || tag.empty?)
|
117
|
+
prompt = TTY::Prompt.new
|
118
|
+
tag = prompt.ask("Enter a tag to describe this git user entry: ").to_s.gsub(/\W+/,'')
|
119
|
+
end
|
107
120
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
121
|
+
if tag.empty?
|
122
|
+
puts "You must enter a short tag to describe the git user entry you would like to save."
|
123
|
+
exit Gitswitch::EXIT_MISSING_INFO
|
124
|
+
end
|
125
|
+
|
126
|
+
puts "Adding a new gitswitch user entry for tag '#{tag}'"
|
127
|
+
(email, name) = prompt_for_email_and_name
|
128
|
+
Gitswitch.set_gitswitch_entry(tag, email, name)
|
129
|
+
exit Gitswitch::EXIT_OK
|
130
|
+
end
|
117
131
|
end
|
118
|
-
|
119
|
-
puts "Updating #{tag} entry..."
|
120
|
-
(email, name) = prompt_for_email_and_name
|
121
|
-
Gitswitch.set_gitswitch_entry(tag, email, name)
|
122
|
-
exit EXIT_OK
|
123
|
-
end
|
124
132
|
|
133
|
+
class Delete < Dry::CLI::Command
|
134
|
+
desc "Delete a tagged user entry"
|
135
|
+
|
136
|
+
def call(tag: "")
|
137
|
+
tag_table = Gitswitch.get_tag_display
|
138
|
+
|
139
|
+
tag = tag.gsub(/\W+/, '')
|
140
|
+
if (tag.empty?)
|
141
|
+
puts tag_table
|
142
|
+
prompt = TTY::Prompt.new
|
143
|
+
tag = prompt.ask("\nWhich tag would you like to delete: ").to_s.gsub(/\W+/,'')
|
144
|
+
end
|
125
145
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
146
|
+
if tag.empty?
|
147
|
+
puts "No tag chosen"
|
148
|
+
exit Gitswitch::EXIT_MISSING_INFO
|
149
|
+
end
|
150
|
+
|
151
|
+
Gitswitch.delete_gitswitch_entry(tag)
|
152
|
+
|
153
|
+
puts Gitswitch.get_tag_display
|
154
|
+
|
155
|
+
exit Gitswitch::EXIT_OK
|
156
|
+
end
|
134
157
|
end
|
135
158
|
|
136
|
-
|
137
|
-
|
138
|
-
end
|
159
|
+
class Update < Dry::CLI::Command
|
160
|
+
include ::Gitswitch::CLI::Helpers
|
139
161
|
|
162
|
+
desc "Update a tagged user entry"
|
163
|
+
argument :tag, desc: "Tag name"
|
140
164
|
|
141
|
-
|
142
|
-
|
165
|
+
def call(tag: "", **)
|
166
|
+
tag_table = Gitswitch.get_tag_display
|
143
167
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
168
|
+
tag = tag.gsub(/\W+/, '')
|
169
|
+
if (tag.empty?)
|
170
|
+
prompt = TTY::Prompt.new
|
171
|
+
tag = prompt.ask("Which tag would you like to update: \n#{tag_table}\nTag: ").to_s.gsub(/\W+/,'')
|
172
|
+
end
|
173
|
+
|
174
|
+
if tag.empty?
|
175
|
+
puts "No tag chosen"
|
176
|
+
exit Gitswitch::EXIT_MISSING_INFO
|
177
|
+
end
|
178
|
+
|
179
|
+
puts "Updating #{tag} entry..."
|
180
|
+
(email, name) = prompt_for_email_and_name
|
181
|
+
Gitswitch.set_gitswitch_entry(tag, email, name)
|
182
|
+
|
183
|
+
exit Gitswitch::EXIT_OK
|
184
|
+
end
|
150
185
|
end
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
186
|
+
|
187
|
+
class Version < Dry::CLI::Command
|
188
|
+
desc "Show the gitswitch version"
|
189
|
+
|
190
|
+
def call(*)
|
191
|
+
puts Gitswitch::VERSION
|
192
|
+
|
193
|
+
exit Gitswitch::EXIT_OK
|
194
|
+
end
|
157
195
|
end
|
158
196
|
|
159
|
-
|
197
|
+
register "add", Add, aliases: ["-a", "--add"]
|
198
|
+
register "delete", Delete, aliases: ["remove"]
|
199
|
+
register "info", Info, aliases: ["-i", "--info"]
|
200
|
+
register "init", Init
|
201
|
+
register "list", List, aliases: ["-l", "--list"]
|
202
|
+
register "switch", Switch, aliases: ["-r"]
|
203
|
+
register "update", Update, aliases: ["-o","--overwrite"]
|
204
|
+
register "version", Version, aliases: ["-v", "--version"]
|
160
205
|
end
|
161
|
-
|
162
|
-
|
163
206
|
end
|
164
|
-
end
|
207
|
+
end
|
data/lib/gitswitch/commands.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
|
-
|
4
|
-
def self.gitswitch_config_file
|
3
|
+
module Gitswitch
|
4
|
+
def self.gitswitch_config_file
|
5
5
|
ENV['GITSWITCH_CONFIG_FILE'] || File.join(ENV["HOME"], ".gitswitch")
|
6
6
|
end
|
7
7
|
|
@@ -47,7 +47,7 @@ class Gitswitch
|
|
47
47
|
# * +email+ - Required
|
48
48
|
# * +name+ - Required
|
49
49
|
def self.set_gitswitch_entry(tag, email, name)
|
50
|
-
users[tag] = {:
|
50
|
+
users[tag] = {name: name, email: email}
|
51
51
|
save_gitswitch_file(users)
|
52
52
|
end
|
53
53
|
|
@@ -61,7 +61,7 @@ class Gitswitch
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def self.get_user(tag)
|
64
|
-
## TODO: Stop coding so defensively.
|
64
|
+
## TODO: Stop coding so defensively.
|
65
65
|
if !users.empty? && users[tag] && !users[tag].empty?
|
66
66
|
users[tag]
|
67
67
|
end
|
@@ -72,28 +72,30 @@ class Gitswitch
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def self.get_tag_display
|
75
|
-
|
76
|
-
|
75
|
+
users.map do |key, user|
|
76
|
+
item = "#{key}:\n"
|
77
|
+
item << " Name: #{user[:name]}\n" if !user[:name].to_s.empty?
|
78
|
+
item << " E-mail: #{user[:email]}\n"
|
79
|
+
item
|
80
|
+
end.join("\n")
|
77
81
|
end
|
78
82
|
|
79
83
|
def self.list_users
|
80
|
-
response =
|
81
|
-
response <<
|
82
|
-
|
83
|
-
response << "#{key}:\n"
|
84
|
-
response << " Name: #{user[:name]}\n" if !user[:name].to_s.empty?
|
85
|
-
response << " E-mail: #{user[:email]}\n\n"
|
86
|
-
end
|
84
|
+
response = "\nCurrent git user options --\n"
|
85
|
+
response << get_tag_display
|
86
|
+
|
87
87
|
response
|
88
88
|
end
|
89
89
|
|
90
90
|
## Return active user information.
|
91
91
|
## If you're in a git repo, show that user info. Otherwise, display the global info.
|
92
92
|
def self.current_user_info(options = {})
|
93
|
-
response = !Gitswitch::in_a_git_repo || options[:global] ? "Your git user information from your global config:\n" : "Your git user information from the current repository:\n"
|
94
93
|
current_git_user = Gitswitch::get_git_user_info(options)
|
95
|
-
|
94
|
+
|
95
|
+
response = !Gitswitch::in_a_git_repo || options[:global] ? "Your git user information from your global config:\n" : "Your git user information from the current repository:\n"
|
96
|
+
response << "Name: #{current_git_user[:name]}\n"
|
96
97
|
response << "E-mail: #{current_git_user[:email]}\n"
|
98
|
+
|
97
99
|
response
|
98
100
|
end
|
99
101
|
|
@@ -105,7 +107,7 @@ class Gitswitch
|
|
105
107
|
def self.switch_global_user(tag = "default")
|
106
108
|
if user = get_user(tag)
|
107
109
|
puts "Switching your .gitconfig user info to \"#{tag}\" tag (#{user[:name]} <#{user[:email]}>)."
|
108
|
-
git_config(user, {:
|
110
|
+
git_config(user, {global: true})
|
109
111
|
else
|
110
112
|
puts "ERROR: Could not find info for tag \"#{tag}\" in your .gitswitch file"
|
111
113
|
end
|
@@ -130,7 +132,6 @@ class Gitswitch
|
|
130
132
|
end
|
131
133
|
end
|
132
134
|
|
133
|
-
|
134
135
|
##############################################################
|
135
136
|
# TODO: Straight delegation through to Gitswitch::Git
|
136
137
|
def self.in_a_git_repo
|
@@ -144,5 +145,4 @@ class Gitswitch
|
|
144
145
|
def self.get_git_user_info(options = {})
|
145
146
|
Gitswitch::Git.get_git_user_info(options)
|
146
147
|
end
|
147
|
-
|
148
148
|
end
|
data/lib/gitswitch/git.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'shellwords' if !String.new.methods.include?('shellescape')
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Gitswitch
|
4
|
+
module Git
|
5
5
|
GIT_BIN = '/usr/bin/env git'
|
6
6
|
|
7
7
|
def self.version
|
@@ -15,7 +15,7 @@ class Gitswitch
|
|
15
15
|
def self.git_config(user, options = {})
|
16
16
|
git_args = 'config --replace-all'
|
17
17
|
git_args += ' --global' if options[:global]
|
18
|
-
|
18
|
+
|
19
19
|
%x(#{GIT_BIN} #{git_args} user.email #{user[:email].to_s.shellescape})
|
20
20
|
%x(#{GIT_BIN} #{git_args} user.name #{user[:name].to_s.shellescape}) if !user[:name].to_s.empty?
|
21
21
|
end
|
@@ -23,12 +23,11 @@ class Gitswitch
|
|
23
23
|
def self.get_git_user_info(options = {})
|
24
24
|
git_args = 'config --get'
|
25
25
|
git_args += ' --global' if options[:global]
|
26
|
-
|
26
|
+
|
27
27
|
{
|
28
|
-
:
|
29
|
-
:
|
30
|
-
}
|
28
|
+
name: %x(#{GIT_BIN} #{git_args} user.name).to_s.chomp,
|
29
|
+
email: %x(#{GIT_BIN} #{git_args} user.email).to_s.chomp
|
30
|
+
}
|
31
31
|
end
|
32
|
-
|
33
32
|
end
|
34
|
-
end
|
33
|
+
end
|
data/lib/gitswitch/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
end
|
1
|
+
module Gitswitch
|
2
|
+
VERSION = "0.5.0"
|
3
|
+
end
|
data/spec/git_spec.rb
CHANGED
data/spec/gitswitch_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Gitswitch do
|
4
|
-
|
5
4
|
describe "basics" do
|
6
5
|
it "should have a VERSION" do
|
7
6
|
expect(Gitswitch::VERSION).not_to eq ''
|
@@ -44,20 +43,15 @@ describe Gitswitch do
|
|
44
43
|
Gitswitch.create_fresh_gitswitch_file
|
45
44
|
expect(Gitswitch.users.keys.count).to eq 0
|
46
45
|
end
|
47
|
-
|
48
46
|
end
|
49
47
|
|
50
|
-
|
51
48
|
describe "weird outlier cases" do
|
52
49
|
it "in a git repo directory with no user info specified, show the global config header and user info" do
|
53
50
|
skip
|
54
51
|
end
|
55
52
|
end
|
56
53
|
|
57
|
-
|
58
54
|
it "shows the current git user credentials" do
|
59
55
|
expect(Gitswitch.current_user_info).to match /^Your git user/
|
60
56
|
end
|
61
|
-
|
62
|
-
|
63
57
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
1
4
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
5
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
-
require 'rubygems'
|
4
|
-
require 'gitswitch'
|
5
|
-
|
6
|
-
require 'bundler'
|
7
|
-
Bundler.setup
|
8
6
|
|
7
|
+
require 'gitswitch'
|
9
8
|
|
10
9
|
RSpec.configure do |c|
|
11
10
|
end
|
@@ -18,4 +17,4 @@ end
|
|
18
17
|
|
19
18
|
def set_test_entry
|
20
19
|
Gitswitch.set_gitswitch_entry(*get_test_entry)
|
21
|
-
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitswitch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Alba
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2012-04-29 00:00:00.000000000 Z
|
@@ -25,7 +25,21 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: dry-cli
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tty-prompt
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
@@ -52,6 +66,20 @@ dependencies:
|
|
52
66
|
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: 3.3.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
description: Easily switch your git name/e-mail user info -- Handy for work vs. personal
|
56
84
|
and for pair programming
|
57
85
|
email: joe@joealba.com
|
@@ -65,9 +93,9 @@ files:
|
|
65
93
|
- ".bundle/config"
|
66
94
|
- ".document"
|
67
95
|
- ".gemtest"
|
96
|
+
- ".github/workflows/tests.yml"
|
68
97
|
- ".gitignore"
|
69
98
|
- ".rspec"
|
70
|
-
- ".travis.yml"
|
71
99
|
- Gemfile
|
72
100
|
- LICENSE
|
73
101
|
- README.rdoc
|
@@ -83,10 +111,15 @@ files:
|
|
83
111
|
- spec/gitswitch_spec.rb
|
84
112
|
- spec/spec_helper.rb
|
85
113
|
- spec/tmp/.gitkeep
|
86
|
-
homepage:
|
114
|
+
homepage: https://github.com/joealba/gitswitch
|
87
115
|
licenses: []
|
88
|
-
metadata:
|
89
|
-
|
116
|
+
metadata:
|
117
|
+
bug_tracker_uri: https://github.com/joealba/gitswitch/issues
|
118
|
+
changelog_uri: https://github.com/joealba/gitswitch/blob/main/CHANGELOG.md
|
119
|
+
documentation_uri: https://github.com/joealba/gitswitch
|
120
|
+
homepage_uri: https://github.com/joealba/gitswitch
|
121
|
+
source_code_uri: https://github.com/joealba/gitswitch
|
122
|
+
post_install_message:
|
90
123
|
rdoc_options:
|
91
124
|
- "--charset=UTF-8"
|
92
125
|
require_paths:
|
@@ -102,9 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
135
|
- !ruby/object:Gem::Version
|
103
136
|
version: '0'
|
104
137
|
requirements: []
|
105
|
-
|
106
|
-
|
107
|
-
signing_key:
|
138
|
+
rubygems_version: 3.2.22
|
139
|
+
signing_key:
|
108
140
|
specification_version: 4
|
109
141
|
summary: Easy git user switching
|
110
142
|
test_files:
|