SharpSVN checkout创建本地目录,但它不是工作副本

时间:2015-01-19 17:00:38

标签: c# svn sharpsvn

我正在使用Branch类中的客户端的标准构造函数:

this.svn = newSvnClient();

Branch类中的另一个方法是远程复制:

this.svn.RemoteCopy(this.trunk, this.branch, copy)

最后,同一类中的另一个方法检查出来:

this.svn.CheckOut(this.branch, this.localCopy)

该目录是我希望的,但它不是一个工作副本,只是一个包含所有文件的普通旧文件夹。我已经尝试了svn.Authentication.Clear()svn.Authentication.DefaultCredentials与SslServerTrustHandlers以防万一身份验证是一个问题。这些都行不通。可能是什么问题?

/*
 * Class representing a single branch 
 */
class Branch
{

    public SvnClient svn {get; set;}
    public Uri trunk {get; set;}
    public string localCopy {get; set;} //path to local working copy
    public Uri branch {get; set;} //repo location of new branch to be created
    public string branchName {get; set;}


    public Branch(string branchName, Uri trunk = null)
    {

        this.trunk = trunk ?? new Uri("repo trunk location"); 
        this.branchName = branchName;

        this.svn = new SvnClient();

        this.localCopy = String.Format("C:\\branches\\{0}", this.branchName.Trim());
        this.branch = new Uri(String.Format("repo branch location", this.branchName.Trim()));

    }

    //check if branch on repo already exists
    public static bool checkBranchExists(Uri branch, SvnClient client)
    {
        Collection<SvnInfoEventArgs> info;
        bool branchExists = client.GetInfo(branch, new SvnInfoArgs { ThrowOnError = false }, out info);
        return branchExists;

    }

    //check if local copy already exists
    public static bool checkLocalBranchExists(String localCopy)
    {
        bool localBranchExists = Directory.Exists(localCopy);
        return localBranchExists;

    }

    //CopyTo trunk to branches
    private void CopyTo()
    {
        SvnCopyArgs copy = new SvnCopyArgs();
        copy.LogMessage = "creating new branch";

        if (!checkBranchExists(this.branch, this.svn))
        {
            this.svn.RemoteCopy(this.trunk, this.branch, copy);
        }
        else
        {
            throw new SvnException(); //branch already exists on repo
        }

    }

    //checkout from branches on repo to local working copy
    public void Checkout()
    {


        try
        {
            if (!checkLocalBranchExists(this.localCopy))
            {
                CopyTo();
                this.svn.CheckOut(this.branch, this.localCopy); 
            }
            else
            {
                throw new IOException();
            }

        }
        catch (Exception ex)
        {
            if (ex.InnerException is SvnException)
                MessageBox.Show("Branch already exists on repo", "CopyTo Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            else
            {
                if (ex.InnerException is IOException)
                    MessageBox.Show("Branch already exists locally", "Checkout Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }           

    }
}    

更新:我正在使用Subversion 1.7。据我所知,在1.6之后,checkout不会创建工作副本,这意味着必须使用svn upgrade将目录升级为工作副本。这可能与SharpSVN有关吗?

2 个答案:

答案 0 :(得分:0)

此代码在我的机器上正常工作:

Uri uri = new Uri("https://path-to-svn/svn/test/branch");
Uri branchUri = new Uri("https://path-to-svn/svn/test/branch-copy");
SvnTarget target = SvnTarget.FromUri(uri);
SvnUriTarget targetBranch = new SvnUriTarget(branchUri);

SvnClient client = new SvnClient();
client.Authentication.ForceCredentials("user", "pass");
SvnCopyArgs sca = new SvnCopyArgs();
sca.LogMessage = "here goes some log message";
client.RemoteCopy(target, branchUri, sca);
client.CheckOut(targetBranch, "folder-to-checkout");

它应该与你的相同。请测试一下,让我们知道结果。

答案 1 :(得分:0)

这里的问题是repo的subversion版本,我的本地subversion和SharpSVN版本之间的不匹配,在这种情况下,这三个版本都必须是版本1.7.18。