Skip to content

Commit 893d9e1

Browse files
committed
Grab the repository from the document instead of through the initializer
1 parent ede70b1 commit 893d9e1

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

Classes/Controllers/PBGitRepositoryDocument.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ - (void)makeWindowControllers
8585
{
8686
// Create our custom window controller
8787
#ifndef CLI
88-
[self addWindowController: [[PBGitWindowController alloc] initWithRepository:self.repository displayDefault:YES]];
88+
[self addWindowController:[[PBGitWindowController alloc] init]];
8989
#endif
9090
}
9191

Classes/Controllers/PBGitWindowController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
__weak IBOutlet NSProgressIndicator *progressIndicator;
2828
}
2929

30-
@property (nonatomic, strong) PBGitRepository *repository;
30+
@property (nonatomic, strong) PBGitRepository *repository;
3131
/* This is assign because that's what NSWindowController says :-S */
3232
@property (assign) PBGitRepositoryDocument *document;
3333

34-
- (id)initWithRepository:(PBGitRepository*)theRepository displayDefault:(BOOL)display;
34+
- (instancetype)init;
3535

3636
- (void)changeContentController:(PBViewController *)controller;
3737

Classes/Controllers/PBGitWindowController.m

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,28 @@
2222
#import "PBGitRef.h"
2323
#import "PBError.h"
2424
#import "PBRepositoryDocumentController.h"
25+
#import "PBGitRepositoryDocument.h"
2526
#import "PBRefMenuItem.h"
2627
#import "PBRemoteProgressSheet.h"
2728

2829
@implementation PBGitWindowController
2930

30-
@synthesize repository;
3131
@dynamic document;
3232

33-
- (id)initWithRepository:(PBGitRepository*)theRepository displayDefault:(BOOL)displayDefault
33+
- (instancetype)init
3434
{
35-
if (!(self = [self initWithWindowNibName:@"RepositoryWindow"]))
35+
self = [super initWithWindowNibName:@"RepositoryWindow"];
36+
if (!self)
3637
return nil;
3738

38-
self.repository = theRepository;
39-
4039
return self;
4140
}
4241

42+
- (PBGitRepository *)repository
43+
{
44+
return [self.document repository];
45+
}
46+
4347
- (void)synchronizeWindowTitleWithDocumentName
4448
{
4549
[super synchronizeWindowTitleWithDocumentName];
@@ -65,10 +69,10 @@ - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
6569
{
6670
if ([menuItem action] == @selector(showCommitView:)) {
6771
[menuItem setState:(contentController == sidebarController.commitViewController) ? YES : NO];
68-
return ![repository isBareRepository];
72+
return ![self.repository isBareRepository];
6973
} else if ([menuItem action] == @selector(showHistoryView:)) {
7074
[menuItem setState:(contentController != sidebarController.commitViewController) ? YES : NO];
71-
return ![repository isBareRepository];
75+
return ![self.repository isBareRepository];
7276
} else if (menuItem.action == @selector(fetchRemote:)) {
7377
return [self validateMenuItem:menuItem remoteTitle:@"Fetch “%@" plainTitle:@"Fetch"];
7478
} else if (menuItem.action == @selector(pullRemote:)) {
@@ -108,7 +112,8 @@ - (void) windowDidLoad
108112
[[self window] setFrameUsingName:@"GitX"];
109113
[[self window] setRepresentedURL:self.repository.workingDirectoryURL];
110114

111-
sidebarController = [[PBGitSidebarController alloc] initWithRepository:repository superController:self];
115+
sidebarController = [[PBGitSidebarController alloc] initWithRepository:self.repository superController:self];
116+
112117
[[sidebarController view] setFrame:[sourceSplitView bounds]];
113118
[sourceSplitView addSubview:[sidebarController view]];
114119
[sourceListControlsView addSubview:sidebarController.sourceListControlsView];
@@ -283,7 +288,7 @@ - (IBAction)addRemote:(id)sender
283288
windowController:self];
284289
[progressSheet beginProgressSheetForBlock:^{
285290
NSError *error = nil;
286-
BOOL success = [repository addRemote:remoteName withURL:remoteURL error:&error];
291+
BOOL success = [self.repository addRemote:remoteName withURL:remoteURL error:&error];
287292
return success ? nil : error;
288293
} completionHandler:^(NSError *error) {
289294
if (error) {
@@ -292,7 +297,7 @@ - (IBAction)addRemote:(id)sender
292297
}
293298

294299
// Now fetch that remote
295-
PBGitRef *remoteRef = [repository refForName:remoteName];
300+
PBGitRef *remoteRef = [self.repository refForName:remoteName];
296301
[self performFetchForRef:remoteRef];
297302
}];
298303
}];
@@ -309,7 +314,7 @@ - (void)performFetchForRef:(PBGitRef *)ref
309314

