Permalink
Browse files

Make sure User::from_config fails with useful exception in case there…

… is no user information in the git config
  • Loading branch information...
1 parent 5ce692f commit a00b2cd8dee03bcda1ddb616173215697270173c @manveru manveru committed May 31, 2009
Showing with 17 additions and 2 deletions.
  1. +17 −2 lib/git_store/user.rb
View
@@ -9,15 +9,30 @@ def inspect
"#<GitStore::User name=%p email=%p time=%p>" % [name, email, time]
end
+ def self.from_config
+ name, email = config_get('user.name'), config_get('user.email')
new name, email, Time.now
end
+ def self.config_get(key)
+ value = `git config #{key}`.chomp
+
+ if $?.exitstatus == 0
+ return value unless value.empty?
+ raise RuntimError, "#{key} is empty"
+ else
+ raise RuntimError, "No #{key} found in git config"
+ end
+ end
+
+ def self.config_user_email
+ email = `git config user.email`.chomp
+ end
+
def self.parse(user)
if match = user.match(/(.*)<(.*)> (\d+) ([+-]\d+)/)
new match[1].strip, match[2].strip, Time.at(match[3].to_i + match[4].to_i * 3600)
end
end
-
end
-
end

0 comments on commit a00b2cd

Please sign in to comment.