Skip to content

Fix handling of branches with @ character #234

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
24 changes: 11 additions & 13 deletions Classes/git/PBGitRevSpecifier.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,29 @@

#import "PBGitRevSpecifier.h"


@implementation PBGitRevSpecifier

@synthesize parameters, description, workingDirectory;
@synthesize isSimpleRef;

// I believe this relates loosely to parts of git-check-ref-format.
// cf. https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
//
BOOL ContainsComplexRefCharSequence(NSString *refString)
{
return [refString hasPrefix:@"-"] ||
[refString rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@" ~^:"]].location != NSNotFound ||
[refString rangeOfString:@".."].location != NSNotFound ||
[refString rangeOfString:@"@{"].location != NSNotFound;
}

// internal designated init
- (id) initWithParameters:(NSArray *)params description:(NSString *)descrip
{
self = [super init];
parameters = params;
description = descrip;

if (([parameters count] > 1) || ([parameters count] == 0))
isSimpleRef = NO;
else {
NSString *param = [parameters objectAtIndex:0];
if ([param hasPrefix:@"-"] ||
[param rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"^@{}~:"]].location != NSNotFound ||
[param rangeOfString:@".."].location != NSNotFound)
isSimpleRef = NO;
else
isSimpleRef = YES;
}
isSimpleRef = (parameters.count == 1) && !ContainsComplexRefCharSequence(parameters[0]);

return self;
}
Expand Down