GitX v0.4.1
[GitX.git] / PBChangedFile.m
blob518ca6498eac213cc4006afe1eb89b324dc5bb5f
1 //
2 //  PBChangedFile.m
3 //  GitX
4 //
5 //  Created by Pieter de Bie on 22-09-08.
6 //  Copyright 2008 __MyCompanyName__. All rights reserved.
7 //
9 #import "PBChangedFile.h"
10 #import "PBEasyPipe.h"
12 @implementation PBChangedFile
14 @synthesize path, status, cached;
16 - (id) initWithPath:(NSString *)p andRepository:(PBGitRepository *)r
18         path = p;
19         repository = r;
20         return self;
23 - (NSString *) changes
25         if (status == NEW)
26                 return [PBEasyPipe outputForCommand:@"/bin/cat" withArgs:[NSArray arrayWithObject:path] inDir:[repository workingDirectory]];
27         else {
28                 if (cached == YES)
29                         return [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", @"--cached", @"--", path, nil]];
30                 else
31                         return [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"diff", @"--", path, nil]];
32         }
35 - (NSImage *) icon
37         NSString *filename;
38         switch (status) {
39                 case NEW:
40                         filename = @"new_file";
41                         break;
42                 case DELETED:
43                         filename = @"deleted_file";
44                         break;
45                 default:
46                         filename = @"empty_file";
47                         break;
48         }
49         NSString *p = [[NSBundle mainBundle] pathForResource:filename ofType:@"png"];
50         return [[NSImage alloc] initByReferencingFile: p];
53 - (void) stageChanges
55         if (status == DELETED)
56                 [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"rm", path, nil]];
57         else
58                 [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"add", path, nil]];
60         self.cached = YES;
62 - (void) unstageChanges
64         [repository outputInWorkdirForArguments:[NSArray arrayWithObjects:@"reset", @"--", path, nil]];
65         self.cached = NO;
68 + (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
70         return NO;
73 + (BOOL)isKeyExcludedFromWebScript:(const char *)name {
74         return NO;
77 @end