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

Fix detached HEAD not showing in tree #235

Open
wants to merge 2 commits 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
26 changes: 12 additions & 14 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 Expand Up @@ -61,7 +59,7 @@ - (id) initWithCoder:(NSCoder *)coder
+ (PBGitRevSpecifier *)allBranchesRevSpec
{
// Using --all here would include refs like refs/notes/commits, which probably isn't what we want.
return [[PBGitRevSpecifier alloc] initWithParameters:[NSArray arrayWithObjects:@"--branches", @"--remotes", @"--tags", @"--glob=refs/stash*", nil] description:@"All branches"];
return [[PBGitRevSpecifier alloc] initWithParameters:@[@"HEAD", @"--branches", @"--remotes", @"--tags", @"--glob=refs/stash*"] description:@"All branches"];
}

+ (PBGitRevSpecifier *)localBranchesRevSpec
Expand Down