Add --init and --clone to gitx CLI and Applescript

Allows creating repositories from the command line, Applescript, or the scripting bridge. These are basic commands, if you need to use commandline options then use git itself.
This commit is contained in:
Nathan Kinsinger
2010-08-21 18:50:12 -06:00
parent b9232721d0
commit 17f50e3f7e
10 changed files with 135 additions and 15 deletions
+2
View File
@@ -28,6 +28,8 @@
- (void) quit; // Quit the application.
- (BOOL) exists:(id)x; // Verify that an object exists.
- (void) showDiff:(NSString *)x; // Show the supplied diff output in a GitX window.
- (void) initRepository:(NSURL *)x; // Create a git repository at the given filesystem URL.
- (void) cloneRepository:(NSString *)x to:(NSURL *)to isBare:(BOOL)isBare; // Clone a repository.
@end
+12
View File
@@ -160,6 +160,18 @@
<command name="show diff" code="GitXShDf" description="Show the supplied diff output in a GitX window.">
<direct-parameter type="text" description="The textual output from a diff tool."/>
</command>
<command name="init repository" code="GitXInit" description="Create a git repository at the given filesystem URL.">
<direct-parameter type="file" description="The URL of the repository to clone."/>
</command>
<command name="clone repository" code="GitXClon" description="Clone a repository.">
<direct-parameter type="text" description="The URL of the repository to clone."/>
<parameter name="to" code="URL " type="file" description="The location for the new repository.">
<cocoa key="destinationURL"/>
</parameter>
<parameter name="is bare" code="Bare" type="boolean" optional="yes" description="Indicates whether the created repository should be a bare repository.">
<cocoa key="isBare"/>
</parameter>
</command>
</suite>
+4 -1
View File
@@ -9,4 +9,7 @@
#define kGitXBundleIdentifier @"nl.frim.GitX"
#define kGitXAEKeyArgumentsList 'ARGS'
#define kGitXAEKeyArgumentsList 'ARGS'
#define kGitXCloneDestinationURLKey @"destinationURL"
#define kGitXCloneIsBareKey @"isBare"
+2
View File
@@ -12,5 +12,7 @@
@interface NSApplication (GitXScripting)
- (void)showDiffScriptCommand:(NSScriptCommand *)command;
- (void)initRepositoryScriptCommand:(NSScriptCommand *)command;
- (void)cloneRepositoryScriptCommand:(NSScriptCommand *)command;
@end
+24
View File
@@ -7,7 +7,10 @@
//
#import "NSApplication+GitXScripting.h"
#import "GitXScriptingConstants.h"
#import "PBDiffWindowController.h"
#import "PBRepositoryDocumentController.h"
#import "PBCloneRepositoryPanel.h"
@implementation NSApplication (GitXScripting)
@@ -22,4 +25,25 @@
}
}
- (void)initRepositoryScriptCommand:(NSScriptCommand *)command
{
NSURL *repositoryURL = [command directParameter];
if (repositoryURL)
[[PBRepositoryDocumentController sharedDocumentController] initNewRepositoryAtURL:repositoryURL];
}
- (void)cloneRepositoryScriptCommand:(NSScriptCommand *)command
{
NSString *repository = [command directParameter];
if (repository) {
NSDictionary *arguments = [command arguments];
NSURL *destinationURL = [arguments objectForKey:kGitXCloneDestinationURLKey];
if (destinationURL) {
BOOL isBare = [[arguments objectForKey:kGitXCloneIsBareKey] boolValue];
[PBCloneRepositoryPanel beginCloneRepository:repository toURL:destinationURL isBare:isBare];
}
}
}
@end
+3
View File
@@ -23,6 +23,7 @@
}
+ (id) panel;
+ (void)beginCloneRepository:(NSString *)repository toURL:(NSURL *)targetURL isBare:(BOOL)bare;
- (void)showMessageSheet:(NSString *)messageText infoText:(NSString *)infoText;
- (void)showErrorSheet:(NSError *)error;
@@ -38,4 +39,6 @@
@property (assign) IBOutlet NSTextField *errorMessage;
@property (assign) IBOutlet NSView *repositoryAccessoryView;
@property (assign) BOOL isBare;
@end
+17
View File
@@ -21,6 +21,8 @@
@synthesize errorMessage;
@synthesize repositoryAccessoryView;
@synthesize isBare;
#pragma mark -
@@ -31,6 +33,21 @@
return [[self alloc] initWithWindowNibName:@"PBCloneRepositoryPanel"];
}
+ (void)beginCloneRepository:(NSString *)repository toURL:(NSURL *)targetURL isBare:(BOOL)bare
{
if (!repository || [repository isEqualToString:@""] || !targetURL || [[targetURL path] isEqualToString:@""])
return;
PBCloneRepositoryPanel *clonePanel = [PBCloneRepositoryPanel panel];
[clonePanel showWindow:self];
[clonePanel.repositoryURL setStringValue:repository];
[clonePanel.destinationPath setStringValue:[targetURL path]];
clonePanel.isBare = bare;
[clonePanel clone:self];
}
- (void) awakeFromNib
{
+1
View File
@@ -16,4 +16,5 @@
}
- (id) documentForLocation:(NSURL*) url;
- (void)initNewRepositoryAtURL:(NSURL *)url;
@end
+11 -10
View File
@@ -47,6 +47,16 @@
return document;
}
- (void)initNewRepositoryAtURL:(NSURL *)url
{
int terminationStatus;
NSString *result = [PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:[NSArray arrayWithObjects:@"init", @"-q", nil] inDir:[url path] retValue:&terminationStatus];
if (terminationStatus == 0)
[self openDocumentWithContentsOfURL:url display:YES error:NULL];
else
NSRunAlertPanel(@"Failed to create new Git repository", @"Git returned the following error when trying to create the repository: %@", nil, nil, nil, result);
}
- (IBAction)newDocument:(id)sender
{
@@ -58,16 +68,7 @@
[op setMessage:@"Initialize a repository here:"];
[op setTitle:@"New Repository"];
if ([op runModal] == NSFileHandlingPanelOKButton)
{
NSString *path = [op filename];
int terminationStatus;
NSString *result = [PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:[NSArray arrayWithObjects:@"init", @"-q", nil] inDir:path inputString:nil retValue:&terminationStatus];
if (terminationStatus == 0)
[self openDocumentWithContentsOfURL:[op URL] display:YES error:NULL];
else
NSRunAlertPanel(@"Failed to create new Git repository", @"Git returned the following error when trying to create the repository: %@", nil, nil, nil, result);
}
[self initNewRepositoryAtURL:[op URL]];
}
+59 -4
View File
@@ -23,6 +23,8 @@ void usage(char const *programName)
printf(" or: %s (--all|--local|--branch) [branch/tag]\n", programName);
printf(" or: %s <revlist options>\n", programName);
printf(" or: %s (--diff)\n", programName);
printf(" or: %s (--init)\n", programName);
printf(" or: %s (--clone <repository> [destination])\n", programName);
printf("\n");
printf(" -h, --help print this help\n");
printf(" -v, --version prints version info for both GitX and git\n");
@@ -60,6 +62,15 @@ void usage(char const *programName)
printf(" shows the diff in a window in GitX\n");
printf(" git diff [options] | gitx\n");
printf(" use gitx to pipe diff output to a GitX window\n");
printf("\n");
printf("Creating repositories\n");
printf(" These commands will create a git repository and then open it up in GitX\n");
printf("\n");
printf(" --init creates (or reinitializes) a git repository\n");
printf(" --clone <repository URL> [destination path]\n");
printf(" clones the repository (at the specified URL) into the current\n");
printf(" directory or into the specified path\n");
printf("\n");
exit(1);
}
@@ -157,6 +168,37 @@ void handleOpenRepository(NSURL *repositoryURL, NSMutableArray *arguments)
}
}
void handleInit(NSURL *repositoryURL)
{
GitXApplication *gitXApp = [SBApplication applicationWithBundleIdentifier:kGitXBundleIdentifier];
[gitXApp initRepository:repositoryURL];
exit(0);
}
void handleClone(NSURL *repositoryURL, NSMutableArray *arguments)
{
if ([arguments count]) {
NSString *repository = [arguments objectAtIndex:0];
if ([arguments count] > 1) {
NSURL *url = [NSURL fileURLWithPath:[arguments objectAtIndex:1]];
if (url)
repositoryURL = url;
}
GitXApplication *gitXApp = [SBApplication applicationWithBundleIdentifier:kGitXBundleIdentifier];
[gitXApp cloneRepository:repository to:repositoryURL isBare:NO];
}
else {
printf("Error: --clone needs the URL of the repository to clone.\n");
exit(2);
}
exit(0);
}
#pragma mark -
#pragma mark main
@@ -228,10 +270,23 @@ int main(int argc, const char** argv)
NSMutableArray *arguments = argumentsArray();
NSURL *wdURL = workingDirectoryURL(arguments);
if ([arguments count] > 0 && ([[arguments objectAtIndex:0] isEqualToString:@"--diff"] ||
[[arguments objectAtIndex:0] isEqualToString:@"-d"])) {
[arguments removeObjectAtIndex:0];
handleDiffWithArguments(wdURL, arguments);
if ([arguments count]) {
NSString *firstArgument = [arguments objectAtIndex:0];
if ([firstArgument isEqualToString:@"--diff"] || [firstArgument isEqualToString:@"-d"]) {
[arguments removeObjectAtIndex:0];
handleDiffWithArguments(wdURL, arguments);
}
if ([firstArgument isEqualToString:@"--init"]) {
[arguments removeObjectAtIndex:0];
handleInit(wdURL);
}
if ([firstArgument isEqualToString:@"--clone"]) {
[arguments removeObjectAtIndex:0];
handleClone(wdURL, arguments);
}
}
// No commands handled by gitx, open the current dir in GitX with the arguments