Permalink
Browse files

deal with global/local scoping better

  • Loading branch information...
1 parent c4d186e commit 994d59e023fc7d1ca1410c91dbef2398f500c143 Danny Burkes & Josh Susser committed with Danny Burkes & Josh Susser Nov 15, 2010
Showing with 33 additions and 15 deletions.
  1. +2 −0 README.md
  2. +4 −2 git-about
  3. +27 −13 git-pair
View
@@ -33,6 +33,8 @@ Use `git pair` to set the git config user info that sets the commit user metadat
You can put the .pairs file in your project repo root directory and check it into git, or you can put it in your ~ directory so it's available to all projects on the workstation.
+By default this command affects the configuration in the current project (.git/config). Use the `--global` option to set the global git configuration for all projects (~/.gitconfig).
+
## git-project
$ git project pivots
View
@@ -1,8 +1,10 @@
#!/usr/bin/env ruby
config = `git config -l`
-user_name = config =~ %r{^user\.name=(.*)$} ? $1 : "NONE"
-user_email = config =~ %r{^user\.email=(.*)$} ? $1 : "NONE"
+user_name = `git config --get user.name`
+user_name = "NONE" if user_name.length == 0
+user_email = `git config --get user.email`
+user_email = "NONE" if user_email.length == 0
begin
keyfile = File.readlink(File.expand_path("~/.ssh/id_github_current"))
View
@@ -23,11 +23,12 @@ end
def get_pairs_config
pairs_file_path = nil
- until pairs_file_path || Dir.pwd == File.expand_path('/') do
- if File.exists?(".pairs")
- pairs_file_path = File.expand_path(".pairs")
+ candidate_file_path = '.pairs'
+ until pairs_file_path || File.expand_path(candidate_file_path) == '/.pairs' do
+ if File.exists?(candidate_file_path)
+ pairs_file_path = candidate_file_path
else
- Dir.chdir ".."
+ candidate_file_path = File.join("..", candidate_file_path)
end
end
unless pairs_file_path
@@ -47,7 +48,7 @@ email:
INSTRUCTIONS
exit(1)
end
- pairs_file_path ? YAML.load_file(".pairs") : {}
+ pairs_file_path ? YAML.load_file(pairs_file_path) : {}
end
## End of configuration
@@ -86,14 +87,27 @@ if authors.any?
else
config['email']
end
-
- {"user.name" => authors, "user.email" => email}.each do |key, value|
- system("git config #{global_config_string} #{key} #{value}")
- end
+ system(%Q{git config #{global_config_string} user.name "#{authors}"})
+ system(%Q{git config #{global_config_string} user.email "#{email}"})
else
- ["user.name", "user.email"].each do |key|
- system("git config #{global_config_string} --unset #{key}")
- end
+ system("git config #{global_config_string} --unset user.name")
+ system("git config #{global_config_string} --unset user.email")
puts "Unset #{global_config_string} user.name and user.email"
end
-puts `git config #{global_config_string} -l | grep user | tail -2`
+
+global_name_setting = `git config --global --get-regexp '^user\.name'`
+local_name_setting = `git config -f .git/config --get-regexp '^user\.name'`
+if global_name_setting.length > 0 && local_name_setting.length > 0
+ puts "NOTE: Overriding global user.name setting with local."
+end
+puts "global: #{global_name_setting}" if global_name_setting.length > 0
+puts "local: #{local_name_setting}" if local_name_setting.length > 0
+
+
+global_email_setting = `git config --global --get-regexp '^user\.email'`
+local_email_setting = `git config -f .git/config --get-regexp '^user\.email'`
+if global_email_setting.length > 0 && local_email_setting.length > 0
+ puts "NOTE: Overriding global user.email setting with local."
+end
+puts "global: #{global_email_setting}" if global_email_setting.length > 0
+puts "local: #{local_email_setting}" if local_email_setting.length > 0

0 comments on commit 994d59e

Please sign in to comment.