使用 SharpSVN 添加文件

发布于 2024-07-24 08:51:56 字数 1137 浏览 12 评论 0原文

我想使用 SharpSVN 将目录下的所有未版本控制的文件添加到 SVN。

我首先在命令行上尝试了常规的 svn 命令:

C:\temp\CheckoutDir> svn status -v

我看到了所有子目录、所有已签入的文件、一些标有“?”的新文件,没有任何带有“L”锁定指示的文件

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

这会导致所有新文件都在子目录本身已经处于版本控制之下,需要添加。

我想使用 SharpSVN 做同样的事情。 我将一些额外的文件复制到同一目录中并运行此代码:

...
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);
    }
}

但是引发了 SvnException:

  • SvnException.Message: 工作副本 'C:\temp\CheckoutDir' 已锁定
  • SvnException.File: ..\..\..\subversion \libsvn_wc\lock.c"

我的代码中没有其他 svnclient 实例正在运行, 我也尝试

svn.cleanup()

在添加之前拨打电话,但无济于事。

由于文档相当模糊;), 我想知道这里是否有人知道答案。

提前致谢!

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦旅人picnic 2024-07-31 08:51:56

使用我的工具 http://svncompletesync.codeplex.com/ 或将其作为示例。
它正是您所需要的。

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

强者自强 2024-07-31 08:51:56

我尝试了马尔科姆的工具,但现在无法运行它,因为它看起来已经有几年了,但是在查看源代码之后,看起来这确实是您需要用来将本地签出文件夹与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);

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);
浪菊怪哟 2024-07-31 08:51:56

我认为您不应该在路径后缀“,”。 尝试:

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

请在 SharpSvn 讨论板/邮件列表上进一步讨论这个问题,因为您看到的行为可能是一个错误。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文