2010-03-05 45 views
0

我在使用sharpsvn提交時遇到問題。現在我添加我的工作副本的所有文件(如果文件被添加引發異常),並且在它之後我提交。它可以工作,但會導致異常。在添加()之前有一些方法可以獲取存儲庫的狀態,並且只添加新文件或更改的文件?如果我刪除我的工作副本上的一個文件或文件夾,如何刪除這些文件或資料庫上的文件夾? 代碼:提交sharpSVN

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"); 

地址:

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

     } 
    } 

提交:

public bool Commit(string path, string message) 
    { 
     using (SvnClient 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; 
      } 
     } 
    } 

回答

3

你嘗試類似

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

    client.Add(rootDir, aa); 
} 

添加的文件嗎?

這應該都不是已經添加文件到您的工作副本。 (相當於svn add --force <dirname>

如果您知道您得到了什麼樣的異常,這將有所幫助。 Subversion庫可以返回數千個不同的錯誤代碼。大多數人都有有趣的消息文本。

SharpSvn嵌套所有特定的Subversion錯誤作爲內部異常。您的代碼在最後刪除了外部異常,並且丟失了其他異常的堆棧跟蹤。對外部異常使用.ToString()應該會給你最好的錯誤文本。 (對於與svn.exe類似的錯誤輸出,您需要將所有消息連接起來)

另請參閱this other answer以獲取更多建議。

相關問題