gas 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +4 -0
- data/bin/gas +5 -0
- data/lib/gas/gitconfig.rb +30 -4
- data/lib/gas/version.rb +1 -1
- data/lib/gas.rb +26 -2
- data/spec/gas/gitconfig_spec.rb +27 -0
- metadata +8 -8
data/README.textile
CHANGED
@@ -28,6 +28,10 @@ bc. $ gas list
|
|
28
28
|
|
29
29
|
This lists the authors that are set up.
|
30
30
|
|
31
|
+
You can import your current user by giving it a nickname
|
32
|
+
|
33
|
+
bc. $ gas import current_user
|
34
|
+
|
31
35
|
To add a author use, add
|
32
36
|
|
33
37
|
bc. $ gas add walle "Fredrik Wallgren" fredrik.wallgren@gmail.com
|
data/bin/gas
CHANGED
@@ -27,6 +27,11 @@ class GasRunner < Thor
|
|
27
27
|
Gas.add nickname, name, email
|
28
28
|
end
|
29
29
|
|
30
|
+
desc "import NICKNAME", "Imports current user to gasconfig"
|
31
|
+
def import(nickname)
|
32
|
+
Gas.import nickname
|
33
|
+
end
|
34
|
+
|
30
35
|
desc "delete AUTHOR", "Deletes author"
|
31
36
|
def delete(nickname)
|
32
37
|
Gas.delete nickname
|
data/lib/gas/gitconfig.rb
CHANGED
@@ -9,7 +9,7 @@ module Gas
|
|
9
9
|
|
10
10
|
if gitconfig.nil? && File.exists?(@gitconfig_file)
|
11
11
|
@gitconfig = File.read(@gitconfig_file)
|
12
|
-
|
12
|
+
elsif !gitconfig.nil?
|
13
13
|
@gitconfig = gitconfig
|
14
14
|
end
|
15
15
|
end
|
@@ -17,11 +17,13 @@ module Gas
|
|
17
17
|
# Parse out the current user from the gitconfig
|
18
18
|
# TODO: Error handling
|
19
19
|
# @param [String] gitconfig The git configuration
|
20
|
-
# @return [User] The current user
|
20
|
+
# @return [User] The current user or nil if not present
|
21
21
|
def current_user
|
22
22
|
regex = /\[user\]\s+name = (.+)\s+email = (.+)/
|
23
23
|
matches = regex.match @gitconfig
|
24
24
|
|
25
|
+
return nil if matches.nil?
|
26
|
+
|
25
27
|
User.new matches[1], matches[2]
|
26
28
|
end
|
27
29
|
|
@@ -29,8 +31,32 @@ module Gas
|
|
29
31
|
# @param [String] name The new name
|
30
32
|
# @param [String] email The new email
|
31
33
|
def change_user(name, email)
|
32
|
-
|
33
|
-
|
34
|
+
if current_user_present?
|
35
|
+
@gitconfig.gsub! /^\s*name\s?=\s?.+/, " name = #{name}"
|
36
|
+
@gitconfig.gsub! /^\s*email\s?=\s?.+/, " email = #{email}"
|
37
|
+
else
|
38
|
+
create_user(name, email)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Create a user section
|
43
|
+
# @param [String] name The new name
|
44
|
+
# @param [String] email The new email
|
45
|
+
def create_user(name, email)
|
46
|
+
return if current_user_present?
|
47
|
+
|
48
|
+
@gitconfig << <<-EOS
|
49
|
+
|
50
|
+
# Those lines are added by gas, feel free to change them.
|
51
|
+
[user]
|
52
|
+
name = #{name}
|
53
|
+
email = #{email}
|
54
|
+
EOS
|
55
|
+
end
|
56
|
+
|
57
|
+
# Check if user section is present in gitconfig
|
58
|
+
def current_user_present?
|
59
|
+
!current_user.nil?
|
34
60
|
end
|
35
61
|
|
36
62
|
# Saves the gitconfig
|
data/lib/gas/version.rb
CHANGED
data/lib/gas.rb
CHANGED
@@ -19,8 +19,13 @@ module Gas
|
|
19
19
|
# Shows the current user
|
20
20
|
def self.show
|
21
21
|
user = @gitconfig.current_user
|
22
|
-
|
23
|
-
|
22
|
+
|
23
|
+
if user
|
24
|
+
puts 'Current user:'
|
25
|
+
puts "#{user.name} <#{user.email}>"
|
26
|
+
else
|
27
|
+
puts 'No current user in gitconfig'
|
28
|
+
end
|
24
29
|
end
|
25
30
|
|
26
31
|
# Sets _nickname_ as current user
|
@@ -49,6 +54,25 @@ module Gas
|
|
49
54
|
puts user
|
50
55
|
end
|
51
56
|
|
57
|
+
# Imports current user from .gitconfig to .gas
|
58
|
+
# @param [String] nickname The nickname to give to the new user
|
59
|
+
def self.import(nickname)
|
60
|
+
self.has_user? nickname
|
61
|
+
user = @gitconfig.current_user
|
62
|
+
|
63
|
+
if user
|
64
|
+
user = User.new user.name, user.email, nickname
|
65
|
+
|
66
|
+
@config.add user
|
67
|
+
@config.save!
|
68
|
+
|
69
|
+
puts 'Added author'
|
70
|
+
puts user
|
71
|
+
else
|
72
|
+
puts 'No current user to import'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
52
76
|
# Deletes a author from the config using nickname
|
53
77
|
# @param [String] nickname The nickname of the author
|
54
78
|
def self.delete(nickname)
|
data/spec/gas/gitconfig_spec.rb
CHANGED
@@ -9,6 +9,7 @@ describe Gas::Gitconfig do
|
|
9
9
|
@email = 'fredrik.wallgren@gmail.com'
|
10
10
|
gitconfig = "[other stuff]\n foo = bar\n\n[user]\n name = #{@name}\n email = #{@email}\n\n[foo]\n bar = foo"
|
11
11
|
@gitconfig = Gas::Gitconfig.new gitconfig
|
12
|
+
@empty_gitconfig = Gas::Gitconfig.new ''
|
12
13
|
end
|
13
14
|
|
14
15
|
it 'should be able to get current user from gitconfig' do
|
@@ -17,6 +18,10 @@ describe Gas::Gitconfig do
|
|
17
18
|
user.email.should == @email
|
18
19
|
end
|
19
20
|
|
21
|
+
it 'should return nil if no current user is present in gitconfig' do
|
22
|
+
@empty_gitconfig.current_user.should == nil
|
23
|
+
end
|
24
|
+
|
20
25
|
it 'should be able to change the current user' do
|
21
26
|
name = 'Test Testsson'
|
22
27
|
email = 'test@testsson.com'
|
@@ -26,4 +31,26 @@ describe Gas::Gitconfig do
|
|
26
31
|
user.name.should == name
|
27
32
|
user.email.should == email
|
28
33
|
end
|
34
|
+
|
35
|
+
it 'should add a new user if no user section exists in gitconfig' do
|
36
|
+
name = 'Test Testsson'
|
37
|
+
email = 'test@testsson.com'
|
38
|
+
@empty_gitconfig.change_user name, email
|
39
|
+
|
40
|
+
user = @empty_gitconfig.current_user
|
41
|
+
user.name.should == name
|
42
|
+
user.email.should == email
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should not blow up if no gitconfig exists (use empty string instead)' do
|
46
|
+
# Stub out File#exists?
|
47
|
+
class File
|
48
|
+
def self.exists?(path)
|
49
|
+
false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
gitconfig_file_absent = Gas::Gitconfig.new
|
54
|
+
gitconfig_file_absent.instance_variable_get(:@gitconfig).should == ''
|
55
|
+
end
|
29
56
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-07-
|
12
|
+
date: 2011-07-23 00:00:00.000000000 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: thor
|
17
|
-
requirement: &
|
17
|
+
requirement: &12746540 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 0.14.6
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *12746540
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rspec
|
28
|
-
requirement: &
|
28
|
+
requirement: &12746120 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *12746120
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bundler
|
39
|
-
requirement: &
|
39
|
+
requirement: &12745660 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *12745660
|
48
48
|
description: Gas is a utility to keep track of your git authors. Add them to gas and
|
49
49
|
switch at any time. Great if you use one author at work and one at home for instance.
|
50
50
|
email: fredrik.wallgren@gmail.com
|