I had to update a number of sub-directory names in an SVN repository. To do this I used C# (due to me getting far too comfortable in NetBeans and needing to dust off some cobwebs for Visual Studio).
I also used the SharpSVN library.
There is nothing amazing about the code, just essentially using my blog as a quick repository for future reference if required:
string checkoutPath = @"c:\temp\tempcheckout";
string svnUrl = "svn://mysvnrepositorypath";
SvnClient client = null;
try
{
client = new SvnClient();
client.CheckOut(new Uri(svnUrl), checkoutPath);
client.Update(checkoutPath);
DirectoryInfo di = new DirectoryInfo(checkoutPath);
foreach (DirectoryInfo level1 in di.GetDirectories())
{
foreach (DirectoryInfo level2 in level1.GetDirectories())
{
foreach (DirectoryInfo level3 in level2.GetDirectories())
{
if (!level3.FullName.Contains(".svn"))
{
if (level3.Name.Equals(matchPattern))
{
client.Move(level3.FullName, newDirectoryName);
}
}
}
}
}
SvnCommitArgs args = new SvnCommitArgs();
args.LogMessage = "My logging message";
client.Commit(checkoutPath, args);
}
catch (Exception e)
{
Console.WriteLine("*** Exception : " + e.Message + " ****");
}
finally
{
if (client != null)
{
client.Dispose();
}
}
Console.WriteLine("SVN rename complete.");
As I’m typing this I’m realising my subtle change from using a using() block as suggested by the SharpSVN examples and my try…catch…finally block. I’ve been weary about using ‘using’ blocks since exposure to WCF in .NET 3.5 which didn’t implement the using block quite the same as in other places. I’m now off to do some reading about using blocks to gain a bit of better understanding of them.
As a final note, I did original implement this just to do the check-out and then rename the directories outside of using the SharpSVN toolkit, and then tried do a commit of changes via TortoiseSVN – which failed.
It’s better to use the SvnClient.AdministrativeDirectoryName property instead of “.svn”, because Subversion can be configured (on Windows) to use “_svn”
Good point – hadn’t considered that. Was just looking at the set-up I had! I’ll certainly bare it in mind in the future. Thank you.
How can i get the .dll files in a particular revision in svn repository?
Hi,
I’m not certain exactly what you mean? If you’d like to expand I’d be more than happy to help.
You could use something along the lines of TortoiseSVN to view you repository history, and take the versions you require from a known state / check-in?