tags:

views:

459

answers:

3

Currently I'm writing out files with php into a directory, I add that directory (works fine), then when i try and do an svn commit its not working nor returning any kind of error codes. Does anyone have any idea on this?

$tmp = exec('cd '.$this->build_locations[$this->type].'; svn commit --username user --password pw; ls', $output);

I do the cd to the directory (did ls in here worked fine), I do an ls afterwards to confirm its still in the directory.

I've also tried:

svn help

which returns me all the commands just fine (so i know its not an issue with not finding the svn command.

I've chmoded the file 777 to confirm it can execute.

Any other ideas?

Thanks in advance

Edited Code:

    $output = array();
    $tmp1 = exec("cd ".$this->build_locations[$this->type].";");
    $tmp = exec("svn commit ".$this->build_locations[$this->type].$this->app_id." --username user --password password -m 'test' --non-interactive --trust-server-cert --quiet 2>&1;", $output, $error);
    if($error){
        echo('<pre>');
        print_r($output);
        echo('</pre>');
    }
    exit;

This produces:

Array

[0] => could not lookup DNS configuration info service: (ipc/send) invalid destination port
[1] => svn: Commit failed (details follow):
[2] => svn: Unknown hostname 'my.host'
A: 

AFAIK, after a svn commit, if the -m option is not provided, an editor opens up to type in the commit message. Try passing -m "Some commit message", maybe that'll help.

robertbasic
Yes tried this too, along with adding --non-interactive and -q but with no luck :(
Frederico
Did you try to commit like that from shell? Just to test that the configuration for --username and --password are OK? (see the svn book page 86)
robertbasic
Yep, works fine that way
Frederico
Shooting in the dark: tried changing the order of --username/--password and commit?
robertbasic
+1  A: 

Can you try throwing out the errors (read Mike's comment) status.

('cd '.$this->build_locations[$this->type].'; svn commit --username user --password pw; ls', $output, $error);
if($error){
   print_r($error);
}

I would suggest to break the above into 3 separate commands for debugging purpose.

Also, if $this-type can be manipulated by the users, then your code is vulnerable as they can pass something like: .; cat /etc/passwd, which becomes

$tmp = exec('cd .; cat /etc/passwd; svn commit --username user --password pw; ls', $output);
Jay Zeng
Jay, thanks for the warning, yea its not a value the user can enter. I've added that, and it just prints value: 1 for the error. Editing above post to show you what it looks like now.
Frederico
@Frederico - More readable, what errors do you see or nothing happened? By the way, you can do the formatting with print_r("<pre>"); print_r($error);print_r("</pre>"); just in case you don't know.
Jay Zeng
Also you should run the command you constructed in console to ensure it is good.
Jay Zeng
the only thing that exports out is 1 for the $error variable. Doesn't look like anything else is showing up :/
Frederico
@Frederico - Have you verified your svn command is correct in console? I switched to git quite a while and don't quite remember the syntax of svn.
Jay Zeng
Yea works fine in my console. Not sure why i'm getting this error out of console..
Frederico
+1  A: 

SVN command line errors go to stderr, not stdout, which is why you aren't able to see them. What you want to do is redirect stderr to stdout and then print_r($output) to determine the cause of the error.

exec('svn commit <stuff> 2>&1', $output, $returnStatus);
if ( $returnStatus )
{
    print_r($output);
}

Sample output:

Array
(
    [0] => svn: Commit failed (details follow):
    [1] => svn: '/path/to/<stuff>' is not under version control
)

This is not ideal because it mixes stderr with stdout when it would otherwise be unnecessary, but I don't know of another way to get the desired output in this case. If someone else does, please comment.

Note: The third parameter to exec(...) is the return status, not the error message, so you need to tweak your code accordingly for that as well.

If the error output after making the 2>&1 modification doesn't help solve the root cause of your problem, please post the new output here.

Edit after new information:

Did you upload this SVN working copy to your server from somewhere else? That would explain this error.

If I check out a working copy from my local repository, upload it to my remote server, and then try to commit, I get the same error.

If that's the case, you need to execute the "svn checkout" of the working copy on the server running the PHP script in order to be able to commit to it. If that server can't communicate with the repository's server, then that's a whole other problem.

Mike
@Mike - Thanks for pointing out. you are right,per the manual, the 3rd parameter means "If the return_var argument is present along with the output argument, then the return status of the executed command will be written to this variable."
Jay Zeng
Thanks Mike, I was able to toss out a few more fun errors.. Added above.
Frederico
It's strange as the working copy has been checked out already, and I have my gui - Versions - up looking at the file (shows modified). So I'm not sure why it thinks that the hostname can't be found..I'm uploading a test case to try on a working copy directly on the server as well.Thanks
Frederico
That actually makes sense if you are working over Samba or something similar. Any operations your GUI does on the repository would originate from your computer, while any operations the PHP script does on the repository would originate from the PHP server. If the PHP server can't talk to the SVN server, there's your problem. Try SSH'ing onto the PHP server and pinging the SVN server to see if it's visible.
Mike
Yes, I got a bit further on the server, appears the permissions wern't set right on my initial grab of the working copy. It's telling me that svn can't open file /location/.svn/lock/ which i'm figuring means since i created the WC with another user is why i'm seeing this. Now trying to create the WC with same user as web is on. Thanks for the heads up with the outputting the errors, helping me move much quicker on this!
Frederico
With a redownload of the WC with the correct user, all worked great!
Frederico