private void DoFetchRecentChanges(SvnClient client, SvnStatusArgs sa, List <string> roots, List <SvnStatusEventArgs> resultList, Dictionary <string, string> found) { foreach (string path in roots) { if (IsWorkingCopy(client, path) || !IgnoreStatus(SvnStatus.NotVersioned, SvnStatus.None)) { // TODO: Find some way to get this information safely in the status cache // (Might not be possible because of delays in network check) client.Status(path, sa, delegate(object s, SvnStatusEventArgs stat) { if (IgnoreStatus(stat)) { return; // Not a synchronization item } else if (found.ContainsKey(stat.FullPath)) { return; // Already reported } stat.Detach(); resultList.Add(stat); found.Add(stat.FullPath, ""); }); } } }
/// <summary> /// 获取本地Working Copy中某个文件的状态 /// </summary> public static SvnStatusEventArgs GetLocalFileState(string localPath, out SvnException svnException) { Collection <SvnStatusEventArgs> status = new Collection <SvnStatusEventArgs>(); SvnStatusArgs statusArgs = new SvnStatusArgs(); statusArgs.RetrieveAllEntries = true; try { _svnClient.GetStatus(localPath, statusArgs, out status); if (status.Count > 0) { svnException = null; return(status[0]); } else { svnException = new SvnException("未知原因导致无法读取本地文件信息"); return(null); } } catch (SvnException exception) { svnException = exception; return(null); } }
public override IEnumerable <VersionInfo> Status(Repository repo, FilePath path, SvnRevision revision, bool descendDirs, bool changedItemsOnly, bool remoteStatus) { var list = new List <VersionInfo> (); var args = new SvnStatusArgs(); args.Revision = GetRevision(revision); args.Depth = descendDirs ? SvnDepth.Infinity : SvnDepth.Children; args.RetrieveAllEntries = !changedItemsOnly; args.RetrieveRemoteStatus = remoteStatus; lock (client) { try { client.Status(path, args, (o, a) => list.Add(CreateVersionInfo(repo, a))); } catch (SvnInvalidNodeKindException e) { if (e.SvnErrorCode == SvnErrorCode.SVN_ERR_WC_NOT_WORKING_COPY) { list.Add(VersionInfo.CreateUnversioned(e.File, true)); } else if (e.SvnErrorCode == SvnErrorCode.SVN_ERR_WC_NOT_FILE) { list.Add(VersionInfo.CreateUnversioned(e.File, false)); } else { throw; } } } return(list); }
public bool Commit() { Console.WriteLine("开始检查是否需要提交新参数表..."); SvnCommitArgs ca = new SvnCommitArgs(); SvnStatusArgs sa = new SvnStatusArgs(); Collection<SvnStatusEventArgs> statuses; SC.GetStatus(GetAppLoc(), sa, out statuses); int i = 0; foreach (var item in statuses) { if (item.LocalContentStatus != item.RemoteContentStatus) { i++; } if (!item.Versioned) { SC.Add(item.FullPath); Console.WriteLine("新增加文件" + item.FullPath); i++; } else if (item.Conflicted) { SC.Resolve(item.FullPath, SvnAccept.Working); Console.WriteLine("处理冲突文件" + item.FullPath); } else if (item.IsRemoteUpdated) { SC.Update(item.FullPath); Console.WriteLine("处理冲突文件" + item.FullPath); } else if (item.LocalContentStatus == SvnStatus.Missing) { SC.Delete(item.FullPath); Console.WriteLine("处理丢失文件" + item.FullPath); i++; } } if (i > 0) { ca.LogMessage = ""; SvnCommitResult scr; if (SC.Commit(GetAppLoc(), ca, out scr)) { Console.WriteLine("提交完成"); } else { Console.WriteLine("提交失败"); } } else { Console.WriteLine("无变化,无需检查"); } return true; }
void DoRefresh(bool showProgressDialog) { ISvnSolutionLayout pls = Context.GetService <ISvnSolutionLayout>(); List <SvnStatusEventArgs> resultList = new List <SvnStatusEventArgs>(); List <string> roots = new List <string>(SvnItem.GetPaths(pls.GetUpdateRoots(null))); Dictionary <string, string> found = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); bool refreshFromList = false; try { if (showProgressDialog) { IProgressRunner pr = Context.GetService <IProgressRunner>(); if (pr.RunModal(PCResources.RetrievingRemoteStatus, delegate(object sender, ProgressWorkerArgs e) { SvnStatusArgs sa = new SvnStatusArgs(); sa.RetrieveRemoteStatus = true; DoFetchRecentChanges(e.Client, sa, roots, resultList, found); }).Succeeded) { refreshFromList = true; } } else { ShowBusyIndicator(); using (SvnClient client = Context.GetService <ISvnClientPool>().GetClient()) { SvnStatusArgs sa = new SvnStatusArgs(); sa.RetrieveRemoteStatus = true; // don't throw error // list is cleared in case of an error // show a label in the list view??? sa.ThrowOnError = false; DoFetchRecentChanges(client, sa, roots, resultList, found); refreshFromList = true; } } } finally { if (refreshFromList) { OnRecentChangesFetched(resultList); } if (!showProgressDialog) { HideBusyIndicator(); } } }
/* * This adds, modifies, and removes index entries to match the working tree. */ public bool AddAll() { /* * var startInfo = GetStartInfo("add -A"); * * // add fails if there are no files (directories don't count) * return ExecuteUnless(startInfo, "did not match any files"); */ var overallStatus = true; using (var client = new SvnClient()) { SvnUI.Bind(client, parentWindow); var statusList = (Collection <SvnStatusEventArgs>)null; var svnStatusArgs = new SvnStatusArgs { Depth = SvnDepth.Infinity, IgnoreExternals = false, KeepDepth = false, RetrieveIgnoredEntries = false }; if (client.GetStatus(useSvnStandardDirStructure ? trunkPath : workingCopyPath, svnStatusArgs, out statusList)) { overallStatus = statusList.Select(svnStatusEventArg => { switch (svnStatusEventArg.LocalNodeStatus) { case SvnStatus.Missing: logger.WriteLine("Commit: Deleting file {0} due to status = {1}", svnStatusEventArg.FullPath, svnStatusEventArg.LocalNodeStatus); return(client.Delete(svnStatusEventArg.FullPath, new SvnDeleteArgs { KeepLocal = false, Force = false })); case SvnStatus.NotVersioned: logger.WriteLine("Commit: Adding file {0} due to status = {1}", svnStatusEventArg.FullPath, svnStatusEventArg.LocalNodeStatus); return(client.Add(svnStatusEventArg.FullPath, new SvnAddArgs { AddParents = false, Depth = SvnDepth.Infinity, Force = false })); default: return(true); } }) .Aggregate(true, (state, val) => state &= val); } else { overallStatus = false; } } return(overallStatus); }
public override IEnumerable <VersionInfo> Status(Repository repo, FilePath path, SvnRevision revision, bool descendDirs, bool changedItemsOnly, bool remoteStatus) { List <VersionInfo> list = new List <VersionInfo> (); SvnStatusArgs args = new SvnStatusArgs(); args.Revision = GetRevision(revision); args.Depth = descendDirs ? SvnDepth.Infinity : SvnDepth.Children; args.RetrieveAllEntries = !changedItemsOnly; args.RetrieveRemoteStatus = remoteStatus; client.Status(path, args, delegate(object o, SvnStatusEventArgs a) { list.Add(CreateVersionInfo(repo, a)); }); return(list); }
public void TestCommit() { using (SvnClient client = new SvnClient()) { var localpath = "d:\\sharpsvn\\需求文档\\1.txt"; localpath = "d:\\sharpsvn\\1.txt"; //localpath = @"E:\project\ccms\CCMS_V7_HBYD_R"; var username = "******"; var pwd = "123456"; client.Authentication.DefaultCredentials = new System.Net.NetworkCredential(username, pwd); //如果项目不存在则checkout,否则进行update Console.WriteLine("开始检查是否需要提交新参数表..."); SvnCommitArgs ca = new SvnCommitArgs(); SvnStatusArgs sa = new SvnStatusArgs(); Collection <SvnStatusEventArgs> statuses; client.GetStatus(localpath, sa, out statuses); int i = 0; foreach (var item in statuses) { if (item.LocalContentStatus != item.RemoteContentStatus) { i++; } if (!item.Versioned) { client.Add(item.FullPath); Console.WriteLine("新增加文件" + item.FullPath); i++; } } if (i > 0) { ca.LogMessage = "测试提交文档"; SvnCommitResult clientr; if (client.Commit(localpath, ca, out clientr)) { Console.WriteLine("提交完成"); } else { Console.WriteLine("提交失败"); } } else { Console.WriteLine("无变化,无需检查"); } } }
public void Exception_StatusCrash() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.Default); SvnStatusArgs sa = new SvnStatusArgs(); sa.ThrowOnError = false; sa.RetrieveAllEntries = true; Assert.That(Client.Status(sbox.Wc, sa, delegate(object sender, SvnStatusEventArgs e) { throw new InvalidOperationException(); }), Is.False); Assert.That(sa.LastException.RootCause, Is.InstanceOf(typeof(InvalidOperationException))); }
/// <summary> /// Determines the SVN status of a given path /// </summary> /// <param name="path">The path to check</param> /// <returns>Same character codes as used by svn st</returns> public SvnStatus GetSvnStatus(string path) { SvnStatusArgs sa = new SvnStatusArgs(); sa.Depth = SvnDepth.Empty; sa.AddExpectedError(SvnErrorCode.SVN_ERR_WC_PATH_NOT_FOUND); Collection <SvnStatusEventArgs> results; if (!Client.GetStatus(path, sa, out results) || results.Count != 1) { return(SvnStatus.None); } return(results[0].LocalNodeStatus); }
public void CheckLocalRemoteStatus() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.Default); string WcPath = sbox.Wc; string dir = WcPath; SvnStatusArgs sa = new SvnStatusArgs(); sa.RetrieveRemoteStatus = true; Collection<SvnStatusEventArgs> r; using (SvnClient c = new SvnClient()) { c.GetStatus(dir, sa, out r); } }
/// <summary> /// 工作区与版本库之间修改列表 /// </summary> private void ChangeList() { using (SvnClient client = new SvnClient()) { Collection <SvnStatusEventArgs> statuslist = new Collection <SvnStatusEventArgs>(); SvnStatusArgs args = new SvnStatusArgs(); args.Depth = SvnDepth.Infinity; client.GetStatus(WORKSPACE, out statuslist); foreach (var item in statuslist) { Console.WriteLine(item.Path + " " + item.LocalNodeStatus); } } }
public Status SingleStatus(string filename) { filename = FileUtility.NormalizePath(filename); Status result = null; if (statusCache.TryGetValue(filename, out result)) { Debug("SVN: SingleStatus(" + filename + ") = cached " + result.TextStatus); return(result); } Debug("SVN: SingleStatus(" + filename + ")"); BeforeReadOperation("stat"); try { SvnStatusArgs args = new SvnStatusArgs { Revision = SvnRevision.Working, RetrieveAllEntries = true, RetrieveIgnoredEntries = true, Depth = SvnDepth.Empty }; client.Status( filename, args, delegate(object sender, SvnStatusEventArgs e) { Debug("SVN: SingleStatus.callback(" + e.FullPath + "," + e.LocalContentStatus + ")"); System.Diagnostics.Debug.Assert(filename.ToString().Equals(e.FullPath, StringComparison.OrdinalIgnoreCase)); result = new Status { Copied = e.LocalCopied, TextStatus = ToStatusKind(e.LocalContentStatus) }; } ); if (result == null) { result = new Status { TextStatus = StatusKind.None }; } statusCache.Add(filename, result); return(result); } catch (SvnException ex) { throw new SvnClientException(ex); } finally { AfterOperation(); } }
public CommitFile[] GetChangedFiles(string branchPath) { var changedCommitFiles = new ConcurrentQueue <CommitFile>(); using (var svnClient = new SvnClient()) { var statusArgs = new SvnStatusArgs { Depth = SvnDepth.Infinity, RetrieveAllEntries = true }; Collection <SvnStatusEventArgs> statuses; svnClient.GetStatus(branchPath, statusArgs, out statuses); Parallel.ForEach(statuses, (item) => { if ((item.LocalContentStatus == SvnStatus.Modified || item.LocalContentStatus == SvnStatus.Added) && (item.NodeKind == SvnNodeKind.File) ) { ModifyStatus statusChange = ModifyStatus.Modified; if (item.LocalContentStatus == SvnStatus.Modified) { statusChange = ModifyStatus.Modified; } else if (item.LocalContentStatus == SvnStatus.Added) { statusChange = ModifyStatus.Added; } FileInfo fi = new FileInfo(item.Path); changedCommitFiles.Enqueue(new CommitFile(fi.FullName, fi.Extension, statusChange)); } }); } return(changedCommitFiles.ToArray()); }
public override IEnumerable <VersionInfo> Status(Repository repo, FilePath path, SvnRevision revision, bool descendDirs, bool changedItemsOnly, bool remoteStatus) { if (path == FilePath.Null) { throw new ArgumentNullException(); } var list = new List <VersionInfo> (); var args = new SvnStatusArgs { Revision = GetRevision(revision), Depth = descendDirs ? SvnDepth.Infinity : SvnDepth.Children, RetrieveAllEntries = !changedItemsOnly, RetrieveRemoteStatus = remoteStatus, }; lock (client) { try { client.Status(path, args, (o, a) => list.Add(CreateVersionInfo(repo, a))); } catch (SvnInvalidNodeKindException e) { if (!string.IsNullOrEmpty(e.File)) { if (e.SvnErrorCode == SvnErrorCode.SVN_ERR_WC_NOT_WORKING_COPY) { list.Add(VersionInfo.CreateUnversioned(e.File, true)); } else if (e.SvnErrorCode == SvnErrorCode.SVN_ERR_WC_NOT_FILE) { list.Add(VersionInfo.CreateUnversioned(e.File, false)); } else { throw; } } } catch (SvnWorkingCopyPathNotFoundException e) { list.Add(VersionInfo.CreateUnversioned(e.File, Directory.Exists(e.File))); } } return(list); }
//处理有问题的文件 public void QuestionFile(string path) { // string path = "D:\\Test"; //SvnClient client = new SvnClient(); SvnStatusArgs sa = new SvnStatusArgs(); Collection <SvnStatusEventArgs> status; _client.GetStatus(path, sa, out status); foreach (var item in status) { string fPath = item.FullPath; if (item.LocalContentStatus != item.RemoteContentStatus) { //被修改了的文件 } if (!item.Versioned) { //新增文件 _client.Add(fPath); } else if (item.Conflicted) { //将冲突的文件用工作文件解决冲突 _client.Resolve(fPath, SvnAccept.Working); } else if (item.IsRemoteUpdated) { //更新来自远程的新文件 _client.Update(fPath); } else if (item.LocalContentStatus == SvnStatus.Missing) { //删除丢失的文件 _client.Delete(fPath); } } }
public void TestEntry() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.AnkhSvnCases); string WcPath = sbox.Wc; string form = Path.Combine(WcPath, "Form.cs"); this.RunCommand("svn", "lock " + form); string output = this.RunCommand("svn", "info " + form); Collection<SvnStatusEventArgs> statuses; Client.GetStatus(form, out statuses); //Status s = SingleStatus(client, form); SvnStatusArgs a = new SvnStatusArgs(); this.Client.Status(form, a, delegate(object sender, SvnStatusEventArgs e) { }); }
/// <summary> /// While the server isn't up to date /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void doSvnUpdate(object sender, DoWorkEventArgs e) { client = new SvnClient(); client.Notify += onSvnNotify; client.Authentication.Clear(); client.Authentication.DefaultCredentials = null; System.Console.Out.WriteLine(client.GetUriFromWorkingCopy(System.IO.Directory.GetCurrentDirectory())); Uri rep = client.GetUriFromWorkingCopy(System.IO.Directory.GetCurrentDirectory()); Uri rel = new Uri("http://subversion.assembla.com/svn/skyrimonlineupdate/"); if (rep == null || rep != rel) { SvnDelete.findSvnDirectories(System.IO.Directory.GetCurrentDirectory()); exploreDirectory(rel); download.Maximum = iCount; updating = true; SvnCheckOutArgs args = new SvnCheckOutArgs(); args.AllowObstructions = true; if (client.CheckOut(rel, System.IO.Directory.GetCurrentDirectory(), args, out mResult)) { updated = true; } } else { downloadprogress.Text = "Building update list, please be patient..."; updating = true; SvnStatusArgs sa = new SvnStatusArgs(); sa.RetrieveRemoteStatus = true; Collection <SvnStatusEventArgs> r; client.GetStatus(System.IO.Directory.GetCurrentDirectory(), sa, out r); foreach (SvnStatusEventArgs i in r) { client.Revert(i.FullPath); if (i.IsRemoteUpdated) { iCount++; } } download.Maximum = iCount; SvnUpdateArgs args = new SvnUpdateArgs(); args.AllowObstructions = true; if (client.Update(System.IO.Directory.GetCurrentDirectory(), args)) { updated = true; } else { Application.Exit(); } } }
public void Status_LocalStatus() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.AnkhSvnCases); string WcPath = sbox.Wc; string unversioned = CreateTextFile(WcPath, "unversioned.cs"); string added = CreateTextFile(WcPath, "added.cs"); this.RunCommand("svn", "add " + added); string changed = CreateTextFile(WcPath, "Form.cs"); string ignored = CreateTextFile(WcPath, "foo.ignored"); string propChange = Path.Combine(WcPath, "App.ico"); this.RunCommand("svn", "ps foo bar " + propChange); this.RunCommand("svn", "ps svn:ignore *.ignored " + WcPath); SvnStatusArgs a = new SvnStatusArgs(); a.Depth = SvnDepth.Empty; Client.Status(unversioned, a, delegate(object sender, SvnStatusEventArgs e) { Assert.That(SvnStatus.NotVersioned, Is.EqualTo(e.LocalContentStatus), "Wrong text status on " + unversioned); Assert.That(string.Compare(unversioned, e.Path, true) == 0, "Unversioned filenames don't match"); }); Client.Status(added, a, delegate(object sender, SvnStatusEventArgs e) { Assert.That(SvnStatus.Added, Is.EqualTo(e.LocalContentStatus), "Wrong text status on " + added); Assert.That(string.Compare(added, e.Path, true) == 0, "Added filenames don't match"); }); Client.Status(changed, a, delegate(object sender, SvnStatusEventArgs e) { Assert.That(SvnStatus.Modified, Is.EqualTo(e.LocalContentStatus), "Wrong text status " + changed); Assert.That(string.Compare(changed, e.Path, true) == 0, "Changed filenames don't match"); }); Client.Status(propChange, a, delegate(object sender, SvnStatusEventArgs e) { Assert.That(SvnStatus.Modified, Is.EqualTo(e.LocalPropertyStatus), "Wrong property status " + propChange); Assert.That(string.Compare(propChange, e.Path, true) == 0, "Propchanged filenames don't match"); }); a.RetrieveAllEntries = true; Client.Status(ignored, a, delegate(object sender, SvnStatusEventArgs e) { Assert.That(e.LocalContentStatus, Is.EqualTo(SvnStatus.Ignored), "Wrong content status " + ignored); }); }
/// <summary> /// Refreshes the specified path using the specified depth /// </summary> /// <param name="path">A normalized path</param> /// <param name="pathKind"></param> /// <param name="depth"></param> /// <remarks> /// If the path is a file and depth is greater that <see cref="SvnDepth.Empty"/> the parent folder is walked instead. /// /// <para>This method guarantees that after calling it at least one up-to-date item exists /// in the statusmap for <paramref name="path"/>. If we can not find information we create /// an unspecified item /// </para> /// </remarks> void RefreshPath(string path, SvnNodeKind pathKind) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } string walkPath = path; bool walkingDirectory = false; switch (pathKind) { case SvnNodeKind.Directory: walkingDirectory = true; break; case SvnNodeKind.File: walkPath = SvnTools.GetNormalizedDirectoryName(path); walkingDirectory = true; break; default: try { if (File.Exists(path)) // ### Not long path safe { pathKind = SvnNodeKind.File; goto case SvnNodeKind.File; } } catch (PathTooLongException) { /* Fall through */ } break; } SvnStatusArgs args = new SvnStatusArgs(); args.Depth = SvnDepth.Children; args.RetrieveAllEntries = true; args.RetrieveIgnoredEntries = true; args.ThrowOnError = false; lock (_lock) { SvnDirectory directory; ISvnDirectoryUpdate updateDir; SvnItem walkItem; // We get more information for free, lets use that to update other items if (_dirMap.TryGetValue(walkPath, out directory)) { updateDir = directory; updateDir.TickAll(); } else { // No existing directory instance, let's create one updateDir = directory = new SvnDirectory(Context, walkPath); _dirMap[walkPath] = directory; } walkItem = directory.Directory; bool ok; bool statSelf = false; bool noWcAtAll = false; // Don't retry file open/read operations on failure. These would only delay the result // (default number of delays = 100) using (new SharpSvn.Implementation.SvnFsOperationRetryOverride(0)) { ok = _client.Status(walkPath, args, RefreshCallback); } if (!ok) { if (args.LastException != null) { switch (args.LastException.SvnErrorCode) { case SvnErrorCode.SVN_ERR_WC_UNSUPPORTED_FORMAT: if (CommandService != null) { CommandService.PostExecCommand(AnkhCommand.NotifyWcToNew, walkPath); } break; case SvnErrorCode.SVN_ERR_WC_UPGRADE_REQUIRED: _enableUpgrade = true; if (updateDir != null) { updateDir.SetNeedsUpgrade(); } if (!_sendUpgrade && CommandService != null) { _sendUpgrade = true; CommandService.PostExecCommand(AnkhCommand.NotifyUpgradeRequired, walkPath); } break; case SvnErrorCode.SVN_ERR_WC_NOT_WORKING_COPY: // Status only reports this error if there is no ancestor working copy // We should avoid statting all parent directories again for .IsVersionable noWcAtAll = true; break; case SvnErrorCode.SVN_ERR_WC_CLEANUP_REQUIRED: if (updateDir != null) { updateDir.SetNeedsCleanup(); } break; } } statSelf = true; } else if (directory != null) { walkItem = directory.Directory; // Might have changed via casing } if (!statSelf) { if (((ISvnItemUpdate)walkItem).ShouldRefresh()) { statSelf = true; } else if (walkingDirectory && !walkItem.IsVersioned) { statSelf = true; } } if (statSelf) { // Svn did not stat the items for us.. Let's make something up if (walkingDirectory) { StatDirectory(walkPath, directory, noWcAtAll); } else { // Just stat the item passed and nothing else in the Depth.Empty case if (walkItem == null) { string truepath = SvnTools.GetTruePath(walkPath); // Gets the on-disk casing if it exists StoreItem(walkItem = CreateItem(truepath ?? walkPath, (truepath != null) ? NoSccStatus.NotVersioned : NoSccStatus.NotExisting, SvnNodeKind.Unknown)); } else { ((ISvnItemUpdate)walkItem).RefreshTo(walkItem.Exists ? NoSccStatus.NotVersioned : NoSccStatus.NotExisting, SvnNodeKind.Unknown); } } } if (directory != null) { foreach (ISvnItemUpdate item in directory) { if (item.IsItemTicked()) // These items were not found in the stat calls { item.RefreshTo(NoSccStatus.NotExisting, SvnNodeKind.Unknown); } } if (updateDir.ScheduleForCleanup) { ScheduleForCleanup(directory); // Handles removing already deleted items } // We keep them cached for the current command only } SvnItem pathItem; // We promissed to return an updated item for the specified path; check if we updated it if (!_map.TryGetValue(path, out pathItem)) { // We did not; it does not even exist in the cache StoreItem(pathItem = CreateItem(path, NoSccStatus.NotExisting)); if (directory != null) { updateDir.Store(pathItem); ScheduleForCleanup(directory); } } else { ISvnItemUpdate update = pathItem; if (!update.IsStatusClean()) { update.RefreshTo(NoSccStatus.NotExisting, SvnNodeKind.Unknown); // We did not see it in the walker if (directory != null) { ((ISvnDirectoryUpdate)directory).Store(pathItem); ScheduleForCleanup(directory); } } } } }
/// <summary> /// While the server isn't up to date /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void doSvnUpdate(object sender, DoWorkEventArgs e) { client = new SvnClient(); client.Notify += onSvnNotify; client.Authentication.Clear(); client.Authentication.DefaultCredentials = null; System.Console.Out.WriteLine(client.GetUriFromWorkingCopy(System.IO.Directory.GetCurrentDirectory())); Uri rep = client.GetUriFromWorkingCopy(System.IO.Directory.GetCurrentDirectory()); Uri rel = new Uri("http://subversion.assembla.com/svn/skyrimonlineupdate/"); if (rep == null || rep != rel) { SvnDelete.findSvnDirectories(System.IO.Directory.GetCurrentDirectory()); exploreDirectory(rel); download.Maximum = iCount; updating = true; SvnCheckOutArgs args = new SvnCheckOutArgs(); args.AllowObstructions = true; if (client.CheckOut(rel, System.IO.Directory.GetCurrentDirectory(), args, out mResult)) { updated = true; } } else { downloadprogress.Text = "Building update list, please be patient..."; updating = true; SvnStatusArgs sa = new SvnStatusArgs(); sa.RetrieveRemoteStatus = true; Collection<SvnStatusEventArgs> r; client.GetStatus(System.IO.Directory.GetCurrentDirectory(), sa, out r); foreach (SvnStatusEventArgs i in r) { client.Revert(i.FullPath); if (i.IsRemoteUpdated) iCount++; } download.Maximum = iCount; SvnUpdateArgs args = new SvnUpdateArgs(); args.AllowObstructions = true; if (client.Update(System.IO.Directory.GetCurrentDirectory(), args)) { updated = true; } else { Application.Exit(); } } }
private void MaybeRevert(string newName, SvnEntry toBefore) { ThreadHelper.ThrowIfNotOnUIThread(); if (toBefore == null) { return; } SvnInfoArgs ia = new SvnInfoArgs(); SvnInfoEventArgs info = null; ia.ThrowOnError = false; ia.Depth = SvnDepth.Empty; ia.Info += delegate(object sender, SvnInfoEventArgs e) { e.Detach(); info = e; }; if (!Client.Info(newName, ia, null) || info == null) { return; } // Use SvnEntry to peek below the current delete if (toBefore.RepositoryId != info.RepositoryId || toBefore.Uri != info.CopyFromUri || toBefore.Revision != info.CopyFromRevision) { return; } using (MarkIgnoreRecursive(newName)) using (MoveAway(newName)) { SvnRevertArgs ra = new SvnRevertArgs(); ra.Depth = SvnDepth.Empty; ra.ThrowOnError = false; // Do a quick check if we can safely revert with depth infinity using (new SharpSvn.Implementation.SvnFsOperationRetryOverride(0)) { SvnStatusArgs sa = new SvnStatusArgs(); sa.IgnoreExternals = true; sa.ThrowOnError = false; bool modifications = false; if (Client.Status(newName, sa, delegate(object sender, SvnStatusEventArgs e) { if (e.Conflicted || (e.LocalPropertyStatus != SvnStatus.Normal && e.LocalPropertyStatus != SvnStatus.None)) { e.Cancel = modifications = true; } else if (e.FullPath == newName) { return; } switch (e.LocalNodeStatus) { case SvnStatus.None: case SvnStatus.Normal: case SvnStatus.Modified: // Text only change is ok case SvnStatus.Ignored: case SvnStatus.External: case SvnStatus.NotVersioned: break; default: e.Cancel = modifications = true; break; } }) && !modifications) { ra.Depth = SvnDepth.Infinity; } } Client.Revert(newName, ra); } }
void DoRefresh(bool showProgressDialog) { IAnkhProjectLayoutService pls = Context.GetService<IAnkhProjectLayoutService>(); List<SvnStatusEventArgs> resultList = new List<SvnStatusEventArgs>(); List<string> roots = new List<string>(SvnItem.GetPaths(pls.GetUpdateRoots(null))); Dictionary<string, string> found = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); bool refreshFromList = false; try { if (showProgressDialog) { IProgressRunner pr = Context.GetService<IProgressRunner>(); if (pr.RunModal("Retrieving remote status", delegate(object sender, ProgressWorkerArgs e) { SvnStatusArgs sa = new SvnStatusArgs(); sa.RetrieveRemoteStatus = true; DoFetchRecentChanges(e.Client, sa, roots, resultList, found); }).Succeeded) { refreshFromList = true; } } else { ShowBusyIndicator(); using (SvnClient client = Context.GetService<ISvnClientPool>().GetClient()) { SvnStatusArgs sa = new SvnStatusArgs(); sa.RetrieveRemoteStatus = true; // don't throw error // list is cleared in case of an error // show a label in the list view??? sa.ThrowOnError = false; DoFetchRecentChanges(client, sa, roots, resultList, found); refreshFromList = true; } } } finally { if (refreshFromList) { OnRecentChangesFetched(resultList); } if (!showProgressDialog) { HideBusyIndicator(); } } }
static int Main(string[] args) { try { Console.WriteLine("Svn2: {0}", Assembly.GetExecutingAssembly().GetName().Version); if (args.Length < 1) { Usage(); return(-2); } string command = args[0]; if (command == "/?" || command == "-?" || command == "--help") { Usage(); return(-2); } string path = (args.Length == 2) ? Path.GetFullPath(args[1]) : Path.GetFullPath(Environment.CurrentDirectory); SvnClient client = new SvnClient(); switch (command) { case "sync": { SvnStatusArgs statusArgs = new SvnStatusArgs(); statusArgs.Depth = SvnDepth.Infinity; statusArgs.ThrowOnError = true; client.Status(path, statusArgs, new EventHandler <SvnStatusEventArgs>(delegate(object sender, SvnStatusEventArgs e) { switch (e.LocalContentStatus) { case SvnStatus.NotVersioned: Console.WriteLine(" {0} {1}", StatusToChar(e.LocalContentStatus), e.FullPath); if (File.Exists(e.FullPath)) { FileSystem.DeleteFile(e.FullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } else if (Directory.Exists(e.FullPath)) { FileSystem.DeleteDirectory(e.FullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } break; } })); } break; case "cleanup": { Console.WriteLine("Cleaning up {0}", path); SvnCleanUpArgs cleanupArgs = new SvnCleanUpArgs(); cleanupArgs.ThrowOnError = true; cleanupArgs.Notify += new EventHandler <SvnNotifyEventArgs>(delegate(object sender, SvnNotifyEventArgs e) { Console.WriteLine(" L {0}", e.FullPath); }); client.CleanUp(path, cleanupArgs); } break; case "revert": { Console.WriteLine("Reverting {0}", path); SvnRevertArgs revertArgs = new SvnRevertArgs(); revertArgs.Depth = SvnDepth.Infinity; revertArgs.ThrowOnError = true; revertArgs.Notify += new EventHandler <SvnNotifyEventArgs>(delegate(object sender, SvnNotifyEventArgs e) { Console.WriteLine(" R {0}", e.FullPath); }); client.Revert(path, revertArgs); } break; case "status": { SvnStatusArgs statusArgs = new SvnStatusArgs(); statusArgs.Depth = SvnDepth.Infinity; statusArgs.ThrowOnError = true; client.Status(path, statusArgs, new EventHandler <SvnStatusEventArgs>(delegate(object sender, SvnStatusEventArgs e) { Console.WriteLine(" {0} {1}", StatusToChar(e.LocalContentStatus), e.FullPath); })); } break; default: throw new Exception(string.Format("Unsupported '{0}' command", command)); } return(0); } catch (Exception ex) { Console.Error.WriteLine(ex.Message); #if DEBUG Console.Error.WriteLine(ex.StackTrace); #endif return(-1); } }
private static long GetRevision(String path) { if (String.IsNullOrEmpty(path)) return 0; if (!IsWorkingCopy(path)) return 0; long remoteRevision = 0; long localRevision = 0; try { using (SvnClient client = new SvnClient()) { SvnStatusArgs statusargs = new SvnStatusArgs(); statusargs.Depth = SvnDepth.Empty; // Adjust this to check direct files, or (recursive) directories etc statusargs.RetrieveAllEntries = true; statusargs.RetrieveRemoteStatus = true; Collection<SvnStatusEventArgs> statuses; client.GetStatus(path, statusargs, out statuses); remoteRevision = statuses[0].Revision; } } catch (Exception) { Logger.Write("Error while retrieving information from remote repo", LogLevel.Warning); } using (SvnWorkingCopyClient client = new SvnWorkingCopyClient()) { SvnWorkingCopyVersion version; if (client.GetVersion(path, out version)) { if (version.End >= 0) localRevision = version.End; } } if (remoteRevision > localRevision) { Logger.Write("Working copy seems to be out of date", LogLevel.Warning); } return localRevision; }
public void TestStatusResult() { SvnSandBox sbox = new SvnSandBox(this); Uri repos = sbox.CreateRepository(SandBoxRepository.Empty); string dir = sbox.GetTempDir(); SvnStatusArgs sa = new SvnStatusArgs { Depth = SvnDepth.Children, ThrowOnError = false }; Assert.That(Client.Status(dir, sa, null), Is.False); Assert.That(sa.LastException, Is.Not.Null); Assert.That(sa.LastException.SvnErrorCode, Is.EqualTo(SvnErrorCode.SVN_ERR_WC_NOT_WORKING_COPY)); Client.CheckOut(repos, dir); Assert.That(Client.Status(dir, sa, null), Is.True); Assert.That(sa.LastException, Is.Null); Assert.That(Client.Status(Path.Combine(dir, "subdir"), sa, null), Is.True); Assert.That(sa.LastException, Is.Null); Assert.That(Client.Status(Path.Combine(dir, "subdir\\subsubdir"), sa, null), Is.False); Assert.That(sa.LastException.SvnErrorCode, Is.EqualTo(SvnErrorCode.SVN_ERR_WC_PATH_NOT_FOUND)); }
private void GatherSvnInformation( SvnInformation svn ) { using ( var client = new SvnClient() ) { var arg = new SvnStatusArgs() { Revision = new SvnRevision( SvnRevisionType.Working ), Depth = SvnDepth.Empty }; client.Info( WorkingCopy, ( sender, e ) => { svn.Now = DateTime.Now; if ( String.IsNullOrEmpty( svn.Url ) ) svn.Url = e.Uri.AbsoluteUri; svn.CommitRevision = e.Revision; } ); Collection<SvnStatusEventArgs> statuses; arg.Depth = SvnDepth.Infinity; arg.RetrieveAllEntries = true; client.GetStatus( WorkingCopy, arg, out statuses ); foreach ( var item in statuses ) { if ( string.IsNullOrEmpty( svn.RootUrl ) ) svn.RootUrl = item.RepositoryRoot.AbsoluteUri; svn.MinRevision = item.Revision > 0 && ( item.Revision < svn.MinRevision || svn.MinRevision == 0 ) ? item.Revision : svn.MinRevision; svn.MaxRevision = item.Revision > 0 && ( item.Revision > svn.MaxRevision || svn.MaxRevision == 0 ) ? item.Revision : svn.MaxRevision; svn.IsSvnItem = false; switch ( item.LocalNodeStatus ) { case SvnStatus.None: case SvnStatus.NotVersioned: case SvnStatus.Ignored: break; case SvnStatus.External: case SvnStatus.Incomplete: case SvnStatus.Normal: svn.IsSvnItem = true; break; default: svn.IsSvnItem = true; svn.HasModifications = true; break; } switch ( item.LocalPropertyStatus ) { case SvnStatus.None: case SvnStatus.NotVersioned: case SvnStatus.Ignored: break; case SvnStatus.External: case SvnStatus.Incomplete: case SvnStatus.Normal: svn.IsSvnItem = true; break; default: svn.IsSvnItem = true; svn.HasModifications = true; break; } } svn.MixedRevisions = svn.MinRevision != svn.MaxRevision; svn.RevisionRange = String.Format( "{0}:{1}", svn.MinRevision, svn.MaxRevision ); } }
public Status SingleStatus(string filename) { filename = FileUtility.NormalizePath(filename); Status result = null; if (statusCache.TryGetValue(filename, out result)) { Debug("SVN: SingleStatus(" + filename + ") = cached " + result.TextStatus); return result; } Debug("SVN: SingleStatus(" + filename + ")"); BeforeReadOperation("stat"); try { SvnStatusArgs args = new SvnStatusArgs { Revision = SvnRevision.Working, RetrieveAllEntries = true, RetrieveIgnoredEntries = true, Depth = SvnDepth.Empty }; client.Status( filename, args, delegate (object sender, SvnStatusEventArgs e) { Debug("SVN: SingleStatus.callback(" + e.FullPath + "," + e.LocalContentStatus + ")"); System.Diagnostics.Debug.Assert(filename.ToString().Equals(e.FullPath, StringComparison.OrdinalIgnoreCase)); result = new Status { Copied = e.LocalCopied, TextStatus = ToStatusKind(e.LocalContentStatus) }; } ); if (result == null) { result = new Status { TextStatus = StatusKind.None }; } statusCache.Add(filename, result); return result; } catch (SvnException ex) { switch (ex.SvnErrorCode) { case SvnErrorCode.SVN_ERR_WC_UPGRADE_REQUIRED: result = new Status { TextStatus = StatusKind.None }; break; case SvnErrorCode.SVN_ERR_WC_NOT_WORKING_COPY: result = new Status { TextStatus = StatusKind.Unversioned }; break; default: throw new SvnClientException(ex); } statusCache.Add(filename, result); return result; } finally { AfterOperation(); } }
public bool Commit() { Console.WriteLine("开始检查是否需要提交新参数表..."); SvnCommitArgs ca = new SvnCommitArgs(); SvnStatusArgs sa = new SvnStatusArgs(); Collection <SvnStatusEventArgs> statuses; SC.GetStatus(GetAppLoc(), sa, out statuses); int i = 0; foreach(var item in statuses) { if (item.LocalContentStatus != item.RemoteContentStatus) { { i++; } } if (!item.Versioned) { { SC.Add(item.FullPath); Console.WriteLine("新增加文件" + item.FullPath); i++; } } else if (item.Conflicted) { { SC.Resolve(item.FullPath, SvnAccept.Working); Console.WriteLine("处理冲突文件" + item.FullPath); } } else if (item.IsRemoteUpdated) { { SC.Update(item.FullPath); Console.WriteLine("处理冲突文件" + item.FullPath); } } else if (item.LocalContentStatus == SvnStatus.Missing) { { SC.Delete(item.FullPath); Console.WriteLine("处理丢失文件" + item.FullPath); i++; } } } if(i > 0) { ca.LogMessage = ""; SvnCommitResult scr; if (SC.Commit(GetAppLoc(), ca, out scr)) { { Console.WriteLine("提交完成"); } } else { { Console.WriteLine("提交失败"); } } } else { Console.WriteLine("无变化,无需检查"); } return true; }
private void GatherSvnInformation(SvnInformation svn) { Log.LogMessage("Gathering SVN details from " + WorkingCopy); using (var client = new SvnClient()) { var arg = new SvnStatusArgs() { Revision = new SvnRevision(SvnRevisionType.Working), Depth = SvnDepth.Empty }; client.Info(WorkingCopy, (sender, e) => { svn.Now = DateTime.Now; if (String.IsNullOrEmpty(svn.Url)) { svn.Url = e.Uri.AbsoluteUri; } svn.CommitRevision = e.Revision; }); Collection <SvnStatusEventArgs> statuses; arg.Depth = SvnDepth.Infinity; arg.RetrieveAllEntries = true; client.GetStatus(WorkingCopy, arg, out statuses); foreach (var item in statuses) { if (string.IsNullOrEmpty(svn.RootUrl)) { svn.RootUrl = item.RepositoryRoot.AbsoluteUri; } svn.MinRevision = item.Revision > 0 && (item.Revision < svn.MinRevision || svn.MinRevision == 0) ? item.Revision : svn.MinRevision; svn.MaxRevision = item.Revision > 0 && (item.Revision > svn.MaxRevision || svn.MaxRevision == 0) ? item.Revision : svn.MaxRevision; svn.IsSvnItem = false; switch (item.LocalNodeStatus) { case SvnStatus.None: case SvnStatus.NotVersioned: case SvnStatus.Ignored: break; case SvnStatus.External: case SvnStatus.Incomplete: case SvnStatus.Normal: svn.IsSvnItem = true; break; default: svn.IsSvnItem = true; svn.HasModifications = true; break; } switch (item.LocalPropertyStatus) { case SvnStatus.None: case SvnStatus.NotVersioned: case SvnStatus.Ignored: break; case SvnStatus.External: case SvnStatus.Incomplete: case SvnStatus.Normal: svn.IsSvnItem = true; break; default: svn.IsSvnItem = true; svn.HasModifications = true; break; } } svn.MixedRevisions = svn.MinRevision != svn.MaxRevision; svn.RevisionRange = String.Format("{0}:{1}", svn.MinRevision, svn.MaxRevision); } }
public Dictionary<string, Status> MultiStatus(DirectoryInfo directoryInfo) { if (directoryInfo == null) { throw new ArgumentNullException(nameof(directoryInfo)); } var result = new Dictionary<string, Status>(); Debug($@"SVN: {nameof(MultiStatus)}({directoryInfo.FullName})"); BeforeReadOperation("stat"); try { var args = new SvnStatusArgs { Revision = SvnRevision.Working, RetrieveAllEntries = true, RetrieveIgnoredEntries = true, Depth = SvnDepth.Infinity }; _client.Status( directoryInfo.FullName, args, (sender, e) => { Debug($@"SVN: {nameof(MultiStatus)}.callback('{e.FullPath}', {e.LocalContentStatus})"); var status = new Status(ToStatusKind(e.LocalContentStatus), e.LocalCopied); result.Add(e.FullPath, status); }); return result; } catch (SvnException ex) { throw new SvnClientException(ex); } finally { AfterOperation(); } }
/// <summary> /// Refreshes the specified path using the specified depth /// </summary> /// <param name="path">A normalized path</param> /// <param name="pathKind"></param> /// <param name="depth"></param> /// <remarks> /// If the path is a file and depth is greater that <see cref="SvnDepth.Empty"/> the parent folder is walked instead. /// /// <para>This method guarantees that after calling it at least one up-to-date item exists /// in the statusmap for <paramref name="path"/>. If we can not find information we create /// an unspecified item /// </para> /// </remarks> void RefreshPath(string path, SvnNodeKind pathKind) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } var walkPath = path; var walkingDirectory = false; switch (pathKind) { case SvnNodeKind.Directory: walkingDirectory = true; break; case SvnNodeKind.File: walkPath = SvnTools.GetNormalizedDirectoryName(path); walkingDirectory = true; break; default: try { if (File.Exists(path)) // ### Not long path safe { pathKind = SvnNodeKind.File; goto case SvnNodeKind.File; } } catch (PathTooLongException) { /* Fall through */ } break; } var args = new SvnStatusArgs(); args.Depth = SvnDepth.Children; args.RetrieveAllEntries = true; args.RetrieveIgnoredEntries = true; args.ThrowOnError = false; lock (_lock) { ISvnDirectoryUpdate updateDir; SvnItem walkItem = null; // We get more information for free, lets use that to update other items DirectoryMap.TryGetValue(walkPath, out var directory); if (null != directory) { updateDir = directory; updateDir.TickAll(); } else { // No existing directory instance, let's create one directory = new SvnDirectory(walkPath); updateDir = directory = GetDirectory(walkPath); DirectoryMap[walkPath] = directory; } bool ok; var statSelf = false; var noWcAtAll = false; // Don't retry file open/read operations on failure. These would only delay the result // (default number of delays = 100) using (new SharpSvn.Implementation.SvnFsOperationRetryOverride(0)) { ok = _client.Status(walkPath, args, RefreshCallback); } if (directory != null) { walkItem = directory.Directory; // Might have changed via casing } if (!statSelf && null != walkItem) { if (((ISvnItemUpdate)walkItem).ShouldRefresh()) { statSelf = true; } else if (walkingDirectory && !walkItem.IsVersioned) { statSelf = true; } } if (statSelf) { // Svn did not stat the items for us.. Let's make something up if (walkingDirectory) { StatDirectory(walkPath, directory, noWcAtAll); } else { // Just stat the item passed and nothing else in the Depth.Empty case if (walkItem == null) { var truepath = SvnTools.GetTruePath(walkPath); // Gets the on-disk casing if it exists StoreItem(walkItem = CreateItem(truepath ?? walkPath, (truepath != null) ? NoSccStatus.NotVersioned : NoSccStatus.NotExisting, SvnNodeKind.Unknown)); } else { ((ISvnItemUpdate)walkItem).RefreshTo(walkItem.Exists ? NoSccStatus.NotVersioned : NoSccStatus.NotExisting, SvnNodeKind.Unknown); } } } if (directory != null) { foreach (ISvnItemUpdate item in directory) { if (item.IsItemTicked()) // These items were not found in the stat calls { item.RefreshTo(NoSccStatus.NotExisting, SvnNodeKind.Unknown); } } if (updateDir.ScheduleForCleanup) { ScheduleForCleanup(directory); // Handles removing already deleted items } // We keep them cached for the current command only } SvnItem pathItem; // We promissed to return an updated item for the specified path; check if we updated it if (!Map.TryGetValue(path, out pathItem)) { // We did not; it does not even exist in the cache StoreItem(pathItem = CreateItem(path, NoSccStatus.NotExisting)); if (directory != null) { updateDir.Store(pathItem); ScheduleForCleanup(directory); } } else { ISvnItemUpdate update = pathItem; if (!update.IsStatusClean()) { update.RefreshTo(NoSccStatus.NotExisting, SvnNodeKind.Unknown); // We did not see it in the walker if (directory != null) { ((ISvnDirectoryUpdate)directory).Store(pathItem); ScheduleForCleanup(directory); } } } } }
public override IEnumerable<VersionInfo> Status (Repository repo, FilePath path, SvnRevision revision, bool descendDirs, bool changedItemsOnly, bool remoteStatus) { List<VersionInfo> list = new List<VersionInfo> (); SvnStatusArgs args = new SvnStatusArgs (); args.Revision = GetRevision (revision); args.Depth = descendDirs ? SvnDepth.Infinity : SvnDepth.Children; args.RetrieveAllEntries = !changedItemsOnly; args.RetrieveRemoteStatus = remoteStatus; lock (client) { try { client.Status (path, args, delegate (object o, SvnStatusEventArgs a) { list.Add (CreateVersionInfo (repo, a)); }); } catch (SvnInvalidNodeKindException e) { if (e.SvnErrorCode == SvnErrorCode.SVN_ERR_WC_NOT_WORKING_COPY) list.Add (VersionInfo.CreateUnversioned (e.File, true)); else if (e.SvnErrorCode == SvnErrorCode.SVN_ERR_WC_NOT_FILE) list.Add (VersionInfo.CreateUnversioned (e.File, false)); else throw; } } return list; }
/* * This adds, modifies, and removes index entries to match the working tree. */ public bool AddAll() { /* var startInfo = GetStartInfo("add -A"); // add fails if there are no files (directories don't count) return ExecuteUnless(startInfo, "did not match any files"); */ var overallStatus = true; using (var client = new SvnClient()) { SvnUI.Bind(client, parentWindow); var statusList = (Collection<SvnStatusEventArgs>)null; var svnStatusArgs = new SvnStatusArgs { Depth = SvnDepth.Infinity, IgnoreExternals = false, KeepDepth = false, RetrieveIgnoredEntries = false }; if (client.GetStatus(useSvnStandardDirStructure ? trunkPath : workingCopyPath, svnStatusArgs, out statusList)) { overallStatus = statusList.Select(svnStatusEventArg => { switch (svnStatusEventArg.LocalNodeStatus) { case SvnStatus.Missing: logger.WriteLine("Commit: Deleting file {0} due to status = {1}", svnStatusEventArg.FullPath, svnStatusEventArg.LocalNodeStatus); return client.Delete(svnStatusEventArg.FullPath, new SvnDeleteArgs { KeepLocal = false, Force = false }); case SvnStatus.NotVersioned: logger.WriteLine("Commit: Adding file {0} due to status = {1}", svnStatusEventArg.FullPath, svnStatusEventArg.LocalNodeStatus); return client.Add(svnStatusEventArg.FullPath, new SvnAddArgs { AddParents = false, Depth = SvnDepth.Infinity, Force = false }); default: return true; } }) .Aggregate(true, (state, val) => state &= val); } else overallStatus = false; } return overallStatus; }
public override void OnExecute(CommandEventArgs e) { List <SvnItem> toRevert = new List <SvnItem>(); HybridCollection <string> contained = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase); HybridCollection <string> checkedItems = null; foreach (SvnItem i in e.Selection.GetSelectedSvnItems(false)) { if (contained.Contains(i.FullPath)) { continue; } contained.Add(i.FullPath); if (i.IsModified || (i.IsVersioned && i.IsDocumentDirty) || i.IsConflicted) { toRevert.Add(i); } } Predicate <SvnItem> initialCheckedFilter = null; if (toRevert.Count > 0) { checkedItems = new HybridCollection <string>(contained, StringComparer.OrdinalIgnoreCase); initialCheckedFilter = delegate(SvnItem item) { return(checkedItems.Contains(item.FullPath)); }; } foreach (SvnItem i in e.Selection.GetSelectedSvnItems(true)) { if (contained.Contains(i.FullPath)) { continue; } contained.Add(i.FullPath); if (i.IsModified || (i.IsVersioned && i.IsDocumentDirty)) { toRevert.Add(i); } } if (e.PromptUser || (!e.DontPrompt && !Shift)) { using (PendingChangeSelector pcs = new PendingChangeSelector()) { pcs.Text = CommandStrings.RevertDialogTitle; pcs.PreserveWindowPlacement = true; pcs.LoadItems(toRevert, null, initialCheckedFilter); if (pcs.ShowDialog(e.Context) != DialogResult.OK) { return; } toRevert.Clear(); toRevert.AddRange(pcs.GetSelectedItems()); } } IAnkhOpenDocumentTracker documentTracker = e.GetService <IAnkhOpenDocumentTracker>(); ICollection <string> revertPaths = SvnItem.GetPaths(toRevert); documentTracker.SaveDocuments(revertPaths); // Revert items backwards to make sure we revert children before their ancestors toRevert.Sort(delegate(SvnItem i1, SvnItem i2) { bool add1 = i1.IsAdded || i1.IsReplaced; bool add2 = i2.IsAdded || i2.IsReplaced; if (add1 && !add2) { return(-1); } else if (add2 && !add1) { return(1); } else if (add1 && add2) { return(-StringComparer.OrdinalIgnoreCase.Compare(i1.FullPath, i2.FullPath)); } return(StringComparer.OrdinalIgnoreCase.Compare(i1.FullPath, i2.FullPath)); }); // perform the actual revert using (DocumentLock dl = documentTracker.LockDocuments(revertPaths, DocumentLockType.NoReload)) using (dl.MonitorChangesForReload()) { e.GetService <IProgressRunner>().RunModal(CommandStrings.Reverting, delegate(object sender, ProgressWorkerArgs a) { SvnRevertArgs ra = new SvnRevertArgs(); ra.AddExpectedError(SvnErrorCode.SVN_ERR_WC_NOT_DIRECTORY, SvnErrorCode.SVN_ERR_WC_INVALID_OPERATION_DEPTH); // Parent revert invalidated this change ra.Depth = SvnDepth.Empty; List <SvnItem> toRevertWithInfinity = new List <SvnItem>(); foreach (SvnItem item in toRevert) { if (!a.Client.Revert(item.FullPath, ra)) { switch (ra.LastException.SvnErrorCode) { case SvnErrorCode.SVN_ERR_WC_INVALID_OPERATION_DEPTH: toRevertWithInfinity.Add(item); break; } } } ra = new SvnRevertArgs(); ra.AddExpectedError(SvnErrorCode.SVN_ERR_WC_NOT_DIRECTORY); ra.Depth = SvnDepth.Infinity; foreach (SvnItem item in toRevertWithInfinity) { SvnStatusArgs sa = new SvnStatusArgs(); sa.RetrieveIgnoredEntries = false; sa.IgnoreExternals = true; sa.ThrowOnError = false; bool modifications = false; using (new SharpSvn.Implementation.SvnFsOperationRetryOverride(0)) { if (!a.Client.Status(item.FullPath, sa, delegate(object ss, SvnStatusEventArgs ee) { if (ee.FullPath == item.FullPath) { return; } if (ee.Conflicted || (ee.LocalPropertyStatus != SvnStatus.Normal && ee.LocalPropertyStatus != SvnStatus.None)) { ee.Cancel = modifications = true; } else { switch (ee.LocalNodeStatus) { case SvnStatus.None: case SvnStatus.Normal: case SvnStatus.Ignored: case SvnStatus.External: case SvnStatus.NotVersioned: break; default: ee.Cancel = modifications = true; break; } } })) { modifications = true; } } if (!modifications) { a.Client.Revert(item.FullPath, ra); } } }); } }
private void DoFetchRecentChanges(SvnClient client, SvnStatusArgs sa, List<string> roots, List<SvnStatusEventArgs> resultList, Dictionary<string, string> found) { foreach (string path in roots) { // TODO: Find some way to get this information safely in the status cache // (Might not be possible because of delays in network check) client.Status(path, sa, delegate(object s, SvnStatusEventArgs stat) { if (IgnoreStatus(stat)) return; // Not a synchronization item else if (found.ContainsKey(stat.FullPath)) return; // Already reported stat.Detach(); resultList.Add(stat); found.Add(stat.FullPath, ""); }); } }
public void MoreStatusTestsObsolete() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.AnkhSvnCases, false); string WcPath = sbox.Wc; Uri ReposUrl = sbox.RepositoryUri; using (SvnClient client = NewSvnClient(true, false)) { client.Update(WcPath); client.CreateDirectory(Path.Combine(WcPath, "statTst")); string local = Path.Combine(WcPath, "statTst/LocalStatBase1"); string local2 = Path.Combine(WcPath, "statTst/LocalStatBase2"); string local3 = Path.Combine(WcPath, "statTst/LocalStatBase3"); string local4 = Path.Combine(WcPath, "statTst/LocalStatBase4"); string local5 = Path.Combine(WcPath, "statTst/LocalStatBase5"); string local6 = Path.Combine(WcPath, "statTst/LocalStatBase6"); SvnCommitResult ci, ci9; Touch2(local); client.Add(local); client.Commit(WcPath, out ci); client.Copy(local, local2); client.Commit(WcPath); client.SetProperty(local, "test-q", "value"); client.Copy(local, local3); client.Copy(local, local6); client.Copy(local, local5); client.Commit(WcPath, out ci9); client.Copy(local, local4); client.Delete(local5); client.SetProperty(local, "test-q", "value2"); client.RemoteDelete(new Uri(ReposUrl, "statTst/LocalStatBase2")); client.AddToChangeList(local6, "MyList"); Touch2(local6); Guid reposGuid; client.TryGetRepositoryId(ReposUrl, out reposGuid); for (int mode = 0; mode < 4; mode++) { SvnStatusArgs a = new SvnStatusArgs(); a.RetrieveRemoteStatus = mode % 2 == 1; a.RetrieveAllEntries = mode > 1; int n = 0; client.Status(Path.Combine(WcPath, "statTst"), a, delegate(object sender, SvnStatusEventArgs e) { n++; string p = e.Path; int nn = -1; switch (e.Path[e.Path.Length - 1]) { case '1': nn = 1; break; case '2': nn = 2; break; case '3': nn = 3; break; case '4': nn = 4; break; case '5': nn = 5; break; case '6': nn = 6; break; default: Assert.That(e.FullPath, Is.EqualTo(Path.GetDirectoryName(local))); break; } if (nn >= 0) Assert.That(Path.GetDirectoryName(e.FullPath), Is.EqualTo(Path.Combine(WcPath, "statTst"))); Assert.That(Path.GetFileName(e.Path), Is.EqualTo(Path.GetFileName(e.FullPath))); switch (nn) { case 1: Assert.That(e.LocalNodeStatus, Is.EqualTo(SvnStatus.Modified)); Assert.That(e.LocalTextStatus, Is.EqualTo(SvnStatus.Normal)); Assert.That(e.LocalPropertyStatus, Is.EqualTo(SvnStatus.Modified)); break; case 2: Assert.That(e.LocalNodeStatus, Is.EqualTo(SvnStatus.Normal)); Assert.That(e.LocalTextStatus, Is.EqualTo(SvnStatus.Normal)); Assert.That(e.LocalPropertyStatus, Is.EqualTo(SvnStatus.None)); break; case 3: Assert.That(e.LocalNodeStatus, Is.EqualTo(SvnStatus.Normal)); Assert.That(e.LocalTextStatus, Is.EqualTo(SvnStatus.Normal)); Assert.That(e.LocalPropertyStatus, Is.EqualTo(SvnStatus.Normal)); break; case 4: Assert.That(e.LocalNodeStatus, Is.EqualTo(SvnStatus.Added)); Assert.That(e.LocalTextStatus, Is.EqualTo(SvnStatus.Normal)); Assert.That(e.LocalPropertyStatus, Is.EqualTo(SvnStatus.Normal)); break; case 5: Assert.That(e.LocalNodeStatus, Is.EqualTo(SvnStatus.Deleted)); Assert.That(e.LocalTextStatus, Is.EqualTo(SvnStatus.Normal)); Assert.That(e.LocalPropertyStatus, Is.EqualTo(SvnStatus.None)); break; case 6: Assert.That(e.LocalNodeStatus, Is.EqualTo(SvnStatus.Modified)); Assert.That(e.LocalTextStatus, Is.EqualTo(SvnStatus.Modified)); Assert.That(e.LocalPropertyStatus, Is.EqualTo(SvnStatus.Normal)); break; default: break; } Assert.That(e.LocalCopied, Is.EqualTo(nn == 4)); Assert.That(e.Wedged, Is.False); if (a.RetrieveRemoteStatus) { Assert.That(e.RemoteContentStatus, Is.EqualTo(nn == 2 ? SvnStatus.Deleted : SvnStatus.None)); } else { Assert.That(e.RemoteContentStatus, Is.EqualTo(SvnStatus.None)); } Assert.That(e.RemoteLock, Is.Null); Assert.That(e.RemotePropertyStatus, Is.EqualTo(SvnStatus.None)); if (nn == 2 && a.RetrieveRemoteStatus) { Assert.That(e.RemoteUpdateCommitAuthor, Is.Null); Assert.That(e.RemoteUpdateNodeKind, Is.EqualTo(SvnNodeKind.File)); Assert.That(e.RemoteUpdateCommitTime, Is.EqualTo(DateTime.MinValue)); Assert.That(e.RemoteUpdateRevision, Is.EqualTo(ci.Revision + 3)); } else if (nn == -1 && a.RetrieveRemoteStatus) { Assert.That(e.RemoteUpdateCommitAuthor, Is.EqualTo(Environment.UserName)); Assert.That(e.RemoteUpdateNodeKind, Is.EqualTo(SvnNodeKind.Directory)); Assert.That(e.RemoteUpdateCommitTime, Is.GreaterThan(DateTime.UtcNow - new TimeSpan(0, 45, 0))); Assert.That(e.RemoteUpdateRevision, Is.EqualTo(ci.Revision + 3)); } else { Assert.That(e.RemoteUpdateCommitAuthor, Is.Null); Assert.That(e.RemoteUpdateNodeKind, Is.EqualTo(SvnNodeKind.None)); Assert.That(e.RemoteUpdateCommitTime, Is.EqualTo(DateTime.MinValue)); Assert.That(e.RemoteUpdateRevision, Is.LessThan(0L)); } Assert.That(e.Switched, Is.False); if (nn >= 0) Assert.That(e.Uri, Is.EqualTo(new Uri(ReposUrl, "statTst/localStatBase" + nn.ToString()))); else Assert.That(e.Uri, Is.EqualTo(new Uri(ReposUrl, "statTst/"))); Assert.That(e.WorkingCopyInfo, Is.Not.Null); if (nn >= 0) Assert.That(e.WorkingCopyInfo.Name, Is.EqualTo(Path.GetFileName(e.Path))); else Assert.That(e.WorkingCopyInfo.Name, Is.EqualTo("")); Assert.That(e.WorkingCopyInfo.ChangeList, Is.EqualTo((nn == 6) ? "MyList" : null)); if (nn >= 0) Assert.That(e.WorkingCopyInfo.Checksum, Is.Not.Null); Assert.That(e.WorkingCopyInfo.Uri, Is.EqualTo(e.Uri)); Assert.That(e.WorkingCopyInfo.RepositoryUri, Is.EqualTo(ReposUrl)); /*if(a.ContactRepository) Assert.That(e.WorkingCopyInfo.RepositoryId, Is.EqualTo(reposGuid)); else*/ Assert.That(e.WorkingCopyInfo.RepositoryId, Is.Not.EqualTo(Guid.Empty), "Expected guid for {0} / nn={1}", e.Path, nn); Assert.That(e.WorkingCopyInfo.IsAbsent, Is.False); Assert.That(e.WorkingCopyInfo.IsDeleted, Is.False); Assert.That(e.WorkingCopyInfo.IsIncomplete, Is.False); // Assert.That(e.WorkingCopyInfo.ConflictNewFile, Is.Null); Assert.That(e.WorkingCopyInfo.ConflictOldFile, Is.Null); Assert.That(e.WorkingCopyInfo.ConflictWorkFile, Is.Null); if (nn == 4) { Assert.That(e.WorkingCopyInfo.IsCopy, Is.True); Assert.That(e.WorkingCopyInfo.CopiedFrom, Is.EqualTo(new Uri(ReposUrl, "statTst/localStatBase1"))); Assert.That(e.WorkingCopyInfo.LastChangeAuthor, Is.Not.Null); Assert.That(e.WorkingCopyInfo.CopiedFromRevision, Is.EqualTo(ci.Revision + 2)); } else { Assert.That(e.WorkingCopyInfo.IsCopy, Is.False); Assert.That(e.WorkingCopyInfo.CopiedFrom, Is.Null); Assert.That(e.WorkingCopyInfo.LastChangeAuthor, Is.EqualTo(Environment.UserName)); Assert.That(e.WorkingCopyInfo.CopiedFromRevision, Is.EqualTo(-1L)); } Assert.That(e.WorkingCopyInfo.Depth, Is.EqualTo(SvnDepth.Infinity)); Assert.That(e.WorkingCopyInfo.HasProperties, Is.EqualTo(nn >= 0 && nn != 2)); Assert.That(e.WorkingCopyInfo.HasPropertyChanges, Is.EqualTo(nn == 1), "Expected property changes (nn={0})", nn); Assert.That(e.WorkingCopyInfo.KeepLocal, Is.False); if (nn == 4) { Assert.That(e.WorkingCopyInfo.LastChangeRevision, Is.EqualTo(9)); Assert.That(e.WorkingCopyInfo.LastChangeTime, Is.GreaterThan(DateTime.MinValue)); Assert.That(e.WorkingCopyInfo.Schedule, Is.EqualTo(SvnSchedule.Add)); Assert.That(e.WorkingCopyInfo.ContentChangeTime, Is.GreaterThan(DateTime.MinValue)); Assert.That(e.WorkingCopyInfo.Revision, Is.EqualTo(ci.Revision)); Assert.That(e.WorkingCopyInfo.WorkingCopySize, Is.EqualTo(36)); } else { switch (nn) { case 2: Assert.That(e.WorkingCopyInfo.LastChangeRevision, Is.EqualTo(ci.Revision + 1)); Assert.That(e.WorkingCopyInfo.Revision, Is.EqualTo(ci.Revision + 1)); break; default: Assert.That(e.WorkingCopyInfo.LastChangeRevision, Is.EqualTo((nn >= 0) ? (ci.Revision + 2) : ci.Revision)); Assert.That(e.WorkingCopyInfo.Revision, Is.EqualTo((nn >= 0) ? (ci.Revision + 2) : ci.Revision)); break; } Assert.That(e.WorkingCopyInfo.LastChangeTime, Is.GreaterThan(DateTime.UtcNow - new TimeSpan(0, 0, 45))); Assert.That(e.WorkingCopyInfo.Schedule, Is.EqualTo((nn == 5) ? SvnSchedule.Delete : SvnSchedule.Normal)); if (nn == 5) { // Deleted node } else if (nn >= 0) { Assert.That(e.WorkingCopyInfo.ContentChangeTime, Is.GreaterThan(DateTime.UtcNow - new TimeSpan(0, 0, 45))); Assert.That(e.WorkingCopyInfo.WorkingCopySize, Is.EqualTo(36L), "WCSize = 36"); } else { Assert.That(e.WorkingCopyInfo.NodeKind, Is.EqualTo(SvnNodeKind.Directory)); Assert.That(e.WorkingCopyInfo.ContentChangeTime, Is.EqualTo(DateTime.MinValue)); Assert.That(e.WorkingCopyInfo.WorkingCopySize, Is.EqualTo(-1L), "WCSize = -1"); } } Assert.That(e.WorkingCopyInfo.LockComment, Is.Null); Assert.That(e.WorkingCopyInfo.LockOwner, Is.Null); Assert.That(e.WorkingCopyInfo.LockTime, Is.EqualTo(DateTime.MinValue)); Assert.That(e.WorkingCopyInfo.LockToken, Is.Null); Assert.That(e.WorkingCopyInfo.NodeKind, Is.EqualTo(nn >= 0 ? SvnNodeKind.File : SvnNodeKind.Directory)); Assert.That(e.WorkingCopyInfo.PropertyRejectFile, Is.Null); }); if (a.RetrieveAllEntries) Assert.That(n, Is.EqualTo(7)); else if (a.RetrieveRemoteStatus) Assert.That(n, Is.EqualTo(5)); else Assert.That(n, Is.EqualTo(4)); } File.Delete(local); client.Status(local, delegate(object sender, SvnStatusEventArgs e) { Assert.That(e.WorkingCopyInfo.IsAbsent, Is.False); Assert.That(e.WorkingCopyInfo.IsIncomplete, Is.False); Assert.That(e.WorkingCopyInfo.IsDeleted, Is.False); Assert.That(e.LocalContentStatus, Is.EqualTo(SvnStatus.Missing)); }); SvnDeleteArgs da = new SvnDeleteArgs(); da.Force = true; client.Delete(local, da); client.Status(local, delegate(object sender, SvnStatusEventArgs e) { Assert.That(e.WorkingCopyInfo.IsAbsent, Is.False); Assert.That(e.WorkingCopyInfo.IsIncomplete, Is.False); Assert.That(e.WorkingCopyInfo.IsDeleted, Is.False); Assert.That(e.LocalContentStatus, Is.EqualTo(SvnStatus.Deleted)); }); } }
public void CheckOverrideWorking() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.Empty); string tmp2Dir = sbox.Wc; StringBuilder lotOfData = new StringBuilder(); lotOfData.Append('Y', 1024 * 1024); string file2 = Path.Combine(tmp2Dir, "File-2"); File.WriteAllText(file2, lotOfData.ToString()); Client.Add(file2); Client.Configuration.LogMessageRequired = false; Client.Commit(file2); lotOfData = new StringBuilder(); lotOfData.Append('Y', 512 * 1024); lotOfData.Append('Z', 512 * 1024); File.WriteAllText(file2, lotOfData.ToString()); using (FileStream fs2 = new FileStream(file2, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) { SvnStatusArgs sa = new SvnStatusArgs(); sa.ThrowOnError = false; TimeSpan t2; DateTime start; using (new MyFsOverride()) { start = DateTime.Now; Client.Status(file2, sa, null); t2 = DateTime.Now - start; //Assert.That(sa.LastException, Is.Not.Null); // Fails in 1.5-1.6.4 } } }
public override IEnumerable<VersionInfo> Status (Repository repo, FilePath path, SvnRevision revision, bool descendDirs, bool changedItemsOnly, bool remoteStatus) { var list = new List<VersionInfo> (); var args = new SvnStatusArgs { Revision = GetRevision (revision), Depth = descendDirs ? SvnDepth.Infinity : SvnDepth.Children, RetrieveAllEntries = !changedItemsOnly, RetrieveRemoteStatus = remoteStatus, }; lock (client) { try { client.Status (path, args, (o, a) => list.Add (CreateVersionInfo (repo, a))); } catch (SvnInvalidNodeKindException e) { if (e.SvnErrorCode == SvnErrorCode.SVN_ERR_WC_NOT_WORKING_COPY) list.Add (VersionInfo.CreateUnversioned (e.File, true)); else if (e.SvnErrorCode == SvnErrorCode.SVN_ERR_WC_NOT_FILE) list.Add (VersionInfo.CreateUnversioned (e.File, false)); else throw; } catch (SvnWorkingCopyPathNotFoundException e) { var fp = new FilePath (e.File); list.Add (VersionInfo.CreateUnversioned (fp, fp.IsDirectory)); } } return list; }
public void RepositoryLockStatus() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.AnkhSvnCases); string WcPath = sbox.Wc; string form = Path.Combine(WcPath, "Form.cs"); Client.Lock(form, "test"); SvnStatusArgs sa = new SvnStatusArgs() { RetrieveRemoteStatus = true }; this.Client.Status(form, sa, delegate(object sender, SvnStatusEventArgs e) { Assert.IsNotNull(e.RemoteLock); Assert.That(e.RemoteLock.Owner, Is.EqualTo(Environment.UserName)); Assert.That(DateTime.Now.Date, Is.EqualTo(e.RemoteLock.CreationTime.ToLocalTime().Date)); Assert.That(e.RemoteLock.Comment, Is.EqualTo("test")); Assert.IsFalse(e.RemoteLock.IsRawNetworkComment); }); }
public override IEnumerable<VersionInfo> Status (Repository repo, FilePath path, SvnRevision revision, bool descendDirs, bool changedItemsOnly, bool remoteStatus) { List<VersionInfo> list = new List<VersionInfo> (); SvnStatusArgs args = new SvnStatusArgs (); args.Revision = GetRevision (revision); args.Depth = descendDirs ? SvnDepth.Infinity : SvnDepth.Children; args.RetrieveAllEntries = !changedItemsOnly; args.RetrieveRemoteStatus = remoteStatus; lock (client) client.Status (path, args, delegate (object o, SvnStatusEventArgs a) { list.Add (CreateVersionInfo (repo, a)); }); return list; }
public void StatusDelayTest() { SvnSandBox sbox = new SvnSandBox(this); string tmp1Dir = sbox.GetTempDir(); string tmp2Dir = sbox.GetTempDir(); string tmp3Dir = sbox.GetTempDir(); Uri emptyUri = sbox.CreateRepository(SandBoxRepository.Empty); Client.CheckOut(emptyUri, tmp1Dir); Client.CheckOut(emptyUri, tmp2Dir); Client.CheckOut(emptyUri, tmp3Dir); StringBuilder lotOfData = new StringBuilder(); lotOfData.Append('Y', 1024 * 1024); string file1 = Path.Combine(tmp1Dir, "File-1"); string file2 = Path.Combine(tmp2Dir, "File-2"); string file3 = Path.Combine(tmp3Dir, "File-3"); File.WriteAllText(file1, lotOfData.ToString()); File.WriteAllText(file2, lotOfData.ToString()); File.WriteAllText(file3, lotOfData.ToString()); Client.Add(file1); Client.Add(file2); Client.Add(file3); Client.Configuration.LogMessageRequired = false; Client.Commit(file1); Client.Commit(file2); Client.Commit(file3); lotOfData = new StringBuilder(); lotOfData.Append('Y', 512 * 1024); lotOfData.Append('Z', 512 * 1024); File.WriteAllText(file1, lotOfData.ToString()); File.WriteAllText(file2, lotOfData.ToString()); File.WriteAllText(file3, lotOfData.ToString()); using (FileStream fs2 = new FileStream(file2, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) using (FileStream fs3 = new FileStream(file3, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) { SvnStatusArgs sa = new SvnStatusArgs(); sa.ThrowOnError = false; TimeSpan t1, t2, t3; DateTime start = DateTime.Now; Client.Status(file1, sa, null); t1 = DateTime.Now - start; Assert.That(sa.LastException, Is.Null); using (new SharpSvn.Implementation.SvnFsOperationRetryOverride(0)) { start = DateTime.Now; Client.Status(file2, sa, null); t2 = DateTime.Now - start; //Assert.That(sa.LastException, Is.Not.Null); // Fails in 1.5-1.6.4 } start = DateTime.Now; Client.Status(file3, sa, null); t3 = DateTime.Now - start; //Assert.That(sa.LastException, Is.Not.Null); // Fails in 1.5-1.6.4 Assert.That(t3, Is.GreaterThan(t2 + new TimeSpan(0, 0, 2))); System.Diagnostics.Trace.WriteLine(string.Format("t1={0}, t2={1}, t3={2}", t1, t2, t3)); } }
/// <summary> /// Tests an update where we contact the repository /// </summary> /*[TestMethod] public void TestRepositoryStatus() { // modify the file in another working copy and commit string wc2 = this.FindDirName(Path.Combine(this.WcPath, "wc2")); try { Zip.ExtractZipResource(wc2, this.GetType(), WC_FILE); this.RenameAdminDirs(wc2); using (StreamWriter w = new StreamWriter( Path.Combine(wc2, "Form.cs"), true)) w.Write("Hell worl"); this.RunCommand("svn", "ci -m \"\" " + wc2); // find the status in our own wc int youngest; string form = Path.Combine(this.WcPath, "Form.cs"); this.Client.Status(out youngest, form, Revision.Head, new StatusCallback(this.StatusFunc), false, false, true, true); Assert.AreEqual(e.RepositoryTextStatus, SvnStatus.Modified, "Wrong status"); } finally { PathUtils.RecursiveDelete(wc2); } }*/ SvnStatusEventArgs SingleStatus(SvnClient client, string path) { SvnStatusArgs sa = new SvnStatusArgs(); sa.Depth = SvnDepth.Empty; sa.RetrieveAllEntries = true; Collection<SvnStatusEventArgs> rslt; client.GetStatus(path, sa, out rslt); if (rslt.Count != 1) return null; SvnStatusEventArgs r = rslt[0]; if (!r.Versioned && !r.Conflicted && r.LocalNodeStatus == SvnStatus.None && r.LocalTextStatus == SvnStatus.None && r.LocalPropertyStatus == SvnStatus.None) { return null; } return r; }
static int Main(string[] args) { try { Console.WriteLine("Svn2: {0}", Assembly.GetExecutingAssembly().GetName().Version); if (args.Length < 1) { Usage(); return -2; } string command = args[0]; if (command == "/?" || command == "-?" || command == "--help") { Usage(); return -2; } string path = (args.Length == 2) ? Path.GetFullPath(args[1]) : Path.GetFullPath(Environment.CurrentDirectory); SvnClient client = new SvnClient(); switch (command) { case "sync": { SvnStatusArgs statusArgs = new SvnStatusArgs(); statusArgs.Depth = SvnDepth.Infinity; statusArgs.ThrowOnError = true; client.Status(path, statusArgs, new EventHandler<SvnStatusEventArgs>(delegate(object sender, SvnStatusEventArgs e) { switch (e.LocalContentStatus) { case SvnStatus.NotVersioned: Console.WriteLine(" {0} {1}", StatusToChar(e.LocalContentStatus), e.FullPath); if (File.Exists(e.FullPath)) { FileSystem.DeleteFile(e.FullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } else if (Directory.Exists(e.FullPath)) { FileSystem.DeleteDirectory(e.FullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } break; } })); } break; case "cleanup": { Console.WriteLine("Cleaning up {0}", path); SvnCleanUpArgs cleanupArgs = new SvnCleanUpArgs(); cleanupArgs.ThrowOnError = true; cleanupArgs.Notify += new EventHandler<SvnNotifyEventArgs>(delegate(object sender, SvnNotifyEventArgs e) { Console.WriteLine(" L {0}", e.FullPath); }); client.CleanUp(path, cleanupArgs); } break; case "revert": { Console.WriteLine("Reverting {0}", path); SvnRevertArgs revertArgs = new SvnRevertArgs(); revertArgs.Depth = SvnDepth.Infinity; revertArgs.ThrowOnError = true; revertArgs.Notify += new EventHandler<SvnNotifyEventArgs>(delegate(object sender, SvnNotifyEventArgs e) { Console.WriteLine(" R {0}", e.FullPath); }); client.Revert(path, revertArgs); } break; case "status": { SvnStatusArgs statusArgs = new SvnStatusArgs(); statusArgs.Depth = SvnDepth.Infinity; statusArgs.ThrowOnError = true; client.Status(path, statusArgs, new EventHandler<SvnStatusEventArgs>(delegate(object sender, SvnStatusEventArgs e) { Console.WriteLine(" {0} {1}", StatusToChar(e.LocalContentStatus), e.FullPath); })); } break; default: throw new Exception(string.Format("Unsupported '{0}' command", command)); } return 0; } catch (Exception ex) { Console.Error.WriteLine(ex.Message); #if DEBUG Console.Error.WriteLine(ex.StackTrace); #endif return -1; } }
public Status SingleStatus(string filename) { Debug("SVN: SingleStatus(" + filename + ")"); BeforeOperation("stat"); try { filename = FileUtility.NormalizePath(filename); SvnStatusArgs args = new SvnStatusArgs { Revision = SvnRevision.Working, RetrieveAllEntries = true, RetrieveIgnoredEntries = true, Depth = SvnDepth.Empty }; Status result = null; client.Status( filename, args, delegate (object sender, SvnStatusEventArgs e) { Debug("SVN: SingleStatus.callback(" + e.FullPath + "," + e.LocalContentStatus + ")"); System.Diagnostics.Debug.Assert(filename.Equals(e.FullPath, StringComparison.OrdinalIgnoreCase)); result = new Status { Copied = e.LocalCopied, TextStatus = ToStatusKind(e.LocalContentStatus) }; } ); if (result != null) { return result; } else { return new Status { TextStatus = StatusKind.None }; } } catch (SvnException ex) { throw new SvnClientException(ex); } finally { AfterOperation(); } }
public void LocalLockStatus() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.AnkhSvnCases); string WcPath = sbox.Wc; string form = Path.Combine(WcPath, "Form.cs"); this.RunCommand("svn", "lock -m test " + form); SvnStatusArgs sa = new SvnStatusArgs(); this.Client.Status(form, delegate(object sender, SvnStatusEventArgs e) { Assert.IsNotNull(e.LocalLock); Assert.That(e.LocalLock.Token, Is.Not.Null); Assert.That(e.LocalLock.Owner, Is.EqualTo(Environment.UserName)); Assert.That(e.LocalLock.CreationTime.ToLocalTime().Date, Is.EqualTo(DateTime.Now.Date)); Assert.That(e.LocalLock.Comment, Is.EqualTo("test")); }); }
public Status SingleStatus(string fileName) { fileName = FileUtility.NormalizePath(fileName); Status result; if (_statusCache.TryGetValue(fileName, out result)) { Debug("SVN: SingleStatus(" + fileName + ") = cached " + result.TextStatus); return result; } Debug("SVN: SingleStatus(" + fileName + ")"); BeforeReadOperation("stat"); try { var args = new SvnStatusArgs { Revision = SvnRevision.Working, RetrieveAllEntries = true, RetrieveIgnoredEntries = true, Depth = SvnDepth.Empty }; _client.Status( fileName, args, delegate (object sender, SvnStatusEventArgs e) { Debug("SVN: SingleStatus.callback(" + e.FullPath + ", " + e.LocalContentStatus + ")"); System.Diagnostics.Debug.Assert( fileName.Equals(e.FullPath, StringComparison.OrdinalIgnoreCase)); result = new Status(ToStatusKind(e.LocalContentStatus), e.LocalCopied); }); if (result == null) { result = Status.None; } _statusCache.Add(fileName, result); return result; } catch (SvnException ex) { throw new SvnClientException(ex); } finally { AfterOperation(); } }
public static void GetStatus(Source source, bool getRemote, bool getAll, out Collection<SvnStatusEventArgs> collection) { SvnStatusArgs args = new SvnStatusArgs { RetrieveAllEntries = getAll, RetrieveRemoteStatus = getRemote }; using (SvnClient client = GetSvnClient(source)) { client.GetStatus(source.Path, args, out collection); } }