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?).
First wait until the task has finished. This can be done synchronously:
or asynchronously by registering and waiting for the
NSTaskDidTerminateNotification.Then get the process exit status:
For most commands, an exit status of
0means no error and exit status> 0indicates some error. I am quite sure that this applies to thesvncommand, but you can check it with the svn documentation.