Question

So I'm currently using the following code to checkout an SVN dir:

NSTask *task = [[NSTask alloc] init];
NSPipe *checkoutPipe = [[NSPipe alloc] init];
[task setLaunchPath:@"/usr/bin/svn"];
[task setArguments:[NSArray arrayWithObjects:@"checkout",SVN_URL_OF_PRJECT_DIR,DEST_DIR,@"--username",SVN_USER,@"--password",SVN_PASSWORD,nil]];
[task setStandardOutput:checkoutPipe];
[task launch];

NSFileHandle *file = [checkoutPipe fileHandleForReading];
NSData *data = [file readDataToEndOfFile];
NSString *checkoutResult = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

NSLog(@"Result: %@",checkoutResult);

This code works fine, but I would like to check programmatically if the checkout was truly successful? The NSLog prints "Checked out revision XY." if the checkout is successful, BUT I observed it prints that even if the files could not actually be put in the specified directory (if the destination path is somehow bad). It will print the Checked out revision XY message along with the message that the destination directory is no good.

So my question is: What is a surefire way to test if the checkout was completely OK and how to make sure that the checking is done after checkout process is completed (I'm not sure, but isn't it async? Or would it have to be in a bg thread for it to be async?).

Was it helpful?

Solution

First wait until the task has finished. This can be done synchronously:

[task waitUntilExit];

or asynchronously by registering and waiting for the NSTaskDidTerminateNotification.

Then get the process exit status:

int status = [task terminationStatus];

For most commands, an exit status of 0 means no error and exit status > 0 indicates some error. I am quite sure that this applies to the svn command, but you can check it with the svn documentation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top