Skip to content
Browse files

PBGitRepository: add a handle for in-worktree-commands

  • Loading branch information...
1 parent 53dfea5 commit 4ebe4b4aa971680d427fdb9b7f3539e63540da23 @pieter committed Sep 22, 2008
Showing with 26 additions and 0 deletions.
  1. +1 −0 PBGitCommitController.h
  2. +1 −0 PBGitRepository.h
  3. +24 −0 PBGitRepository.m
View
1 PBGitCommitController.h
@@ -14,4 +14,5 @@
NSArray *cachedFiles;
}
+@property (retain) NSArray *unstagedFiles, *cachedFiles;
@end
View
1 PBGitRepository.h
@@ -21,6 +21,7 @@ extern NSString* PBGitRepositoryErrorDomain;
- (NSFileHandle*) handleForCommand:(NSString*) cmd;
- (NSFileHandle*) handleForArguments:(NSArray*) args;
+- (NSFileHandle *) handleInWorkDirForArguments:(NSArray *)args;
- (NSString*) outputForCommand:(NSString*) cmd;
- (NSString*) outputForCommand:(NSString *)str retValue:(int *)ret;
- (NSString*) outputForArguments:(NSArray*) args;
View
24 PBGitRepository.m
@@ -257,6 +257,22 @@ - (void) readCurrentBranch
[self selectBranch: [self addBranch: [self headRef]]];
}
+- (NSString *) workingDirectory
+{
+ if ([self.fileURL.path hasSuffix:@"/.git"])
+ return [self.fileURL.path substringToIndex:[self.fileURL.path length] - 5];
+ else if ([[self outputForCommand:@"rev-parse --is-inside-work-tree"] isEqualToString:@"true"])
+ return gitPath;
+
+ return nil;
+}
+
+- (int) returnValueForCommand:(NSString *)cmd
+{
+ int i;
+ [self outputForCommand:cmd retValue: &i];
+ return i;
+}
- (NSFileHandle*) handleForArguments:(NSArray *)args
{
@@ -266,6 +282,14 @@ - (NSFileHandle*) handleForArguments:(NSArray *)args
return [PBEasyPipe handleForCommand:gitPath withArgs:arguments];
}
+- (NSFileHandle*) handleInWorkDirForArguments:(NSArray *)args
+{
+ NSString* gitDirArg = [@"--git-dir=" stringByAppendingString:self.fileURL.path];
+ NSMutableArray* arguments = [NSMutableArray arrayWithObject: gitDirArg];
+ [arguments addObjectsFromArray: args];
+ return [PBEasyPipe handleForCommand:gitPath withArgs:arguments inDir:[self workingDirectory]];
+}
+
- (NSFileHandle*) handleForCommand:(NSString *)cmd
{
NSArray* arguments = [cmd componentsSeparatedByString:@" "];

0 comments on commit 4ebe4b4

Please sign in to comment.
Something went wrong with that request. Please try again.