Skip to content
Browse files

Don't set git email if no email config in .pairs

  • Loading branch information...
1 parent 04003d0 commit db8d0169419dc032877e8e9f5a2492f3c2a5db0b @davidmfoley davidmfoley committed
Showing with 34 additions and 5 deletions.
  1. +13 −5 bin/git-pair
  2. +21 −0 spec/cli_spec.rb
View
18 bin/git-pair
@@ -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
@@ -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?
@@ -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|
View
21 spec/cli_spec.rb
@@ -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")
@@ -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"

0 comments on commit db8d016

Please sign in to comment.
Something went wrong with that request. Please try again.