mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Add some more checking/validation methods to PBGitRepository.
- Add a shaExists method that takes string with a SHA and either returns the full SHA if it exists or nil if not. - Add a completeRefForString: method which completes partial refs like "xyz/master" to "refs/remotes/xyz/master" for example. - Add a checkRefFormatForBranch: method which does the same as checkRefFormat except it also works with partial branch refs like "xyz/master". - Add headRefForSHA skeleton to encapsulate the shell-script-fu from populateList in PBGitSidebarController that deals with getting the head ref for a SHA.
This commit is contained in:
@@ -103,7 +103,11 @@ static NSString * PBStringFromBranchFilterType(PBGitXBranchFilterType type) {
|
||||
- (BOOL) isSHAOnHeadBranch:(NSString *)testSHA;
|
||||
- (BOOL) isRefOnHeadBranch:(PBGitRef *)testRef;
|
||||
- (BOOL) checkRefFormat:(NSString *)refName;
|
||||
- (BOOL) checkRefFormatForBranch:(NSString *)shaOrRefName;
|
||||
- (PBGitRef *) completeRefForString:(NSString *)partialRefString;
|
||||
- (BOOL) refExists:(PBGitRef *)ref;
|
||||
// checks to see if the ref or sha exists - returns nil if not found and the complete sha if found
|
||||
- (NSString *) shaExists:(NSString *)sha;
|
||||
|
||||
- (NSArray *) remotes;
|
||||
- (BOOL) hasRemotes;
|
||||
|
||||
@@ -311,6 +311,13 @@ static NSString * repositoryBasePath = nil;
|
||||
return [self shaForRef:[[self headRef] ref]];
|
||||
}
|
||||
|
||||
- (NSString *) headRefForSHA:(NSString *)sha
|
||||
{
|
||||
// TODO: move code over
|
||||
// from PBGitSidebarController populateList
|
||||
// that deals with getting the head refs path
|
||||
}
|
||||
|
||||
- (PBGitCommit *) headCommit
|
||||
{
|
||||
return [self commitForSHA:[self headSHA]];
|
||||
@@ -417,6 +424,32 @@ static NSString * repositoryBasePath = nil;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL) checkRefFormatForBranch:(NSString *)shaOrRefName
|
||||
{
|
||||
int retValue = 1;
|
||||
[self outputInWorkdirForArguments:[NSArray arrayWithObjects:@"check-ref-format", @"--branch", shaOrRefName, nil] retValue:&retValue];
|
||||
if (retValue)
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (PBGitRef *) completeRefForString:(NSString *)partialRefString {
|
||||
if (![self checkRefFormat:partialRefString] &&
|
||||
![self checkRefFormatForBranch:partialRefString]) {
|
||||
return nil;
|
||||
}
|
||||
NSArray * prefixes = [NSArray arrayWithObjects:kGitXBranchRefPrefix, kGitXRemoteRefPrefix, kGitXTagRefPrefix, nil];
|
||||
PBGitRef * completeRef = nil;
|
||||
for (NSString * prefix in prefixes) {
|
||||
PBGitRef * tryref = [PBGitRef refFromString:[NSString stringWithFormat:@"%@%@", prefix, partialRefString]];
|
||||
if ([self refExists:tryref]) {
|
||||
completeRef = tryref;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return completeRef;
|
||||
}
|
||||
|
||||
- (BOOL) refExists:(PBGitRef *)ref
|
||||
{
|
||||
int retValue = 1;
|
||||
@@ -425,6 +458,15 @@ static NSString * repositoryBasePath = nil;
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSString *) shaExists:(NSString *)sha
|
||||
{
|
||||
int retValue = 1;
|
||||
NSString *output = [self outputInWorkdirForArguments:[NSArray arrayWithObjects:@"rev-parse", sha, nil] retValue:&retValue];
|
||||
if (retValue || [output isEqualToString:@""])
|
||||
return nil;
|
||||
return output;
|
||||
}
|
||||
|
||||
// Returns either this object, or an existing, equal object
|
||||
- (PBGitRevSpecifier*) addBranch:(PBGitRevSpecifier*)branch
|
||||
|
||||
Reference in New Issue
Block a user