Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safe signature #445

Merged
merged 3 commits into from
Mar 3, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why shouldn't this be a length check too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Libgit2 used to be fine with empty emails: libgit2/libgit2@76e3c43

Apparently not anymore 😢


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