ppgit 0.1.0
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/.document +5 -0
- data/.gitignore +21 -0
- data/CHANGELOG +2 -0
- data/LICENSE +20 -0
- data/README.markdown +91 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/bin/ppgit +39 -0
- data/lib/ppgit/usage.txt +66 -0
- data/lib/ppgit/utils.rb +51 -0
- data/lib/ppgit.rb +0 -0
- data/ppgit.gemspec +67 -0
- data/spec/ppgit_clear_spec.rb +49 -0
- data/spec/ppgit_email_root_spec.rb +66 -0
- data/spec/ppgit_spec.rb +117 -0
- data/spec/ppgit_usage_spec.rb +8 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +49 -0
- metadata +104 -0
data/.document
ADDED
data/.gitignore
ADDED
data/CHANGELOG
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Alain Ravet
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
[ppgit](http://rubygems.org/gems/ppgit)
|
2
|
+
=======
|
3
|
+
|
4
|
+
For Git-friendly Pair-Programming sessions.
|
5
|
+
Sign your commits with your pair 2-part name and email : andy\_john / andy\_john@acme.com
|
6
|
+
When you're done, restore your local git config in a snap.
|
7
|
+
|
8
|
+
Quick Usage :
|
9
|
+
-------------
|
10
|
+
|
11
|
+
$ ppgit john andy
|
12
|
+
$ ppgit john andy andy_john@acme.com
|
13
|
+
$ ppgit clear
|
14
|
+
$ ppgit --email_root *@acme.com
|
15
|
+
|
16
|
+
|
17
|
+
Usage :
|
18
|
+
-------
|
19
|
+
|
20
|
+
#### 1 - When the pairing session starts, quickly set user.name and user.email to the pair values :
|
21
|
+
|
22
|
+
$ ppgit john andy andy_john@mycompany.com
|
23
|
+
|
24
|
+
=> this will update ~/.gitconfig to
|
25
|
+
|
26
|
+
[user]
|
27
|
+
name = andy_john
|
28
|
+
email = andy_john@mycompany.com
|
29
|
+
[user-before-ppgit]
|
30
|
+
name = Your Name
|
31
|
+
email = your_email@address.com
|
32
|
+
|
33
|
+
|
34
|
+
#### 2 - When the session is finished, restore ~/.gitconfig to your original local values :
|
35
|
+
|
36
|
+
$ ppgit clear
|
37
|
+
|
38
|
+
=> will restore your ~/.gitconfig to :
|
39
|
+
|
40
|
+
[user]
|
41
|
+
name = Your Name
|
42
|
+
email = your_email@address.com
|
43
|
+
|
44
|
+
#### 3 - If your team pairs share a common email pattern (ex: ann_bob@acme.com, cid_dan@acme.com), you can specify it once and for all :
|
45
|
+
|
46
|
+
$ ppgit --email_root *@acme.com
|
47
|
+
|
48
|
+
=> you can now use the short syntax :
|
49
|
+
|
50
|
+
$ ppgit bob al
|
51
|
+
$ ppgit dan cid
|
52
|
+
|
53
|
+
are now equivalent to :
|
54
|
+
|
55
|
+
$ ppgit bob al al_bob@acme.com
|
56
|
+
$ ppgit dan cid cid_dan@acme.com
|
57
|
+
|
58
|
+
|
59
|
+
#### Tip : use 1 gmail address + n aliases, so you can choose 1 unique gravatar for each pair :
|
60
|
+
|
61
|
+
$ ppgit --email_root mycompany+*@gmail.com
|
62
|
+
|
63
|
+
=> you'll get
|
64
|
+
mycompany+ann_bob@gmail.com
|
65
|
+
mycompany+bob_cid@gmail.com
|
66
|
+
etc..
|
67
|
+
for free, and each can have a unique gravatar.
|
68
|
+
|
69
|
+
|
70
|
+
#### Installation :
|
71
|
+
|
72
|
+
$ gem install ppgit
|
73
|
+
|
74
|
+
#### Report bugs to <http://github.com/alainravet/ppgit/>
|
75
|
+
|
76
|
+
--------------------------------------------------------------------------------
|
77
|
+
|
78
|
+
== Note on Patches/Pull Requests
|
79
|
+
|
80
|
+
* Fork the project.
|
81
|
+
* Make your feature addition or bug fix.
|
82
|
+
* Add tests for it. This is important so I don't break it in a
|
83
|
+
future version unintentionally.
|
84
|
+
* Commit, do not mess with rakefile, version, or history.
|
85
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
86
|
+
* Send me a pull request. Bonus points for topic branches.
|
87
|
+
|
88
|
+
== Copyright
|
89
|
+
|
90
|
+
Copyright (c) 2010 Alain Ravet. See LICENSE for details.
|
91
|
+
·
|
data/Rakefile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "ppgit"
|
8
|
+
gem.summary = %Q{git users' pairs switcher}
|
9
|
+
gem.description = %Q{git users' pairs switcher}
|
10
|
+
gem.email = "alain.ravet+git@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/alainravet/ppgit"
|
12
|
+
gem.authors = ["Alain Ravet"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "ppgit #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/ppgit
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib' ))
|
4
|
+
require 'ppgit/utils'
|
5
|
+
|
6
|
+
if 0 == ARGV.length
|
7
|
+
puts usage_message()
|
8
|
+
else
|
9
|
+
# for testing, we pass an explicit - temporary - config file.
|
10
|
+
file_part = argv_value_of('--file')
|
11
|
+
file_part &&= "--file #{file_part}"
|
12
|
+
PPGIT_FILE_PART = file_part
|
13
|
+
|
14
|
+
if emailroot = argv_value_of('--email_root')
|
15
|
+
set_git_value 'ppgit.emailroot' , emailroot
|
16
|
+
end
|
17
|
+
|
18
|
+
if ARGV == %w(clear)
|
19
|
+
restore_git_value :from => 'user-before-ppgit.name' , :to => 'user.name'
|
20
|
+
restore_git_value :from => 'user-before-ppgit.email', :to => 'user.email'
|
21
|
+
`git config #{file_part} --remove-section user-before-ppgit`
|
22
|
+
|
23
|
+
elsif [2,3].include?(ARGV.length)
|
24
|
+
|
25
|
+
backup_git_value :from => 'user.name' , :to => 'user-before-ppgit.name'
|
26
|
+
backup_git_value :from => 'user.email', :to => 'user-before-ppgit.email'
|
27
|
+
|
28
|
+
two_users = [ARGV[0], ARGV[1]]
|
29
|
+
pair_user = two_users.sort.join('_')
|
30
|
+
|
31
|
+
pair_email = ARGV[2]
|
32
|
+
pair_email ||= email_from_email_root_and_user(pair_user)
|
33
|
+
|
34
|
+
set_git_value 'user.name' , pair_user
|
35
|
+
if pair_email
|
36
|
+
set_git_value 'user.email' , pair_email
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/ppgit/usage.txt
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
--------------------------------------------------------------------------------
|
4
|
+
ppgit : quickly update ~/.gitconfig for pair-programming sessions.
|
5
|
+
--------------------------------------------------------------------------------
|
6
|
+
|
7
|
+
Quick Usage:
|
8
|
+
|
9
|
+
$ ppgit john andy
|
10
|
+
$ ppgit john andy andy_john@acme.com
|
11
|
+
$ ppgit clear
|
12
|
+
$ ppgit --email_root *@acme.com
|
13
|
+
|
14
|
+
|
15
|
+
Usage:
|
16
|
+
|
17
|
+
1 - When the pairing session starts, quickly set user.name and user.email to the pair values:
|
18
|
+
|
19
|
+
$ ppgit john andy andy_john@mycompany.com
|
20
|
+
|
21
|
+
=> will update ~/.gitconfig to
|
22
|
+
|
23
|
+
[user]
|
24
|
+
name = andy_john
|
25
|
+
email = andy_john@mycompany.com
|
26
|
+
|
27
|
+
|
28
|
+
2 - When the session is finished, restore ~/.gitconfig to your original local values :
|
29
|
+
|
30
|
+
$ ppgit clear
|
31
|
+
|
32
|
+
=> will restore ~/.gitconfig to (f.ex) :
|
33
|
+
|
34
|
+
[user]
|
35
|
+
name = Your Name
|
36
|
+
email = your_email@address.com
|
37
|
+
|
38
|
+
|
39
|
+
3 - If your teams pairs share a common email pattern
|
40
|
+
(ex: ann_bob@acme.com, cid_dan@acme.com),
|
41
|
+
, you can specify it once and for all :
|
42
|
+
|
43
|
+
$ ppgit --email_root *@acme.com
|
44
|
+
|
45
|
+
=>
|
46
|
+
$ ppgit bob al
|
47
|
+
$ ppgit dan cid
|
48
|
+
are now the same as
|
49
|
+
$ ppgit bob al al_bob@acme.com
|
50
|
+
$ ppgit dan cid cid_dan@acme.com
|
51
|
+
|
52
|
+
Tip : use 1 gmail address + n aliases, so you can choose 1 unique gravatar for each pair :
|
53
|
+
$ ppgit --email_root mycompany+*@gmail.com
|
54
|
+
=> you'll get
|
55
|
+
mycompany+ann_bob@gmail.com
|
56
|
+
mycompany+bob_cid@gmail.com
|
57
|
+
etc..
|
58
|
+
for free
|
59
|
+
|
60
|
+
Installation :
|
61
|
+
|
62
|
+
$ gem install ppgit
|
63
|
+
|
64
|
+
Report bugs to http://github.com/alainravet/ppgit
|
65
|
+
--------------------------------------------------------------------------------
|
66
|
+
|
data/lib/ppgit/utils.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
def blank?(string_or_nil)
|
2
|
+
string_or_nil.nil? || '' == string_or_nil.strip
|
3
|
+
end
|
4
|
+
|
5
|
+
|
6
|
+
def get_git_value(key)
|
7
|
+
value = (`git config #{PPGIT_FILE_PART} --get #{key}`).chomp
|
8
|
+
value
|
9
|
+
end
|
10
|
+
|
11
|
+
def set_git_value(key, value)
|
12
|
+
`git config #{PPGIT_FILE_PART} #{key} '#{value}'`
|
13
|
+
end
|
14
|
+
|
15
|
+
def argv_value_of(prefix)
|
16
|
+
if (idx = ARGV.index(prefix))
|
17
|
+
ARGV.delete_at(idx) # ex: remove '--files'
|
18
|
+
the_value = ARGV.delete_at(idx)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def backup_git_value(options)
|
23
|
+
source, target = options[:from], options[:to]
|
24
|
+
|
25
|
+
target_already_occupied = !blank?(get_git_value(target))
|
26
|
+
nothing_to_backup = blank?(get_git_value(source))
|
27
|
+
|
28
|
+
return if target_already_occupied || nothing_to_backup
|
29
|
+
set_git_value(target, get_git_value(source))
|
30
|
+
end
|
31
|
+
|
32
|
+
def restore_git_value(options)
|
33
|
+
source, target = options[:from], options[:to]
|
34
|
+
|
35
|
+
nothing_to_restore = blank?(get_git_value(source))
|
36
|
+
return if nothing_to_restore
|
37
|
+
set_git_value(target, get_git_value(source))
|
38
|
+
end
|
39
|
+
|
40
|
+
def email_from_email_root_and_user(pair_user)
|
41
|
+
emailroot = get_git_value('ppgit.emailroot')
|
42
|
+
blank?(emailroot) ?
|
43
|
+
nil :
|
44
|
+
emailroot.gsub('*', pair_user)
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def usage_message
|
49
|
+
path = File.expand_path(File.join(File.dirname(__FILE__), 'usage.txt'))
|
50
|
+
File.open(path).read
|
51
|
+
end
|
data/lib/ppgit.rb
ADDED
File without changes
|
data/ppgit.gemspec
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{ppgit}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Alain Ravet"]
|
12
|
+
s.date = %q{2010-07-21}
|
13
|
+
s.default_executable = %q{ppgit}
|
14
|
+
s.description = %q{git users' pairs switcher}
|
15
|
+
s.email = %q{alain.ravet+git@gmail.com}
|
16
|
+
s.executables = ["ppgit"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.markdown"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"CHANGELOG",
|
25
|
+
"LICENSE",
|
26
|
+
"README.markdown",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"bin/ppgit",
|
30
|
+
"lib/ppgit.rb",
|
31
|
+
"lib/ppgit/usage.txt",
|
32
|
+
"lib/ppgit/utils.rb",
|
33
|
+
"ppgit.gemspec",
|
34
|
+
"spec/ppgit_clear_spec.rb",
|
35
|
+
"spec/ppgit_email_root_spec.rb",
|
36
|
+
"spec/ppgit_spec.rb",
|
37
|
+
"spec/ppgit_usage_spec.rb",
|
38
|
+
"spec/spec.opts",
|
39
|
+
"spec/spec_helper.rb"
|
40
|
+
]
|
41
|
+
s.homepage = %q{http://github.com/alainravet/ppgit}
|
42
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
43
|
+
s.require_paths = ["lib"]
|
44
|
+
s.rubygems_version = %q{1.3.7}
|
45
|
+
s.summary = %q{git users' pairs switcher}
|
46
|
+
s.test_files = [
|
47
|
+
"spec/ppgit_clear_spec.rb",
|
48
|
+
"spec/ppgit_email_root_spec.rb",
|
49
|
+
"spec/ppgit_spec.rb",
|
50
|
+
"spec/ppgit_usage_spec.rb",
|
51
|
+
"spec/spec_helper.rb"
|
52
|
+
]
|
53
|
+
|
54
|
+
if s.respond_to? :specification_version then
|
55
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
56
|
+
s.specification_version = 3
|
57
|
+
|
58
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
59
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "`ppgit clear`" do
|
4
|
+
before(:all) do
|
5
|
+
@cmd = "#{PPGIT_CMD} clear"
|
6
|
+
end
|
7
|
+
|
8
|
+
example 'when there is no user name nor email nor ppgit.email.root in the config' do
|
9
|
+
before = [ '[a]' ]
|
10
|
+
expected = before
|
11
|
+
check_command_result(@cmd, before, expected)
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
example 'when there is a user.name and a user.email but no backed-up values' do
|
16
|
+
before = [ '[user]' ,
|
17
|
+
' name = Alain Ravet' ,
|
18
|
+
' email = alainravet@gmail.com' ]
|
19
|
+
expected = before
|
20
|
+
|
21
|
+
check_command_result(@cmd, before, expected)
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
example 'when there is a user.name + email AND stored values in user-before-ppgit' do
|
26
|
+
before = [ '[user]' ,
|
27
|
+
' name = andy_john' , # value to replace
|
28
|
+
' email = andy_john@test.com' , # ..
|
29
|
+
|
30
|
+
'[user-before-ppgit]' , # section to erase
|
31
|
+
' name = Alain Ravet' , # value to restore
|
32
|
+
' email = alainravet@gmail.com' ] # ..
|
33
|
+
|
34
|
+
expected = [ '[user]' ,
|
35
|
+
' name = Alain Ravet' , # restored value
|
36
|
+
' email = alainravet@gmail.com'] # ..
|
37
|
+
|
38
|
+
check_command_result(@cmd, before, expected)
|
39
|
+
end
|
40
|
+
|
41
|
+
example 'when there is an emailroot : the emailroot is not cleared' do
|
42
|
+
before = [ '[ppgit]' ,
|
43
|
+
' emailroot = old+*@gmail.com' ]
|
44
|
+
expected = before
|
45
|
+
|
46
|
+
check_command_result(@cmd, before, expected)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "`ppgit --email_root acme+*@gmail.com`" do
|
4
|
+
before(:all) do
|
5
|
+
@cmd = "#{PPGIT_CMD} --email_root acme+*@gmail.com"
|
6
|
+
end
|
7
|
+
|
8
|
+
example 'when there is no emailroot yet' do
|
9
|
+
before = [ '[a]' ]
|
10
|
+
|
11
|
+
expected = [ '[a]' ,
|
12
|
+
'[ppgit]' ,
|
13
|
+
' emailroot = acme+*@gmail.com' ]
|
14
|
+
check_command_result(@cmd, before, expected)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
example 'when there is an emailroot' do
|
19
|
+
before = [ '[ppgit]' ,
|
20
|
+
' emailroot = old+*@gmail.com' ]
|
21
|
+
expected = [ '[ppgit]' ,
|
22
|
+
' emailroot = acme+*@gmail.com' ]
|
23
|
+
|
24
|
+
check_command_result(@cmd, before, expected)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "`ppgit john andy --email_root acme+*@gmail.com`" do
|
29
|
+
before(:all) do
|
30
|
+
@cmd = "#{PPGIT_CMD} john andy --email_root acme+*@gmail.com"
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'generates an email for the pair from the root AND stores the email_root' do
|
34
|
+
before = [ '[z]' ]
|
35
|
+
|
36
|
+
expected = [ '[z]' ,
|
37
|
+
'[ppgit]' ,
|
38
|
+
' emailroot = acme+*@gmail.com' ,
|
39
|
+
'[user]' ,
|
40
|
+
' name = andy_john' ,
|
41
|
+
' email = acme+andy_john@gmail.com' ,
|
42
|
+
]
|
43
|
+
|
44
|
+
check_command_result(@cmd, before, expected)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "`ppgit john andy andy_john@test.com --email_root acme+*@gmail.com`" do
|
49
|
+
before(:all) do
|
50
|
+
@cmd = "#{PPGIT_CMD} john andy andy_john@test.com --email_root acme+*@gmail.com"
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'stores the email_root BUT uses the explicit pair email address' do
|
54
|
+
before = [ '[z]' ]
|
55
|
+
|
56
|
+
expected = [ '[z]' ,
|
57
|
+
'[ppgit]' ,
|
58
|
+
' emailroot = acme+*@gmail.com' ,
|
59
|
+
'[user]' ,
|
60
|
+
' name = andy_john' ,
|
61
|
+
' email = andy_john@test.com' ,
|
62
|
+
]
|
63
|
+
|
64
|
+
check_command_result(@cmd, before, expected)
|
65
|
+
end
|
66
|
+
end
|
data/spec/ppgit_spec.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "`ppgit john andy`" do
|
4
|
+
|
5
|
+
context 'when there is no user name nor email nor ppgit.email.root in the config' do
|
6
|
+
before = [ '[a]' ]
|
7
|
+
|
8
|
+
it "combines the names alphabetically and stores them a the new user.name" do
|
9
|
+
expected = [ '[a]' ,
|
10
|
+
'[user]' ,
|
11
|
+
' name = andy_john' ]
|
12
|
+
|
13
|
+
cmd = "#{PPGIT_CMD} john andy"
|
14
|
+
check_command_result(cmd, before, expected)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "uses the 3rd parameter as new user.email" do
|
18
|
+
expected = [ '[a]' ,
|
19
|
+
'[user]' ,
|
20
|
+
' name = andy_john' ,
|
21
|
+
' email = andy_john@test.com' ]
|
22
|
+
|
23
|
+
cmd = "#{PPGIT_CMD} john andy andy_john@test.com"
|
24
|
+
check_command_result(cmd, before, expected)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
example 'when there is only an ppgit.emailroot' do
|
29
|
+
before = [ '[ppgit]' ,
|
30
|
+
' emailroot = pp+*@gmail.com' ]
|
31
|
+
|
32
|
+
expected = [ '[ppgit]' ,
|
33
|
+
' emailroot = pp+*@gmail.com' ,
|
34
|
+
'[user]' ,
|
35
|
+
' name = andy_john' ,
|
36
|
+
' email = pp+andy_john@gmail.com' ,
|
37
|
+
]
|
38
|
+
|
39
|
+
cmd = "#{PPGIT_CMD} john andy"
|
40
|
+
check_command_result(cmd, before, expected)
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
context 'when there is a user.name' do
|
45
|
+
before = [ '[user]' ,
|
46
|
+
' name = Alain Ravet' ]
|
47
|
+
|
48
|
+
it "stores the existing user.name and sets the pair user as the new user.name" do
|
49
|
+
expected = [ '[user]' ,
|
50
|
+
' name = andy_john' ,
|
51
|
+
'[user-before-ppgit]' ,
|
52
|
+
' name = Alain Ravet' ]
|
53
|
+
|
54
|
+
cmd = "#{PPGIT_CMD} john andy"
|
55
|
+
check_command_result(cmd, before, expected)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "uses the 3rd parameter as new user.email" do
|
59
|
+
expected = [ '[user]' ,
|
60
|
+
' name = andy_john' ,
|
61
|
+
' email = andy_john@test.com' ,
|
62
|
+
'[user-before-ppgit]' ,
|
63
|
+
' name = Alain Ravet' ]
|
64
|
+
|
65
|
+
cmd = "#{PPGIT_CMD} john andy andy_john@test.com"
|
66
|
+
check_command_result(cmd, before, expected)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "`ppgit john andy andy_john@acme.com`" do
|
73
|
+
|
74
|
+
context 'when there is a user.name and a user.email' do
|
75
|
+
before = [ '[user]' ,
|
76
|
+
' name = Alain Ravet' ,
|
77
|
+
' email = alainravet@gmail.com' ]
|
78
|
+
|
79
|
+
|
80
|
+
it "stores the 2 existing values and sets the pair email and name as the new values" do
|
81
|
+
expected = [ '[user]' ,
|
82
|
+
' name = andy_john' ,
|
83
|
+
' email = andy_john@test.com' ,
|
84
|
+
'[user-before-ppgit]' ,
|
85
|
+
' name = Alain Ravet' ,
|
86
|
+
' email = alainravet@gmail.com']
|
87
|
+
|
88
|
+
cmd = "#{PPGIT_CMD} john andy andy_john@test.com"
|
89
|
+
check_command_result(cmd, before, expected)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
context 'when there is a user.name + email AND stored values in user-before-ppgit' do
|
95
|
+
before = [ '[user]' ,
|
96
|
+
' name = andy_john' ,
|
97
|
+
' email = andy_john@test.com' ,
|
98
|
+
|
99
|
+
'[user-before-ppgit]' ,
|
100
|
+
' name = Alain Ravet' ,
|
101
|
+
' email = alainravet@gmail.com' ]
|
102
|
+
|
103
|
+
|
104
|
+
it "does not overwrite the values stored in user-before-ppgit" do
|
105
|
+
expected = [ '[user]' ,
|
106
|
+
' name = artie_zane' , # new values
|
107
|
+
' email = artie_zane@test.com' , # ..
|
108
|
+
|
109
|
+
'[user-before-ppgit]' ,
|
110
|
+
' name = Alain Ravet' , # not touched
|
111
|
+
' email = alainravet@gmail.com'] # ..
|
112
|
+
|
113
|
+
cmd = "#{PPGIT_CMD} artie zane artie_zane@test.com"
|
114
|
+
check_command_result(cmd, before, expected)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'ppgit'
|
4
|
+
require 'spec'
|
5
|
+
require 'spec/autorun'
|
6
|
+
|
7
|
+
|
8
|
+
Spec::Runner.configure do |config|
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
# ------------------------------------------------------------------------------
|
14
|
+
# setup helpers
|
15
|
+
# ------------------------------------------------------------------------------
|
16
|
+
|
17
|
+
require 'tempfile'
|
18
|
+
require 'ftools'
|
19
|
+
|
20
|
+
def temp_from_model(model, file_basename=nil)
|
21
|
+
newfile = Tempfile.new(file_basename)
|
22
|
+
source_path = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{model}")
|
23
|
+
File.copy(source_path, newfile.path)
|
24
|
+
newfile
|
25
|
+
end
|
26
|
+
|
27
|
+
def temp_from_string(string, file_basename=nil)
|
28
|
+
f = Tempfile.new(file_basename)
|
29
|
+
f.write(string)
|
30
|
+
f.close
|
31
|
+
f
|
32
|
+
end
|
33
|
+
|
34
|
+
def expected_contents(file_name)
|
35
|
+
f = File.expand_path(File.dirname(__FILE__) + "/fixtures/#{file_name}")
|
36
|
+
File.open(f).read
|
37
|
+
end
|
38
|
+
|
39
|
+
PPGIT_CMD = File.expand_path(File.dirname(__FILE__)) + '/../bin/ppgit'
|
40
|
+
|
41
|
+
def check_command_result(git_command, before, expected)
|
42
|
+
before, expected = before.join("\n"), expected.join("\n")
|
43
|
+
config_file_path = temp_from_string(before).path
|
44
|
+
|
45
|
+
`#{git_command} --file #{config_file_path}`
|
46
|
+
|
47
|
+
actual_text = File.open(config_file_path).read.gsub(/\t/, ' ').chomp
|
48
|
+
actual_text.should == expected
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ppgit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Alain Ravet
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-07-21 00:00:00 +02:00
|
19
|
+
default_executable: ppgit
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
34
|
+
version: 1.2.9
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: git users' pairs switcher
|
38
|
+
email: alain.ravet+git@gmail.com
|
39
|
+
executables:
|
40
|
+
- ppgit
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
- README.markdown
|
46
|
+
files:
|
47
|
+
- .document
|
48
|
+
- .gitignore
|
49
|
+
- CHANGELOG
|
50
|
+
- LICENSE
|
51
|
+
- README.markdown
|
52
|
+
- Rakefile
|
53
|
+
- VERSION
|
54
|
+
- bin/ppgit
|
55
|
+
- lib/ppgit.rb
|
56
|
+
- lib/ppgit/usage.txt
|
57
|
+
- lib/ppgit/utils.rb
|
58
|
+
- ppgit.gemspec
|
59
|
+
- spec/ppgit_clear_spec.rb
|
60
|
+
- spec/ppgit_email_root_spec.rb
|
61
|
+
- spec/ppgit_spec.rb
|
62
|
+
- spec/ppgit_usage_spec.rb
|
63
|
+
- spec/spec.opts
|
64
|
+
- spec/spec_helper.rb
|
65
|
+
has_rdoc: true
|
66
|
+
homepage: http://github.com/alainravet/ppgit
|
67
|
+
licenses: []
|
68
|
+
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options:
|
71
|
+
- --charset=UTF-8
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
requirements: []
|
93
|
+
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 1.3.7
|
96
|
+
signing_key:
|
97
|
+
specification_version: 3
|
98
|
+
summary: git users' pairs switcher
|
99
|
+
test_files:
|
100
|
+
- spec/ppgit_clear_spec.rb
|
101
|
+
- spec/ppgit_email_root_spec.rb
|
102
|
+
- spec/ppgit_spec.rb
|
103
|
+
- spec/ppgit_usage_spec.rb
|
104
|
+
- spec/spec_helper.rb
|