gitswitch 0.1.1 → 0.1.2
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.
- data/README.rdoc +3 -3
- data/Rakefile +16 -24
- data/VERSION +1 -1
- data/gitswitch.gemspec +4 -9
- data/lib/gitswitch.rb +45 -26
- data/spec/gitswitch_spec.rb +7 -0
- data/spec/spec_helper.rb +5 -0
- metadata +9 -22
- data/test/helper.rb +0 -10
- data/test/test_gitswitch.rb +0 -9
data/README.rdoc
CHANGED
@@ -16,9 +16,9 @@ Simply run the script to establish a default ~/.gitswitch file using the git inf
|
|
16
16
|
Add a new git user tag
|
17
17
|
gitswitch -a
|
18
18
|
|
19
|
-
Set specific user info to your current git repository
|
20
|
-
gitswitch -r work
|
21
|
-
gitswitch -r
|
19
|
+
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
|
+
gitswitch -r # User info from your 'default' tag is used if you don't specify a tag
|
22
22
|
|
23
23
|
List all the gitswitch user tags/info you have stored
|
24
24
|
gitswitch -l
|
data/Rakefile
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
|
+
# require 'rspec/core'
|
4
|
+
# require 'rspec/core/rake_task'
|
5
|
+
|
3
6
|
|
4
7
|
begin
|
5
8
|
require 'jeweler'
|
@@ -10,7 +13,8 @@ begin
|
|
10
13
|
gem.email = "joe@joealba.com"
|
11
14
|
gem.homepage = "http://github.com/joealba/gitswitch"
|
12
15
|
gem.authors = ["Joe Alba"]
|
13
|
-
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
16
|
+
# gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
17
|
+
# gem.add_development_dependency "rspec", ">= 0"
|
14
18
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
19
|
end
|
16
20
|
Jeweler::GemcutterTasks.new
|
@@ -18,29 +22,6 @@ rescue LoadError
|
|
18
22
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
23
|
end
|
20
24
|
|
21
|
-
require 'rake/testtask'
|
22
|
-
Rake::TestTask.new(:test) do |test|
|
23
|
-
test.libs << 'lib' << 'test'
|
24
|
-
test.pattern = 'test/**/test_*.rb'
|
25
|
-
test.verbose = true
|
26
|
-
end
|
27
|
-
|
28
|
-
begin
|
29
|
-
require 'rcov/rcovtask'
|
30
|
-
Rcov::RcovTask.new do |test|
|
31
|
-
test.libs << 'test'
|
32
|
-
test.pattern = 'test/**/test_*.rb'
|
33
|
-
test.verbose = true
|
34
|
-
end
|
35
|
-
rescue LoadError
|
36
|
-
task :rcov do
|
37
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
task :test => :check_dependencies
|
42
|
-
|
43
|
-
task :default => :test
|
44
25
|
|
45
26
|
require 'rake/rdoctask'
|
46
27
|
Rake::RDocTask.new do |rdoc|
|
@@ -51,3 +32,14 @@ Rake::RDocTask.new do |rdoc|
|
|
51
32
|
rdoc.rdoc_files.include('README*')
|
52
33
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
34
|
end
|
35
|
+
|
36
|
+
|
37
|
+
# desc 'Default: Run specs'
|
38
|
+
# task :default => :spec
|
39
|
+
#
|
40
|
+
# desc 'Run specs'
|
41
|
+
# RSpec::Core::RakeTask.new(:spec) do |t|
|
42
|
+
# t.pattern = FileList["spec/**/*_spec.rb"]
|
43
|
+
# end
|
44
|
+
|
45
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/gitswitch.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
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.2"
|
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"]
|
@@ -27,9 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"VERSION",
|
28
28
|
"bin/gitswitch",
|
29
29
|
"gitswitch.gemspec",
|
30
|
-
"lib/gitswitch.rb"
|
31
|
-
"test/helper.rb",
|
32
|
-
"test/test_gitswitch.rb"
|
30
|
+
"lib/gitswitch.rb"
|
33
31
|
]
|
34
32
|
s.homepage = %q{http://github.com/joealba/gitswitch}
|
35
33
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -37,8 +35,8 @@ Gem::Specification.new do |s|
|
|
37
35
|
s.rubygems_version = %q{1.3.7}
|
38
36
|
s.summary = %q{Easy git user switching}
|
39
37
|
s.test_files = [
|
40
|
-
"
|
41
|
-
"
|
38
|
+
"spec/gitswitch_spec.rb",
|
39
|
+
"spec/spec_helper.rb"
|
42
40
|
]
|
43
41
|
|
44
42
|
if s.respond_to? :specification_version then
|
@@ -46,12 +44,9 @@ Gem::Specification.new do |s|
|
|
46
44
|
s.specification_version = 3
|
47
45
|
|
48
46
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
-
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
50
47
|
else
|
51
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
52
48
|
end
|
53
49
|
else
|
54
|
-
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
55
50
|
end
|
56
51
|
end
|
57
52
|
|
data/lib/gitswitch.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'optparse'
|
2
|
+
require 'yaml'
|
3
|
+
#require 'escape'
|
3
4
|
|
4
5
|
class GitSwitch
|
5
6
|
VERSION_FILE = File.join File.dirname(__FILE__), "..", "VERSION.yml"
|
@@ -26,7 +27,6 @@ class GitSwitch
|
|
26
27
|
puts "Ok, that's fine. Exiting." and exit
|
27
28
|
end
|
28
29
|
end
|
29
|
-
|
30
30
|
end
|
31
31
|
|
32
32
|
|
@@ -63,7 +63,7 @@ class GitSwitch
|
|
63
63
|
puts parser and exit
|
64
64
|
end
|
65
65
|
|
66
|
-
o.on "-o", "--overwrite", "Overwrite/create a .gitswitch file using your
|
66
|
+
o.on "-o", "--overwrite", "Overwrite/create a .gitswitch file using your global git user info as default" do
|
67
67
|
create_gitswitch_file
|
68
68
|
print_info and exit
|
69
69
|
end
|
@@ -77,7 +77,6 @@ class GitSwitch
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
|
81
80
|
begin
|
82
81
|
parser.parse! args
|
83
82
|
rescue OptionParser::InvalidOption => error
|
@@ -91,12 +90,12 @@ class GitSwitch
|
|
91
90
|
|
92
91
|
# Create a .gitswitch file with the current user defaults
|
93
92
|
def create_gitswitch_file
|
94
|
-
|
95
|
-
if
|
93
|
+
user = get_global_git_user
|
94
|
+
if user[:name].empty? && user[:email].empty?
|
96
95
|
puts "ERROR: You must set up a default git user.name and user.email first."
|
97
96
|
else
|
98
|
-
puts "Adding your
|
99
|
-
set_gitswitch_entry('default',
|
97
|
+
puts "Adding your global git user info to the \"default\" tag..."
|
98
|
+
set_gitswitch_entry('default', user[:email], user[:name])
|
100
99
|
save_gitswitch_file
|
101
100
|
end
|
102
101
|
end
|
@@ -122,18 +121,32 @@ class GitSwitch
|
|
122
121
|
save_gitswitch_file
|
123
122
|
end
|
124
123
|
|
124
|
+
|
125
|
+
def get_user(tag)
|
126
|
+
if @users.empty? || @users[tag].empty? || @users[tag][:email].to_s.empty?
|
127
|
+
return false
|
128
|
+
end
|
129
|
+
@users[tag]
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
def git_config(user, args = {})
|
134
|
+
git_args = 'config --replace-all'
|
135
|
+
git_args += ' --global' if args[:global]
|
136
|
+
|
137
|
+
%x(#{GIT_BIN} #{git_args} user.email #{user[:email].to_s.shellescape})
|
138
|
+
%x(#{GIT_BIN} #{git_args} user.name #{user[:name].to_s.shellescape}) if !user[:name].to_s.empty?
|
139
|
+
end
|
140
|
+
|
125
141
|
|
126
142
|
# Switch git user in your global .gitconfig file
|
127
143
|
# ==== Parameters
|
128
144
|
# * +tag+ - The tag associated with your desired git info in .gitswitch. Defaults to "default".
|
129
145
|
def switch_global_user tag = "default"
|
146
|
+
user = get_user(tag) or raise "ERROR: Could not find info for tag \"#{tag}\" in your .gitswitch file"
|
130
147
|
puts "Switching git user to \"#{tag}\" tag..."
|
131
|
-
|
132
|
-
|
133
|
-
%x(#{GIT_BIN} config --replace-all --global user.email '#{@users[tag][:email]}')
|
134
|
-
else
|
135
|
-
puts "ERROR: Could not find info for tag #{tag} in your .gitswitch file"
|
136
|
-
end
|
148
|
+
git_config(user, {:global => true})
|
149
|
+
# puts "ERROR: Could not find info for tag \"#{tag}\" in your .gitswitch file"
|
137
150
|
end
|
138
151
|
|
139
152
|
|
@@ -141,28 +154,25 @@ class GitSwitch
|
|
141
154
|
# ==== Parameters
|
142
155
|
# * +tag+ - The tag associated with your desired git info in .gitswitch. Defaults to "default".
|
143
156
|
def switch_repo_user tag = "default"
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
else
|
149
|
-
puts "ERROR: Could not find info for tag #{tag} in your .gitswitch file"
|
150
|
-
end
|
157
|
+
user = get_user(tag) or raise "ERROR: Could not find info for tag \"#{tag}\" in your .gitswitch file"
|
158
|
+
puts "Switching git user to \"#{tag}\" tag for the current repository..."
|
159
|
+
git_config(user) or raise "Could not set your repo"
|
160
|
+
# puts "ERROR: Could not find info for tag \"#{tag}\" in your .gitswitch file"
|
151
161
|
end
|
152
162
|
|
153
163
|
|
154
164
|
# Add a user entry to your .gitswitch file
|
155
165
|
def add_gitswitch_entry
|
156
166
|
print "What tag would you like to set to this git user? "
|
157
|
-
tag = gets.
|
167
|
+
tag = gets.gsub(/\W+/,'')
|
158
168
|
|
159
169
|
print "E-mail address: "
|
160
170
|
email = gets.chomp
|
161
171
|
|
162
|
-
print "Name: (ENTER to use \"" +
|
172
|
+
print "Name: (ENTER to use \"" + get_global_git_user()[:name] + "\") "
|
163
173
|
name = gets.chomp
|
164
174
|
if name.empty?
|
165
|
-
name =
|
175
|
+
name = get_global_git_user()[:name]
|
166
176
|
end
|
167
177
|
set_gitswitch_entry(tag, email, name)
|
168
178
|
end
|
@@ -203,10 +213,19 @@ class GitSwitch
|
|
203
213
|
|
204
214
|
# Show the current git user info
|
205
215
|
def get_current_git_user
|
206
|
-
|
216
|
+
{
|
207
217
|
:name => %x(#{GIT_BIN} config --get user.name).to_s.chomp,
|
208
218
|
:email => %x(#{GIT_BIN} config --get user.email).to_s.chomp
|
209
219
|
}
|
210
220
|
end
|
221
|
+
|
222
|
+
# Show the global config git user info
|
223
|
+
def get_global_git_user
|
224
|
+
{
|
225
|
+
:name => %x(#{GIT_BIN} config --global --get user.name).to_s.chomp,
|
226
|
+
:email => %x(#{GIT_BIN} config --global --get user.email).to_s.chomp
|
227
|
+
}
|
228
|
+
end
|
229
|
+
|
211
230
|
|
212
231
|
end
|
data/spec/spec_helper.rb
ADDED
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: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joe Alba
|
@@ -17,21 +17,8 @@ cert_chain: []
|
|
17
17
|
|
18
18
|
date: 2010-09-04 00:00:00 -04:00
|
19
19
|
default_executable: gitswitch
|
20
|
-
dependencies:
|
21
|
-
|
22
|
-
name: thoughtbot-shoulda
|
23
|
-
prerelease: false
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
33
|
-
type: :development
|
34
|
-
version_requirements: *id001
|
20
|
+
dependencies: []
|
21
|
+
|
35
22
|
description: 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.
|
36
23
|
email: joe@joealba.com
|
37
24
|
executables:
|
@@ -51,8 +38,8 @@ files:
|
|
51
38
|
- bin/gitswitch
|
52
39
|
- gitswitch.gemspec
|
53
40
|
- lib/gitswitch.rb
|
54
|
-
-
|
55
|
-
-
|
41
|
+
- spec/gitswitch_spec.rb
|
42
|
+
- spec/spec_helper.rb
|
56
43
|
has_rdoc: true
|
57
44
|
homepage: http://github.com/joealba/gitswitch
|
58
45
|
licenses: []
|
@@ -88,5 +75,5 @@ signing_key:
|
|
88
75
|
specification_version: 3
|
89
76
|
summary: Easy git user switching
|
90
77
|
test_files:
|
91
|
-
-
|
92
|
-
-
|
78
|
+
- spec/gitswitch_spec.rb
|
79
|
+
- spec/spec_helper.rb
|
data/test/helper.rb
DELETED
data/test/test_gitswitch.rb
DELETED