Permalink
Browse files

CommitView: Add commit capability

  • Loading branch information...
1 parent 4024753 commit 3f923f51a10206ed91505bc7e4d61fad586d1682 @pieter committed Sep 23, 2008
Showing with 79 additions and 5 deletions.
  1. +2 −0 PBGitCommitController.h
  2. +36 −0 PBGitCommitController.m
  3. +32 −5 PBGitCommitView.xib
  4. +9 −0 PBGitRepository.m
View
@@ -14,6 +14,7 @@
@interface PBGitCommitController : PBViewController {
NSMutableArray *files;
+ IBOutlet NSTextView *commitMessageView;
IBOutlet NSArrayController *unstagedFilesController;
IBOutlet NSArrayController *cachedFilesController;
@@ -28,4 +29,5 @@
- (void) readUnstagedFiles;
- (IBAction) refresh:(id) sender;
+- (IBAction) commit:(id) sender;
@end
View
@@ -83,6 +83,42 @@ - (void) readCachedFiles
}
}
+- (IBAction) commit:(id) sender
+{
+ NSString *commitMessage = [commitMessageView string];
+ if ([commitMessage length] < 3) {
+ [[NSAlert alertWithMessageText:@"Commitmessage missing"
+ defaultButton:nil
+ alternateButton:nil
+ otherButton:nil
+ informativeTextWithFormat:@"Please enter a commit message before committing"] runModal];
+ return;
+ }
+
+ NSString *tree = [repository outputForCommand:@"write-tree"];
+ if ([tree length] != 40) {
+ NSLog(@"Tree: %@", tree);
+ return;
+ }
+ int ret;
+ NSString *commit = [repository outputForArguments:[NSArray arrayWithObjects:@"commit-tree", tree, @"-p", @"HEAD", nil]
+ inputString:commitMessage
+ retValue: &ret];
+ if (ret || [commit length] != 40) {
+ NSLog(@"Commit failed");
+ return;
+ }
+
+ [repository outputForArguments:[NSArray arrayWithObjects:@"update-ref", @"-m", @"Commit from GitX", @"HEAD", commit, nil]
+ retValue: &ret];
+ if (ret) {
+ NSLog(@"Commit failed(2)");
+ return;
+ }
+
+ NSLog(@"Success! New commit: %@", commit);
+}
+
- (void) cellClicked:(NSCell*) sender
{
NSTableView* tableView = [sender controlView];
View
@@ -8,7 +8,7 @@
<string key="IBDocument.HIToolboxVersion">352.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="54"/>
+ <integer value="130"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1074,6 +1074,22 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
</object>
<int key="connectionID">211</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">commit:</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="792511503"/>
+ </object>
+ <int key="connectionID">212</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">commitMessageView</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="1023793991"/>
+ </object>
+ <int key="connectionID">213</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -1405,7 +1421,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilderKit</string>
<string>com.apple.InterfaceBuilderKit</string>
- <string>{{312, 344}, {852, 432}}</string>
+ <string>{{358, 206}, {852, 432}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="8"/>
<reference ref="8"/>
@@ -1456,7 +1472,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">211</int>
+ <int key="maxID">213</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -1465,22 +1481,33 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<string key="className">PBGitCommitController</string>
<string key="superclassName">PBViewController</string>
<object class="NSMutableDictionary" key="actions">
- <string key="NS.key.0">refresh:</string>
- <string key="NS.object.0">id</string>
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSMutableArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>commit:</string>
+ <string>refresh:</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>id</string>
+ <string>id</string>
+ </object>
</object>
<object class="NSMutableDictionary" key="outlets">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSMutableArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>cachedButtonCell</string>
<string>cachedFilesController</string>
+ <string>commitMessageView</string>
<string>unstagedButtonCell</string>
<string>unstagedFilesController</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>PBIconAndTextCell</string>
<string>NSArrayController</string>
+ <string>NSTextView</string>
<string>PBIconAndTextCell</string>
<string>NSArrayController</string>
</object>
View
@@ -324,6 +324,15 @@ - (NSString*) outputForArguments:(NSArray *)arguments retValue:(int *)ret;
return [PBEasyPipe outputForCommand:gitPath withArgs:arguments inDir: self.fileURL.path retValue: ret];
}
+- (NSString*) outputForArguments:(NSArray *)arguments inputString:(NSString *)input retValue:(int *)ret;
+{
+ return [PBEasyPipe outputForCommand:gitPath
+ withArgs:arguments
+ inDir: self.fileURL.path
+ inputString:input
+ retValue: ret];
+}
+
- (NSString*) parseReference:(NSString *)reference
{
return [self outputForArguments:[NSArray arrayWithObjects: @"rev-parse", reference, nil]];

0 comments on commit 3f923f5

Please sign in to comment.