Add file using SharpSVN
Asked Answered
R

3

5

I would like to add all unversioned files under a directory to SVN using SharpSVN.

I tried regular svn commands on the command line first:

C:\temp\CheckoutDir> svn status -v

I see all subdirs, all the files that are already checked in, a few new files labeled "?", nothing with the "L" lock indication

C:\temp\CheckoutDir> svn add . --force

This results in all new files in the subdirs ,that are already under version control themselves, to be added.

I'd like to do the same using SharpSVN. I copy a few extra files into the same directory and run this code:

...
using ( SharpSvn.SvnClient svn = new SvnClient() )
{
    SvnAddArgs saa = new SvnAddArgs();
    saa.Force = true;
    saa.Depth = SvnDepth.Infinity;
    try
    {
        svn.Add(@"C:\temp\CheckoutDir\." , saa);
    }
    catch (SvnException exc)
    {
        Log(@"SVN Exception: " + exc.Message + " - " + exc.File);
    }
}

But an SvnException is raised:

  • SvnException.Message: Working copy 'C:\temp\CheckoutDir' locked
  • SvnException.File: ..\..\..\subversion\libsvn_wc\lock.c"

No other svnclient instance is running in my code, I also tried calling

svn.cleanup()

right before the Add, but to no avail.

Since the documentation is rather vague ;), I was wondering if anyone here knew the answer.

Thanks in advance!

Jan

Resorcinol answered 8/6, 2009 at 13:20 Comment(2)
Have you tried asking on the SharpSVN discussion boards? You probably could get a better response there.Dissimilate
I will, in the mean time I looked in the Unit tests code: sharpsvn.open.collab.net/source/browse/sharpsvn/trunk/src/… TestAddDirectoryRecursively does something similar, but Adds a new dir1 under WorkingcopyPath and everyting in it. I would like to Add everything under WorkingCopyPath itself.Resorcinol
B
5

Use this my tool http://svncompletesync.codeplex.com/ or take it as a sample. It does exactly what you need.

Barbette answered 7/6, 2010 at 23:0 Comment(1)
Great tool Malcom, does exactly what it says on the box. +1Emmery
R
2

I tried Malcolm's tool but couldn't get it to run now that it looks to be a few years old, but after looking at the source code it looks like this is really all you need to use to sync the local checked out folder with the one in SVN:

string _localCheckoutPath = @"C:\temp\CheckoutDir\";
SvnClient client = new SvnClient();

Collection<SvnStatusEventArgs> changedFiles = new Collection<SvnStatusEventArgs>();
client.GetStatus(_localCheckoutPath, out changedFiles);

//delete files from subversion that are not in filesystem
//add files to suversion , that are new in filesystem

foreach (SvnStatusEventArgs changedFile in changedFiles)
{
    if (changedFile.LocalContentStatus == SvnStatus.Missing)
    {
        client.Delete(changedFile.Path);
    }
    if (changedFile.LocalContentStatus == SvnStatus.NotVersioned)
    {
        client.Add(changedFile.Path);
    }
}

SvnCommitArgs ca = new SvnCommitArgs();
ca.LogMessage = "Some message...";

client.Commit(_localCheckoutPath, ca);
Rose answered 2/12, 2014 at 18:32 Comment(0)
I
1

I think you shouldn't suffix the path with a ','. Try:

svn.Add(@"C:\temp\CheckoutDir" , saa);

Please do discuss this further on the SharpSvn discussion board/mailing list, because the behavior you are seeing might be a bug.

Inna answered 8/6, 2009 at 22:5 Comment(1)
The code you propose tells me: "C:\temp" is not under version control. Which is right. But doesn't help me. I'll post on the forums as soon as I can. Thanks!Resorcinol

© 2022 - 2024 — McMap. All rights reserved.