Reputation:
I'd like to call svn up from an asp.net page so people can hit the page to update a repository. (BTW: I'm using Beanstalk.com svn hosting which doesn't allow post-commit hooks, which is why I am doing it this way).
See what I've got below. The process starts (it shows up in Processes in Task Manager) and exits after several seconds with no output message (at least none is outputted to the page). The repository does not get updated. But it does do something with the repository because the next time I try to manually update it from the command line it says the repo is locked. I have to run svn cleanup to get it to update.
Ideas?
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
startInfo = New System.Diagnostics.ProcessStartInfo("svn")
startInfo.RedirectStandardOutput = True
startInfo.UseShellExecute = False
startInfo.Arguments = "up " & Request.QueryString("path")
pStart.StartInfo = startInfo
pStart.Start()
pStart.WaitForExit()
Response.Write(pStart.StandardOutput.ReadToEnd())
End Sub
Upvotes: 2
Views: 1081
Reputation: 1
I have investigated this in detail. A loooong way to do it is to use Windows Messaging Subsystem (windows event log - you create your own log and write messages to it). Asp.Net creates a message. Then you need to write a windows service which reads the messages every 3 seconds or so. The moment it comes across an 'update svn please message', you run your cmd.exe /c svn.exe blah blah from your freshly created windows service...it works very well, buts its a lot of work...Then there is SharpSVN lib, but it requires a bit of setup and you can run into problems. Finally, most people seem to be trying to use ProcessStartInfo class, but few seem to get it right...Yes, its not easy and a long way around but here's the code......Here's code that will run svn.exe for you and log all the screen output to output buffer....
private static int lineCount = 0;
private static StringBuilder outputBuffer = new StringBuilder();
private void SvnOutputHandler(object sendingProcess,
DataReceivedEventArgs e)
{
Process p = sendingProcess as Process;
// Save the output lines here
// Prepend line numbers to each line of the output.
if (!String.IsNullOrEmpty(e.Data))
{
lineCount++;
outputBuffer.Append("\n[" + lineCount + "]: " + e.Data);
}
}
private void RunSVNCommand()
{
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe",
string.Format("/c svn.exe --config-dir=%APPDATA%\\Subversion --username=yrname --password=yrpassword --trust-server-cert --non-interactive update d:\\inetpub\\wwwroot\\yourpath"));
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
// Redirect the standard output of the sort command.
// This stream is read asynchronously using an event handler.
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
Process p = new Process();
// Set our event handler to asynchronously read the sort output.
p.OutputDataReceived += SvnOutputHandler;
p.ErrorDataReceived += SvnOutputHandler;
p.StartInfo = psi;
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
p.WaitForExit();
}
Quick explanation on svn.exe arguments and why we do it...You need to specify config-dir to whatever account has checked out the svn dir. IIS runs under a different account. If it can't find the config file for svn, you will get a stop message. --Non-interactive and --trust-server-certificate is to basically skip the prompt to accept the security challenges. Finally, you will need to specify username and password as this for some reason does not get sent (with my version of svn.exe anyway). Now, on top of this, connecting via https to the svn server was giving me errors as the hostname reported by IIS is different to a desktop hostname (ssl cert mismatch), hence it does not like the hostname in the config file - go figure. So, I figured, that if I reverse proxy from http to https (so now I have two websites on one server, with one being reversesvn.domain.com:80 proxing to svn.domain.com:8443) This will skip on all the certificate issues and that was the final piece of the puzzle. Here's how to do it - simple : https://blog.ligos.net/2016-11-14/Reverse-Proxy-With-IIS-And-Lets-Encrypt.html.
Upvotes: 0
Reputation: 36300
You can also use the Subversion library that comes with Ankh SVN. I used it in a project to manage files in a Subversion repository and it worked well.
If you insist on using the command line client make sure you check the StandardError output for any error messages. Also make sure the user you run the process as has the appropriate rights.
Upvotes: 2
Reputation: 19612
Using SharpSvn:
using(SvnClient client = new SvnClient())
{
client.Update(Request["path"]);
}
But I would recommend not to use a user passed variable directly for security reasons.
Upvotes: 0