13
13
#import " PBGitBinary.h"
14
14
#import " GitRepoFinder.h"
15
15
16
+ #import < ObjectiveGit/GTRepository.h>
17
+
16
18
@implementation PBRepositoryDocumentController
17
19
// This method is overridden to configure the open panel to only allow
18
20
// selection of directories
@@ -24,60 +26,23 @@ - (NSInteger)runModalOpenPanel:(NSOpenPanel *)openPanel forTypes:(NSArray *)exte
24
26
return [openPanel runModal ];
25
27
}
26
28
27
- // Convert paths to the .git dir before searching for an already open document
28
- - (id )documentForURL : (NSURL *)URL
29
- {
30
- NSURL * fileURL = [GitRepoFinder fileURLForURL: URL];
31
- id result = [super documentForURL: fileURL];
32
- return result;
33
- }
34
-
35
- - (void )noteNewRecentDocumentURL : (NSURL *)URL
36
- {
37
- NSURL * fileURL = [GitRepoFinder fileURLForURL: URL];
38
- [super noteNewRecentDocumentURL: fileURL];
39
- }
40
-
41
- - (id ) documentForLocation : (NSURL *) url
42
- {
43
- id document = [self documentForURL: url];
44
- if (!document) {
45
-
46
- if (!(document = [[PBGitRepository alloc ] initWithURL: url]))
47
- return nil ;
48
-
49
- [self addDocument: document];
50
- }
51
- else
52
- [document showWindows ];
53
-
54
- return document;
55
- }
56
-
57
- - (void )initNewRepositoryAtURL : (NSURL *)url
58
- {
59
- int terminationStatus;
60
- NSString *result = [PBEasyPipe outputForCommand: [PBGitBinary path ] withArgs: [NSArray arrayWithObjects: @" init" , @" -q" , nil ] inDir: [url path ] retValue: &terminationStatus];
61
-
62
- if (terminationStatus == 0 )
63
- [self openDocumentWithContentsOfURL: url display: YES error: NULL ];
64
- else
65
- NSRunAlertPanel (@" Failed to create new Git repository" , @" Git returned the following error when trying to create the repository: %@ " , nil , nil , nil , result);
66
- }
67
-
68
- - (IBAction )newDocument : (id )sender
69
- {
29
+ - (id )makeUntitledDocumentOfType : (NSString *)typeName error : (NSError *__autoreleasing *)outError {
70
30
NSOpenPanel *op = [NSOpenPanel openPanel ];
71
31
72
32
[op setCanChooseFiles: NO ];
73
33
[op setCanChooseDirectories: YES ];
74
34
[op setAllowsMultipleSelection: NO ];
75
35
[op setMessage: @" Initialize a repository here:" ];
76
36
[op setTitle: @" New Repository" ];
77
- if ([op runModal ] == NSFileHandlingPanelOKButton )
78
- [self initNewRepositoryAtURL: [op URL ]];
79
- }
37
+ if ([op runModal ] != NSFileHandlingPanelOKButton )
38
+ return nil ;
80
39
40
+ BOOL success = [GTRepository initializeEmptyRepositoryAtURL: [op URL ] error: outError];
41
+ if (!success)
42
+ return nil ; // Repo creation failed
43
+
44
+ return [[PBGitRepository alloc ] initWithContentsOfURL: [op URL ] ofType: PBGitRepositoryDocumentType error: outError];
45
+ }
81
46
82
47
- (BOOL )validateMenuItem : (NSMenuItem *)item
83
48
{
0 commit comments