Skip to content

Commit

Permalink
Don’t try to read local git config if not git repo
Browse files Browse the repository at this point in the history
  • Loading branch information
nertzy committed Dec 1, 2015
1 parent 81f510d commit 44aebf9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/pivotal_git_scripts/git_pair.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ class GitPairException < Exception; end

class Runner
def main(argv)
git_dir = `git rev-parse --git-dir`.chomp
exit 1 if git_dir.empty?

options = parse_cli_options(argv)
initials = argv
config = read_pairs_config
Expand All @@ -40,6 +37,7 @@ def main(argv)
puts "Unset#{' global' if global} user.name, #{'user.email, ' unless no_email(config)}user.initials"
end

git_dir = `git rev-parse --git-dir`.chomp if system('git rev-parse 2>/dev/null')
[:name, :email, :initials].each do |key|
report_git_settings(git_dir, key)
end
Expand Down Expand Up @@ -193,12 +191,16 @@ def set_git_config(global, options)

def report_git_settings(git_dir, key)
global = `git config --global --get-regexp '^user\.#{key}'`
local = `git config -f #{git_dir}/config --get-regexp '^user\.#{key}'`
if global.length > 0 && local.length > 0
if git_dir
local = `git config -f #{git_dir}/config --get-regexp '^user\.#{key}'`
end

if global.length > 0 && local && local.length > 0
puts "NOTE: Overriding global user.#{key} setting with local."
end

puts "global: #{global}" if global.length > 0
puts "local: #{local}" if local.length > 0
puts "local: #{local}" if local && local.length > 0
end

def extract_author_names_and_email_ids_from_config(config, initials)
Expand Down

0 comments on commit 44aebf9

Please sign in to comment.