void ISvnStatusCache.RefreshWCRoot(SvnItem svnItem) { if (svnItem == null) { throw new ArgumentNullException("svnItem"); } Debug.Assert(svnItem.IsDirectory); // We retrieve nesting information by walking the entry data of the parent directory lock (_lock) { string root; try { root = _client.GetWorkingCopyRoot(svnItem.FullPath); } catch { root = null; } if (root == null) { ((ISvnItemUpdate)svnItem).SetState(SvnItemState.None, SvnItemState.IsWCRoot); return; } // Set all nodes between this node and the root to not-a-wcroot ISvnItemUpdate oi; while (root.Length < svnItem.FullPath.Length) { oi = (ISvnItemUpdate)svnItem; oi.SetState(SvnItemState.None, SvnItemState.IsWCRoot); svnItem = svnItem.Parent; if (svnItem == null) { return; } } oi = svnItem; if (svnItem.FullPath == root) { oi.SetState(SvnItemState.IsWCRoot, SvnItemState.None); } else { oi.SetState(SvnItemState.None, SvnItemState.IsWCRoot); } } }
public override string GetDirectoryDotSvn(FilePath path) { string wc_path; try { wc_path = client.GetWorkingCopyRoot(path.FullPath); return(wc_path); } catch (SvnException e) { switch (e.SvnErrorCode) { case SvnErrorCode.SVN_ERR_WC_NOT_WORKING_COPY: case SvnErrorCode.SVN_ERR_WC_NOT_FILE: return(""); } throw; } }
/// <summary> /// Returns the working copy root directory string /// </summary> /// <param name="filePath"></param> /// <returns></returns> public string GetRoot(string filePath) { var workingCopyRoot = _svnClient.GetWorkingCopyRoot(filePath); return(workingCopyRoot); }
private void Window_Loaded(object sender, RoutedEventArgs e) { lbInfo.Content = "一切正常"; String curDir = Directory.GetCurrentDirectory(); String curExe = System.Reflection.Assembly.GetExecutingAssembly().Location; SvnClient = new SvnClient(); SvnTarget svnTargetCurDir = SvnTarget.FromString(curDir); SvnTarget snvTargetCurExe = SvnTarget.FromString(curExe); // 未使用 - 获取目录下的文件状态 Collection<SvnStatusEventArgs> svnStatusEventArgsCollection; SvnClient.GetStatus(Directory.GetCurrentDirectory(), out svnStatusEventArgsCollection); // 未使用 - 空的 Collection<SvnPropertyListEventArgs> svnPropertyListEventArgsCollection; SvnClient.GetPropertyList(Directory.GetCurrentDirectory(), out svnPropertyListEventArgsCollection); // 未使用 - 获取一个文件的状态 Collection<SvnFileVersionEventArgs> svnFileVersionEventArgsCollection; try { SvnClient.GetFileVersions(snvTargetCurExe, out svnFileVersionEventArgsCollection); } catch(SvnWorkingCopyPathNotFoundException ex) { // 如果查询的文件未加入Repo,会抛此异常 } // 未使用 - 一个好像没什么用的信息列表,目录是第一个项,没有版本号 Collection<SvnListEventArgs> svnListEventArgsCollection; SvnClient.GetList(svnTargetCurDir, out svnListEventArgsCollection); // 未使用 - 工作目录全路径 String workingCopyRoot = SvnClient.GetWorkingCopyRoot(Directory.GetCurrentDirectory()); // 未使用 - 整个仓库的最新版本 long revision = 0; SvnClient.Youngest(Directory.GetCurrentDirectory(), out revision); // 此目录的相关变更 和 GUI中的ShowLog一样 是此目录的相关变更 Collection<SvnLogEventArgs> logList; try { SvnClient.GetLog(Directory.GetCurrentDirectory(), out logList); } catch(SvnInvalidNodeKindException ex) { lbInfo.Content = "当前目录不是SVN目录,停用更新检查功能"; btnUpdateAndLaunch.Visibility = Visibility.Hidden; return; } // 获取本地目录信息,当前版本和修改版本都是本地的 SvnInfoEventArgs svnInfoEventArgs; SvnClient.GetInfo(svnTargetCurDir, out svnInfoEventArgs); long curRevision = svnInfoEventArgs.Revision; // 当前的SVN版本 long changeRevision = logList[0].Revision; // 当前目录的最新远程变更版本 lbVersionChange.Content = changeRevision; lbVersionCur.Content = svnInfoEventArgs.Revision; if (curRevision < changeRevision) { btnUpdateAndLaunch.Visibility = Visibility.Visible; lbInfo.Content = "发现新版本"; } else { btnUpdateAndLaunch.Visibility = Visibility.Hidden; lbInfo.Content = "已经是最新版"; } // -------------------------------------------------------- // SvnWorkingCopyClient // -------------------------------------------------------- SvnWorkingCopyClient svnWorkingCopyClient = new SvnWorkingCopyClient(); // 未使用 只有一个值IsText 没看出有什么用处 SvnWorkingCopyState svnWorkingCopyState; svnWorkingCopyClient.GetState(Directory.GetCurrentDirectory(), out svnWorkingCopyState); // 未使用 返回仅本地存在的所有修改版本 SvnWorkingCopyVersion svnWorkingCopyVersion; svnWorkingCopyClient.GetVersion(curDir, out svnWorkingCopyVersion); // -------------------------------------------------------- // SvnTools // -------------------------------------------------------- // 未使用 传入正确的目录却返回false???? bool isCurDirInWorkingCopy = SvnTools.IsManagedPath(curDir); }
public static void CheckoutUpdate(Parameters parameters) { using var client = new SvnClient(); client.Progress += new EventHandler <SvnProgressEventArgs>(Client_Progress); SetUpClient(parameters, client); var target = SvnTarget.FromString(parameters.Path); SvnInfoEventArgs svnInfoEventArgs; SvnUpdateResult svnUpdateResult; var nonExistentUrl = false; EventHandler <SvnErrorEventArgs> ignoreNonexistent = (o, eventArgs) => { nonExistentUrl = false; //if (eventArgs.Exception.SubversionErrorCode == 170000) if (eventArgs.Exception.Message.Contains("non-existent in revision")) { nonExistentUrl = true; eventArgs.Cancel = true; } }; if (client.GetWorkingCopyRoot(parameters.Path) == null) { client.SvnError += ignoreNonexistent; var getInfoSucceeded = client.GetInfo(SvnUriTarget.FromString(parameters.Url), out svnInfoEventArgs); client.SvnError -= ignoreNonexistent; if (!getInfoSucceeded) { if (nonExistentUrl) { Console.WriteLine("SVN info reported nonexistent URL; creating remote directory."); if (!client.RemoteCreateDirectory(new Uri(parameters.Url), new SvnCreateDirectoryArgs { CreateParents = true, LogMessage = parameters.Message })) { throw new Exception("Create directory failed on " + parameters.Url); } } else { throw new Exception("SVN info failed"); } } DebugMessage(parameters, "Checking out"); if (client.CheckOut(SvnUriTarget.FromString(parameters.Url), parameters.Path, out svnUpdateResult)) { DebugMessage(parameters, "Done"); Console.WriteLine("Checked out r" + svnUpdateResult.Revision); return; } throw new Exception("SVN checkout failed"); } if (!client.GetInfo(target, out svnInfoEventArgs)) { throw new Exception("SVN info failed"); } if (!UrlsMatch(svnInfoEventArgs.Uri.ToString(), parameters.Url)) { throw new Exception(string.Format("A different URL is already checked out ({0} != {1})", svnInfoEventArgs.Uri, parameters.Url)); } if (parameters.Cleanup) { DebugMessage(parameters, "Cleaning up"); client.CleanUp(parameters.Path); DebugMessage(parameters, "Done"); } if (parameters.Revert) { DebugMessage(parameters, "Reverting"); client.Revert(parameters.Path); DebugMessage(parameters, "Done"); } if (parameters.DeleteUnversioned) { DebugMessage(parameters, "Deleting unversioned files"); Collection <SvnStatusEventArgs> changedFiles; client.GetStatus(parameters.Path, out changedFiles); foreach (var changedFile in changedFiles) { if (changedFile.LocalContentStatus == SvnStatus.NotVersioned) { if (changedFile.NodeKind == SvnNodeKind.Directory) { DebugMessage(parameters, "NodeKind is directory for [" + changedFile.FullPath + "]"); } if ((File.GetAttributes(changedFile.FullPath) & FileAttributes.Directory) == FileAttributes.Directory) { DebugMessage(parameters, "Deleting directory [" + changedFile.FullPath + "] recursively!"); Directory.Delete(changedFile.FullPath, true); } else { DebugMessage(parameters, "Deleting file [" + changedFile.FullPath + "]"); File.Delete(changedFile.FullPath); } } } DebugMessage(parameters, "Done"); } DebugMessage(parameters, "Updating"); if (client.Update(parameters.Path, out svnUpdateResult)) { DebugMessage(parameters, "Done"); Console.WriteLine("Updated to r" + svnUpdateResult.Revision); return; } throw new Exception("SVN update failed"); }
private void Window_Loaded(object sender, RoutedEventArgs e) { lbInfo.Content = "一切正常"; String curDir = Directory.GetCurrentDirectory(); String curExe = System.Reflection.Assembly.GetExecutingAssembly().Location; SvnClient = new SvnClient(); SvnTarget svnTargetCurDir = SvnTarget.FromString(curDir); SvnTarget snvTargetCurExe = SvnTarget.FromString(curExe); // 未使用 - 获取目录下的文件状态 Collection <SvnStatusEventArgs> svnStatusEventArgsCollection; SvnClient.GetStatus(Directory.GetCurrentDirectory(), out svnStatusEventArgsCollection); // 未使用 - 空的 Collection <SvnPropertyListEventArgs> svnPropertyListEventArgsCollection; SvnClient.GetPropertyList(Directory.GetCurrentDirectory(), out svnPropertyListEventArgsCollection); // 未使用 - 获取一个文件的状态 Collection <SvnFileVersionEventArgs> svnFileVersionEventArgsCollection; try { SvnClient.GetFileVersions(snvTargetCurExe, out svnFileVersionEventArgsCollection); } catch (SvnWorkingCopyPathNotFoundException ex) { // 如果查询的文件未加入Repo,会抛此异常 } // 未使用 - 一个好像没什么用的信息列表,目录是第一个项,没有版本号 Collection <SvnListEventArgs> svnListEventArgsCollection; SvnClient.GetList(svnTargetCurDir, out svnListEventArgsCollection); // 未使用 - 工作目录全路径 String workingCopyRoot = SvnClient.GetWorkingCopyRoot(Directory.GetCurrentDirectory()); // 未使用 - 整个仓库的最新版本 long revision = 0; SvnClient.Youngest(Directory.GetCurrentDirectory(), out revision); // 此目录的相关变更 和 GUI中的ShowLog一样 是此目录的相关变更 Collection <SvnLogEventArgs> logList; try { SvnClient.GetLog(Directory.GetCurrentDirectory(), out logList); } catch (SvnInvalidNodeKindException ex) { lbInfo.Content = "当前目录不是SVN目录,停用更新检查功能"; btnUpdateAndLaunch.Visibility = Visibility.Hidden; return; } // 获取本地目录信息,当前版本和修改版本都是本地的 SvnInfoEventArgs svnInfoEventArgs; SvnClient.GetInfo(svnTargetCurDir, out svnInfoEventArgs); long curRevision = svnInfoEventArgs.Revision; // 当前的SVN版本 long changeRevision = logList[0].Revision; // 当前目录的最新远程变更版本 lbVersionChange.Content = changeRevision; lbVersionCur.Content = svnInfoEventArgs.Revision; if (curRevision < changeRevision) { btnUpdateAndLaunch.Visibility = Visibility.Visible; lbInfo.Content = "发现新版本"; } else { btnUpdateAndLaunch.Visibility = Visibility.Hidden; lbInfo.Content = "已经是最新版"; } // -------------------------------------------------------- // SvnWorkingCopyClient // -------------------------------------------------------- SvnWorkingCopyClient svnWorkingCopyClient = new SvnWorkingCopyClient(); // 未使用 只有一个值IsText 没看出有什么用处 SvnWorkingCopyState svnWorkingCopyState; svnWorkingCopyClient.GetState(Directory.GetCurrentDirectory(), out svnWorkingCopyState); // 未使用 返回仅本地存在的所有修改版本 SvnWorkingCopyVersion svnWorkingCopyVersion; svnWorkingCopyClient.GetVersion(curDir, out svnWorkingCopyVersion); // -------------------------------------------------------- // SvnTools // -------------------------------------------------------- // 未使用 传入正确的目录却返回false???? bool isCurDirInWorkingCopy = SvnTools.IsManagedPath(curDir); }