Skip to content

Commit

Permalink
Return a signature using the defaults if libgit2 errors on the values…
Browse files Browse the repository at this point in the history
… we give them.
  • Loading branch information
joshaber committed Mar 3, 2015
1 parent 21e6e77 commit 3a8507b
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions ObjectiveGit/GTRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -718,24 +718,33 @@ - (GTSubmodule *)submoduleWithName:(NSString *)name error:(NSError **)error {

#pragma mark User

+ (NSString *)defaultUserName {
NSString *name = NSFullUserName();
if (name.length == 0) name = NSUserName();
if (name.length == 0) name = @"nobody";
return name;
}

+ (NSString *)defaultEmail {
NSString *username = NSUserName();
if (username.length == 0) username = @"nobody";
NSString *domain = NSProcessInfo.processInfo.hostName ?: @"nowhere.local";
return [NSString stringWithFormat:@"%@@%@", username, domain];
}

- (GTSignature *)userSignatureForNow {
GTConfiguration *configuration = [self configurationWithError:NULL];
NSString *name = [configuration stringForKey:@"user.name"];
if (name.length == 0) {
name = NSFullUserName();
if (name.length == 0) name = NSUserName();
if (name.length == 0) name = @"nobody";
}
if (name.length == 0) name = self.class.defaultUserName;

NSString *email = [configuration stringForKey:@"user.email"];
if (email == nil) {
NSString *username = NSUserName();
if (username.length == 0) username = @"nobody";
NSString *domain = NSProcessInfo.processInfo.hostName ?: @"nowhere.local";
email = [NSString stringWithFormat:@"%@@%@", username, domain];
}
if (email == nil) email = self.class.defaultEmail;

NSDate *now = [NSDate date];
GTSignature *signature = [[GTSignature alloc] initWithName:name email:email time:now];
if (signature != nil) return signature;

return [[GTSignature alloc] initWithName:name email:email time:[NSDate date]];
return [[GTSignature alloc] initWithName:self.class.defaultUserName email:self.class.defaultEmail time:now];
}

#pragma mark Tagging
Expand Down

0 comments on commit 3a8507b

Please sign in to comment.