Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

Commit

Permalink
Don't set git email if no email config in .pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmfoley committed Aug 24, 2012
1 parent 04003d0 commit db8d016
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
18 changes: 13 additions & 5 deletions bin/git-pair
Expand Up @@ -22,6 +22,8 @@ Create a `.pairs` config file in project root or your home folder.
eh: Edward Hieatt
js: Josh Susser; jsusser
sf: Serguei Filimonov; serguei
# if email section is present, email will be set
# if you leave out the email config section, email will not be set
email:
prefix: pair
domain: pivotallabs.com
Expand Down Expand Up @@ -126,6 +128,10 @@ def extract_author_names_and_email_ids_from_config(config, initials)
end.transpose
end

def no_email(config)
!config.key? 'email'
end

git_dir = `git rev-parse --git-dir`.chomp
exit 1 if git_dir.empty?

Expand All @@ -137,12 +143,14 @@ global = " --global" if options[:global] or config["global"]
if initials.any?
author_names, email_ids = extract_author_names_and_email_ids_from_config(config, initials)
authors = [author_names[0..-2].join(", "), author_names.last].reject(&:empty?).join(" and ")
email = build_email(email_ids, config["email"])

set_git_config global, :name => authors, :email => email, :initials => initials.join(" ")
git_config = {:name => authors, :initials => initials.join(" ")}
git_config[:email] = build_email(email_ids, config["email"]) unless no_email(config)
set_git_config global, git_config
else
set_git_config global, :name => nil, :email => nil, :initials => nil
puts "Unset#{global} user.name, user.email, user.initials"
git_config = {:name => nil, :initials => nil}
git_config[:email] = nil unless no_email(config)
set_git_config global, git_config
puts "Unset#{global} user.name, #{'user.email, ' unless no_email(config)}user.initials"
end

[:name, :email, :initials].each do |key|
Expand Down
21 changes: 21 additions & 0 deletions spec/cli_spec.rb
Expand Up @@ -82,6 +82,11 @@ def expect_config(result, name, initials, email, options={})
result.should include "#{prefix}user.email #{email}"
end

def git_config_value(name, global = false)
global_prefix = "cd /tmp && " if global
`#{global_prefix}git config user.#{name}`
end

it "prints help" do
result = run "git-pair --help"
result.should include("Configures git authors when pair programming")
Expand Down Expand Up @@ -183,6 +188,22 @@ def expect_config(result, name, initials, email, options={})
expect_config result, "Aa Bb", "ab", "foo@bar.com"
end

context "when no email config is present" do
before do
write ".pairs", File.read(".pairs").sub(/email:.*/m, "")
end

it "doesn't set email" do
run "git pair ab"
git_config_value('email').should be_empty
end

it "doesn't report about email" do
result = run "git pair ab"
result.should_not include "email"
end
end

it "uses no email prefix when only host is given" do
write ".pairs", File.read(".pairs").sub(/email:.*/m, "email:\n domain: foo.com")
result = run "git pair ab"
Expand Down

0 comments on commit db8d016

Please sign in to comment.