310315
[progressSheet beginProgressSheetForBlock:^{
311316
NSError *error = nil;
312-
BOOL success = [repository fetchRemoteForRef:ref error:&error];
317+
BOOL success = [self.repository fetchRemoteForRef:ref error:&error];
313318
return (success ? nil : error);
314319
} completionHandler:^(NSError *error) {
315320
if (error) {
@@ -345,7 +350,7 @@ - (void)performPullForBranch:(PBGitRef *)branchRef remote:(PBGitRef *)remoteRef
345350

346351
[progressSheet beginProgressSheetForBlock:^{
347352
NSError *error = nil;
348-
BOOL success = [repository pullBranch:branchRef fromRemote:remoteRef rebase:rebase error:&error];
353+
BOOL success = [self.repository pullBranch:branchRef fromRemote:remoteRef rebase:rebase error:&error];
349354
return success ? nil : error;
350355
} completionHandler:^(NSError *error) {
351356
if (error) {
@@ -397,7 +402,7 @@ - (void)performPushForBranch:(PBGitRef *)branchRef toRemote:(PBGitRef *)remoteRe
397402

398403
[progressSheet beginProgressSheetForBlock:^{
399404
NSError *error = nil;
400-
BOOL success = [repository pushBranch:branchRef toRemote:remoteRef error:&error];
405+
BOOL success = [self.repository pushBranch:branchRef toRemote:remoteRef error:&error];
401406
return (success ? nil : error);
402407
} completionHandler:^(NSError *error) {
403408
if (error) {
@@ -445,26 +450,26 @@ - (PBSourceViewItem *) selectedItem {
445450
- (IBAction) stashSave:(id) sender
446451
{
447452
NSError *error = nil;
448-
BOOL success = [repository stashSaveWithKeepIndex:NO error:&error];
453+
BOOL success = [self.repository stashSaveWithKeepIndex:NO error:&error];
449454

450455
if (!success) [self showErrorSheet:error];
451456
}
452457

453458
- (IBAction) stashSaveWithKeepIndex:(id) sender
454459
{
455460
NSError *error = nil;
456-
BOOL success = [repository stashSaveWithKeepIndex:YES error:&error];
461+
BOOL success = [self.repository stashSaveWithKeepIndex:YES error:&error];
457462

458463
if (!success) [self showErrorSheet:error];
459464
}
460465

461466
- (IBAction) stashPop:(id) sender
462467
{
463-
if ([repository.stashes count] <= 0) return;
468+
if ([self.repository.stashes count] <= 0) return;
464469

465-
PBGitStash * latestStash = [repository.stashes objectAtIndex:0];
470+
PBGitStash * latestStash = [self.repository.stashes objectAtIndex:0];
466471
NSError *error = nil;
467-
BOOL success = [repository stashPop:latestStash error:&error];
472+
BOOL success = [self.repository stashPop:latestStash error:&error];
468473

469474
if (!success) [self showErrorSheet:error];
470475
}
@@ -513,7 +518,7 @@ - (IBAction) refresh:(id)sender
513518

514519
- (void) createBranch:(id)sender
515520
{
516-
PBGitRef *currentRef = [repository.currentBranch ref];
521+
PBGitRef *currentRef = [self.repository.currentBranch ref];
517522

518523
id <PBGitRefish> refish = nil;
519524
if ([sender isKindOfClass:[PBRefMenuItem class]]) {
@@ -559,7 +564,7 @@ - (void) createTag:(PBRefMenuItem *)sender
559564
if (selectedCommit)
560565
refish = selectedCommit;
561566
else
562-
refish = repository.currentBranch.ref;
567+
refish = self.repository.currentBranch.ref;
563568
}
564569

565570
[PBCreateTagSheet beginSheetWithRefish:refish windowController:self completionHandler:^(PBCreateTagSheet *sheet, NSModalResponse returnCode) {

0 commit comments

Comments
 (0)