gitswitch 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +28 -13
- data/VERSION +1 -1
- data/gitswitch.gemspec +2 -6
- data/lib/gitswitch.rb +39 -34
- metadata +6 -9
- data/spec/gitswitch_spec.rb +0 -7
- data/spec/spec_helper.rb +0 -5
data/README.rdoc
CHANGED
@@ -1,35 +1,50 @@
|
|
1
1
|
= gitswitch
|
2
2
|
|
3
|
-
Easily switch your current git user info
|
3
|
+
Easily set/switch your current git user info for a git repo .git/config or your global ~/.gitconfig file.
|
4
|
+
|
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.
|
4
6
|
|
5
7
|
Would you rather type "git config user.email 'me@work.com'", etc. or type "gitswitch -r work"? If you answered the latter, check out this gem.
|
6
8
|
|
7
9
|
== Install
|
8
10
|
|
9
|
-
gem install gitswitch
|
11
|
+
# gem install gitswitch
|
10
12
|
|
11
13
|
== Usage
|
12
14
|
|
13
15
|
Simply run the script to establish a default ~/.gitswitch file using the git info you already have in your ~/.gitconfig file
|
14
|
-
gitswitch
|
16
|
+
# gitswitch
|
17
|
+
|
18
|
+
Gitswitch users file ~/.gitswitch not found. Would you like to create one? (y/n): y
|
19
|
+
Adding your global .gitconfig user info to the "default" tag...
|
20
|
+
Current git user information:
|
21
|
+
Name: Joe Alba
|
22
|
+
E-mail: joe@home.com
|
15
23
|
|
16
24
|
Add a new git user tag
|
17
|
-
gitswitch -a
|
25
|
+
# gitswitch -a
|
26
|
+
|
27
|
+
Enter a tag to describe this git user entry: work
|
28
|
+
E-mail address: jalba@work.com
|
29
|
+
Name (ENTER to use "Joe Alba"): Joseph M. Alba
|
18
30
|
|
19
31
|
Set specific user info to your current git repository by updating .git/config
|
20
|
-
gitswitch -r work # Update .git/config with your 'work' git user info
|
21
|
-
|
32
|
+
# gitswitch -r work # Update .git/config with your 'work' git user info
|
33
|
+
Switching git user to "work" tag for the current repository (Joseph M. Alba <jalba@work.com>).
|
34
|
+
|
35
|
+
# gitswitch -r # User info from your 'default' tag is used if you don't specify a tag
|
36
|
+
Switching git user to "default" tag for the current repository (Joe Alba <joe@home.com>).
|
22
37
|
|
23
38
|
List all the gitswitch user tags/info you have stored
|
24
|
-
gitswitch -l
|
39
|
+
# gitswitch -l
|
25
40
|
|
26
41
|
Current git user options --
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
42
|
+
default:
|
43
|
+
Name: Joe Alba
|
44
|
+
E-mail: joe@home.com
|
45
|
+
work:
|
46
|
+
Name: Joseph M. Alba
|
47
|
+
E-mail: jalba@work.com
|
33
48
|
|
34
49
|
== Copyright
|
35
50
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/gitswitch.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{gitswitch}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Joe Alba"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-05}
|
13
13
|
s.default_executable = %q{gitswitch}
|
14
14
|
s.description = %q{Do you write code for your employer and for yourself? Want to easily change the e-mail address associated with your commits for work and home repos? This gem might help you out.}
|
15
15
|
s.email = %q{joe@joealba.com}
|
@@ -34,10 +34,6 @@ Gem::Specification.new do |s|
|
|
34
34
|
s.require_paths = ["lib"]
|
35
35
|
s.rubygems_version = %q{1.3.7}
|
36
36
|
s.summary = %q{Easy git user switching}
|
37
|
-
s.test_files = [
|
38
|
-
"spec/gitswitch_spec.rb",
|
39
|
-
"spec/spec_helper.rb"
|
40
|
-
]
|
41
37
|
|
42
38
|
if s.respond_to? :specification_version then
|
43
39
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
data/lib/gitswitch.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'optparse'
|
2
2
|
require 'yaml'
|
3
|
-
#require 'escape'
|
4
3
|
|
5
4
|
class GitSwitch
|
6
5
|
VERSION_FILE = File.join File.dirname(__FILE__), "..", "VERSION.yml"
|
@@ -18,13 +17,17 @@ class GitSwitch
|
|
18
17
|
@users = {}
|
19
18
|
if File.exists? GITSWITCH_CONFIG_FILE
|
20
19
|
@users = YAML::load_file GITSWITCH_CONFIG_FILE
|
21
|
-
|
20
|
+
if @users.nil?
|
21
|
+
puts "Error loading .gitswitch file"
|
22
|
+
exit
|
23
|
+
end
|
22
24
|
else
|
23
25
|
print "Gitswitch users file ~/.gitswitch not found. Would you like to create one? (y/n): "
|
24
26
|
if gets.chomp =~ /^y/i
|
25
27
|
create_gitswitch_file
|
26
28
|
else
|
27
|
-
puts "Ok, that's fine. Exiting."
|
29
|
+
puts "Ok, that's fine. Exiting."
|
30
|
+
exit
|
28
31
|
end
|
29
32
|
end
|
30
33
|
end
|
@@ -90,11 +93,11 @@ class GitSwitch
|
|
90
93
|
|
91
94
|
# Create a .gitswitch file with the current user defaults
|
92
95
|
def create_gitswitch_file
|
93
|
-
user =
|
96
|
+
user = get_git_user_info({:global => true})
|
94
97
|
if user[:name].empty? && user[:email].empty?
|
95
98
|
puts "ERROR: You must set up a default git user.name and user.email first."
|
96
99
|
else
|
97
|
-
puts "Adding your global
|
100
|
+
puts "Adding your global .gitconfig user info to the \"default\" tag..."
|
98
101
|
set_gitswitch_entry('default', user[:email], user[:name])
|
99
102
|
save_gitswitch_file
|
100
103
|
end
|
@@ -123,10 +126,9 @@ class GitSwitch
|
|
123
126
|
|
124
127
|
|
125
128
|
def get_user(tag)
|
126
|
-
if
|
127
|
-
|
129
|
+
if !@users.empty? && @users[tag] && !@users[tag].empty?
|
130
|
+
@users[tag]
|
128
131
|
end
|
129
|
-
@users[tag]
|
130
132
|
end
|
131
133
|
|
132
134
|
|
@@ -143,10 +145,12 @@ class GitSwitch
|
|
143
145
|
# ==== Parameters
|
144
146
|
# * +tag+ - The tag associated with your desired git info in .gitswitch. Defaults to "default".
|
145
147
|
def switch_global_user tag = "default"
|
146
|
-
user = get_user(tag)
|
147
|
-
|
148
|
-
|
149
|
-
|
148
|
+
if user = get_user(tag)
|
149
|
+
puts "Switching your .gitconfig user info to \"#{tag}\" tag (#{user[:name]} <#{user[:email]}>)."
|
150
|
+
git_config(user, {:global => true})
|
151
|
+
else
|
152
|
+
puts "ERROR: Could not find info for tag \"#{tag}\" in your .gitswitch file"
|
153
|
+
end
|
150
154
|
end
|
151
155
|
|
152
156
|
|
@@ -154,26 +158,33 @@ class GitSwitch
|
|
154
158
|
# ==== Parameters
|
155
159
|
# * +tag+ - The tag associated with your desired git info in .gitswitch. Defaults to "default".
|
156
160
|
def switch_repo_user tag = "default"
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
+
## TODO: See if we're actually in a git repo
|
162
|
+
if user = get_user(tag)
|
163
|
+
puts "Switching git user to \"#{tag}\" tag for the current repository (#{user[:name]} <#{user[:email]}>)."
|
164
|
+
git_config(user) or raise "Could not change the git user settings to your repository."
|
165
|
+
else
|
166
|
+
puts "ERROR: Could not find info for tag \"#{tag}\" in your .gitswitch file"
|
167
|
+
end
|
161
168
|
end
|
162
169
|
|
163
170
|
|
164
171
|
# Add a user entry to your .gitswitch file
|
165
172
|
def add_gitswitch_entry
|
166
|
-
print "
|
173
|
+
print "Enter a tag to describe this git user entry: "
|
167
174
|
tag = gets.gsub(/\W+/,'')
|
175
|
+
|
176
|
+
if tag.empty?
|
177
|
+
puts "You must enter a short tag to describe the git user entry you would like to save."
|
178
|
+
exit
|
179
|
+
end
|
168
180
|
|
169
181
|
print "E-mail address: "
|
170
182
|
email = gets.chomp
|
171
183
|
|
172
|
-
print "Name: (ENTER to use \"" +
|
184
|
+
print "Name: (ENTER to use \"" + get_git_user_info({:global => true})[:name] + "\") "
|
173
185
|
name = gets.chomp
|
174
|
-
if name.empty?
|
175
|
-
|
176
|
-
end
|
186
|
+
name = get_git_user_info({:global => true})[:name] if name.empty?
|
187
|
+
|
177
188
|
set_gitswitch_entry(tag, email, name)
|
178
189
|
end
|
179
190
|
|
@@ -190,7 +201,7 @@ class GitSwitch
|
|
190
201
|
|
191
202
|
# Print active account information.
|
192
203
|
def print_info
|
193
|
-
current_git_user =
|
204
|
+
current_git_user = get_git_user_info
|
194
205
|
puts "Current git user information:\n"
|
195
206
|
puts "Name: #{current_git_user[:name]}"
|
196
207
|
puts "E-mail: #{current_git_user[:email]}"
|
@@ -212,20 +223,14 @@ class GitSwitch
|
|
212
223
|
private
|
213
224
|
|
214
225
|
# Show the current git user info
|
215
|
-
def
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
}
|
220
|
-
end
|
221
|
-
|
222
|
-
# Show the global config git user info
|
223
|
-
def get_global_git_user
|
226
|
+
def get_git_user_info(args = {})
|
227
|
+
git_args = 'config --get'
|
228
|
+
git_args += ' --global' if args[:global]
|
229
|
+
|
224
230
|
{
|
225
|
-
:name => %x(#{GIT_BIN}
|
226
|
-
:email => %x(#{GIT_BIN}
|
231
|
+
:name => %x(#{GIT_BIN} #{git_args} user.name).to_s.chomp,
|
232
|
+
:email => %x(#{GIT_BIN} #{git_args} user.email).to_s.chomp
|
227
233
|
}
|
228
234
|
end
|
229
|
-
|
230
235
|
|
231
236
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitswitch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joe Alba
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-05 00:00:00 -04:00
|
19
19
|
default_executable: gitswitch
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -38,8 +38,6 @@ files:
|
|
38
38
|
- bin/gitswitch
|
39
39
|
- gitswitch.gemspec
|
40
40
|
- lib/gitswitch.rb
|
41
|
-
- spec/gitswitch_spec.rb
|
42
|
-
- spec/spec_helper.rb
|
43
41
|
has_rdoc: true
|
44
42
|
homepage: http://github.com/joealba/gitswitch
|
45
43
|
licenses: []
|
@@ -74,6 +72,5 @@ rubygems_version: 1.3.7
|
|
74
72
|
signing_key:
|
75
73
|
specification_version: 3
|
76
74
|
summary: Easy git user switching
|
77
|
-
test_files:
|
78
|
-
|
79
|
-
- spec/spec_helper.rb
|
75
|
+
test_files: []
|
76
|
+
|
data/spec/gitswitch_spec.rb
DELETED