开发者

Commit in sharpSVN

开发者 https://www.devze.com 2022-12-21 21:01 出处:网络
I have a problem doing commit with sharpsvn. Now i´m adding all the files of my working copy (if the file is added throws an exception), and after it i do commit. It works but it trows exceptions. Th

I have a problem doing commit with sharpsvn. Now i´m adding all the files of my working copy (if the file is added throws an exception), and after it i do commit. It works but it trows exceptions. There is some way to get the status of the repository before do add() and only add the new files or the files who are changed? And if i delete one file or folder on my working copy , How can i delete these files or folder on the repository? Code:

 String[] folders;
 folders = Directory.GetDirectories(direccionLocal,"*.*", SearchOption.AllDirectories);
 foreach (String folder in folders)
            {
                String[] files;
                files = Directory.GetFiles(folder);
                foreach (String file in files)
                {
                    if (file.IndexOf("\\.svn") == -1)
                    {
                        Add(file, workingcopy);
                    }
                }

            }


            Commit(workingcopy, "change"); 

Add:

    public bool Add(string path, string direccionlocal)
    {
        using (SvnClient client = new SvnClient())
        {
            SvnAddArgs args = new SvnAddArgs();
            args.Depth = SvnDepth.Empty;
            Console.Out.WriteLine(path);
            args.AddParents = true;


            try
            {
                return client.Add(path, args);
            }
            catch (Exception ex)
            {
                return false;
            }

        }
    }

Commit:

    public bool Commit(string path, string message)
    {
        using (SvnCl开发者_JS百科ient client = new SvnClient())
        {
            SvnCommitArgs args = new SvnCommitArgs();


            args.LogMessage = message;
            args.ThrowOnError = true;
            args.ThrowOnCancel = true;

            try
            {
                return client.Commit(path, args);
            }
            catch (Exception e)
            {
                if (e.InnerException != null)
                {
                    throw new Exception(e.InnerException.Message, e);
                }

                throw e;
            }
        }
    }


Did you try something like

using(SvnClient client = new SvnClient())
{
   SvnAddArgs aa = new SvnAddArgs();
   aa.Depth = SvnDepth.Infinity;
   aa.Force = true;

   client.Add(rootDir, aa);
}

for adding the files?

This should all not already added files to your working copy. (Equivalent to svn add --force <dirname>)

It would help if you tell what kind of exception you get. The Subversion libraries can return thousands of different error codes. Most of those have interesting message texts.

SharpSvn nests all specific Subversion errors as inner exceptions. Your code at the end removes the outer exception and looses the stacktrace of the rest of the exception. Using .ToString() on the outer exception should give you the best error text. (And for a similar error output as svn.exe you need to concat all .Messages)

See also this other answer for more suggestions.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号