public SvnUriTarget GetCopyOrigin(SvnItem item) { if (item == null) { throw new ArgumentNullException("item"); } // TODO: Maybe handle cases where the parent was copied instead of the child? SvnUriTarget copiedFrom = null; using (SvnClient client = GetService <ISvnClientPool>().GetNoUIClient()) { SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; ia.Depth = SvnDepth.Empty; client.Info(item.FullPath, ia, delegate(object sender, SvnInfoEventArgs ee) { if (ee.CopyFromUri != null) { copiedFrom = new SvnUriTarget(ee.CopyFromUri, ee.CopyFromRevision); } }); } return(copiedFrom); }
protected virtual void ValidateAdd(object sender, CancelEventArgs e) { ISvnClientPool clientPool = Context.GetService <ISvnClientPool>(); if (localFolder.SelectedItem == null) { errorProvider1.SetError(localFolder, "Please select a working copy path"); e.Cancel = true; return; } if (RepositoryAddUrl == null) { errorProvider1.SetError(repositoryTree, "Please select a location in the repository to add to"); e.Cancel = true; return; } using (SvnClient sc = clientPool.GetClient()) { SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; Collection <SvnInfoEventArgs> info; bool result = sc.GetInfo(RepositoryUri, ia, out info); if (!result) { errorProvider1.SetError(repositoryTree, "Please select a valid location in the repository to add to"); e.Cancel = true; return; } } }
/// <summary> /// /// </summary> /// <returns></returns> public override bool ResolveFiles() { SvnClient client = new SvnClient(); SvnInfoArgs infoArgs = new SvnInfoArgs(); infoArgs.ThrowOnError = false; infoArgs.Depth = SvnDepth.Files; foreach (SourceFile file in State.SourceFiles.Values) { if (file.IsResolved) continue; string dirName = SvnTools.GetTruePath(SvnTools.GetNormalizedDirectoryName(file.FullName), true); client.Info(dirName, infoArgs, delegate(object sender, SvnInfoEventArgs e) { SourceFile infoFile; string path = e.FullPath; if (State.SourceFiles.TryGetValue(path, out infoFile) && !infoFile.IsResolved) { infoFile.SourceReference = new SubversionSourceReference(this, infoFile, e.RepositoryRoot, e.RepositoryRoot.MakeRelativeUri(e.Uri), e.LastChangeRevision, e.Revision); } }); } return true; }
public void Authentication_SimpleSslCert() { using (SvnClient client = new SvnClient()) { client.Authentication.Clear(); client.Authentication.SslServerTrustHandlers += Authenticator_SslServerTrustHandlers; client.Authentication.UserNamePasswordHandlers += Authenticator_UserNamePasswordHandlers; bool arrived = false; SvnInfoArgs a = new SvnInfoArgs(); a.ThrowOnCancel = false; a.ThrowOnError = false; Assert.That(client.Info(new Uri("https://svn.apache.org/repos/private/committers"), a, delegate(object sender, SvnInfoEventArgs e) { arrived = true; }), Is.False); Assert.That(a.LastException, Is.Not.Null); Assert.That(a.LastException, Is.InstanceOf(typeof(SvnException))); Assert.That(arrived, Is.False); Assert.That(_serverTrustTicked); Assert.That(_userNamePasswordTicked); Assert.That(_userArgs, Is.Not.Null); Assert.That(_userArgs.InitialUserName, Is.Not.Null); Assert.That(_userArgs.Realm, Is.EqualTo("<https://svn.apache.org:443> ASF Members")); Assert.That(_userArgs.RealmUri, Is.EqualTo(new Uri("https://svn.apache.org/"))); } }
private void EnsureCredentials(ScmUserNamePasswordEventArgs e) { ISvnClientPool pool = (Context != null) ? Context.GetService <ISvnClientPool>() : null; if (pool != null) { using (SvnPoolClient client = pool.GetNoUIClient()) { EventHandler <SvnUserNamePasswordEventArgs> handler = delegate(object sender, SvnUserNamePasswordEventArgs args) { args.Save = true; args.UserName = e.UserName; args.Password = e.Password; }; client.Authentication.UserNamePasswordHandlers += handler; try { SvnInfoArgs infoArgs = new SvnInfoArgs(); infoArgs.ThrowOnError = false; System.Collections.ObjectModel.Collection <SvnInfoEventArgs> info; if (client.GetInfo(SvnUriTarget.FromString(e.RepositoryUri), infoArgs, out info)) { } } finally { client.Authentication.UserNamePasswordHandlers -= handler; } } } }
/// <summary> /// Checks, if the item at <paramref name="svnUrl"/> in specific revision exists /// </summary> /// <param name="svnUrl">URL of item inside the SVN Repository</param> /// <param name="versionSpec">Version specification ("H" for latest or "Rxxx" for specific revision)</param> /// <returns>true, item exists in expected revision, otherwise false.</returns> public bool ItemExists(string svnUrl, string versionSpec) { if (!IsUrlValid(svnUrl)) { return(false); } SvnInfoArgs args = new SvnInfoArgs(); args.Revision = ConvertToRevsion(versionSpec); try { Collection <SvnInfoEventArgs> contents; _svn.GetInfo(new Uri(svnUrl), args, out contents); return(true); } catch (SvnAuthenticationException) { throw new SvnAuthenticationException(); } catch { return(false); } }
/// <summary> /// /// </summary> /// <returns></returns> public override bool ResolveFiles() { SvnClient client = new SvnClient(); SvnInfoArgs infoArgs = new SvnInfoArgs(); infoArgs.ThrowOnError = false; infoArgs.Depth = SvnDepth.Files; foreach (SourceFile file in State.SourceFiles.Values) { if (file.IsResolved) { continue; } string dirName = SvnTools.GetTruePath(SvnTools.GetNormalizedDirectoryName(file.FullName), true); client.Info(dirName, infoArgs, delegate(object sender, SvnInfoEventArgs e) { SourceFile infoFile; string path = e.FullPath; if (State.SourceFiles.TryGetValue(path, out infoFile) && !infoFile.IsResolved) { infoFile.SourceReference = new SubversionSourceReference(this, infoFile, e.RepositoryRoot, e.RepositoryRoot.MakeRelativeUri(e.Uri), e.LastChangeRevision, e.Revision); } }); } return(true); }
public void Relocate_SvnServeRelocate() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.Default, false); // start a svnserve process on this repos Process svnserve = this.StartSvnServe(sbox.RepositoryUri.AbsolutePath); try { Uri localUri = new Uri(String.Format("svn://127.0.0.1:{0}/", PortNumber)); bool svnServeAvailable = false; for (int i = 0; i < 10; i++) { SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; // This test also checks whether "svn://127.0.0.1:{0}/" is correctly canonicalized to "svn://127.0.0.1:{0}" Client.Info(localUri, ia, delegate(object sender, SvnInfoEventArgs e) { svnServeAvailable = true; }); if (svnServeAvailable) { break; } Thread.Sleep(100); } Assert.That(svnServeAvailable); Assert.That(Client.Relocate(sbox.Wc, sbox.RepositoryUri, localUri)); Collection <SvnInfoEventArgs> list; SvnInfoArgs a = new SvnInfoArgs(); Assert.That(Client.GetInfo(sbox.Wc, a, out list)); Assert.That(list.Count, Is.GreaterThan(0)); Assert.That(list[0].Uri.ToString().StartsWith(localUri.ToString())); } finally { System.Threading.Thread.Sleep(100); if (!svnserve.HasExited) { svnserve.Kill(); svnserve.WaitForExit(); } } }
public static void GetInfo(Source source, out Collection<SvnInfoEventArgs> collection) { using (SvnClient client = GetSvnClient(source)) { SvnInfoArgs args = new SvnInfoArgs { ThrowOnError = true }; client.GetInfo(SvnTarget.FromString(source.Path), args, out collection); } }
public void Relocate_SvnServeRelocate() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.Default, false); // start a svnserve process on this repos Process svnserve = this.StartSvnServe(sbox.RepositoryUri.AbsolutePath); try { Uri localUri = new Uri(String.Format("svn://127.0.0.1:{0}/", PortNumber)); bool svnServeAvailable = false; for (int i = 0; i < 10; i++) { SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; // This test also checks whether "svn://127.0.0.1:{0}/" is correctly canonicalized to "svn://127.0.0.1:{0}" Client.Info(localUri, ia, delegate(object sender, SvnInfoEventArgs e) { svnServeAvailable = true; }); if (svnServeAvailable) break; Thread.Sleep(100); } Assert.That(svnServeAvailable); Assert.That(Client.Relocate(sbox.Wc, sbox.RepositoryUri, localUri)); Collection<SvnInfoEventArgs> list; SvnInfoArgs a = new SvnInfoArgs(); Assert.That(Client.GetInfo(sbox.Wc, a, out list)); Assert.That(list.Count, Is.GreaterThan(0)); Assert.That(list[0].Uri.ToString().StartsWith(localUri.ToString())); } finally { System.Threading.Thread.Sleep(100); if (!svnserve.HasExited) { svnserve.Kill(); svnserve.WaitForExit(); } } }
/// <summary> /// Получить URL ветки из которой была выделена фитча /// </summary> /// <param name="revision">Номер ревизии в которой выделена ветка</param> /// <param name="workingCopyPath">Путь к рабочей копии</param> /// <returns>Строка с URL</returns> private string GetBaseBranchPath(long revision, string workingCopyPath) { string basePath = string.Empty; var svnInfoArgs = new SvnInfoArgs { Revision = new SvnRevision(revision) }; Info(SvnTarget.FromString(workingCopyPath), svnInfoArgs, (sender, args) => { basePath = args.Uri.ToString(); Logger.LogInfo(args.Uri.ToString()); }); return(basePath); }
bool ItemExists(Uri target) { bool found = false; using (SvnClient client = NewSvnClient(false, false)) { SvnInfoArgs args = new SvnInfoArgs(); args.ThrowOnError = false; args.Depth = SvnDepth.Empty; return(client.Info(target, args, delegate(object sender, SvnInfoEventArgs e) { found = true; }) && found); } }
Exception GetNotFoundError() { SvnClient client = new SvnClient(); SvnInfoArgs a = new SvnInfoArgs(); a.ThrowOnError = false; Assert.That(client.Info("c:/does/not/ever/exist/on/windows", a, delegate(object sender, SvnInfoEventArgs e) { }), Is.False, "Should fail"); return(a.LastException); }
/// <summary> /// Actual method to be executed for the implementing task /// </summary> /// <param name="client">The instance of the SVN client</param> /// <returns></returns> public override bool ExecuteCommand(SvnClient client) { SvnTarget target = new SvnPathTarget(RepositoryPath); SvnInfoArgs args = new SvnInfoArgs(); Collection<SvnInfoEventArgs> infoResult = new Collection<SvnInfoEventArgs>(); bool result = client.GetInfo(target, args, out infoResult); SvnInfoEventArgs info = infoResult[0]; Revision = info.Revision; RepositoryId = info.RepositoryId; NodeKind = info.NodeKind.ToString(); Schedule = info.Schedule.ToString(); LastChangedRevision = info.LastChangeRevision; LastChangedAuthor = info.LastChangeAuthor; LastChangeDate = info.LastChangeTime; return result; }
public void WcCasing() { SvnSandBox sbox = new SvnSandBox(this); Uri CollabReposUri = sbox.CreateRepository(SandBoxRepository.MergeScenario); string dir = sbox.Wc; SvnUpdateResult r; Assert.That(Client.CheckOut(CollabReposUri, dir, out r)); Collection <SvnInfoEventArgs> items; SvnInfoArgs aa = new SvnInfoArgs(); aa.Depth = SvnDepth.Children; Assert.That(Client.GetInfo(Path.Combine(dir, "trunk"), aa, out items)); foreach (SvnInfoEventArgs ia in items) { bool reached = false; Assert.That(Client.Info(ia.FullPath, delegate(object sender, SvnInfoEventArgs e) { reached = true; })); Assert.That(reached); reached = false; SvnInfoArgs a = new SvnInfoArgs(); a.ThrowOnError = false; Client.Info(ia.FullPath.ToUpperInvariant(), a, delegate(object sender, SvnInfoEventArgs e) { reached = true; }); if (ia.NodeKind != SvnNodeKind.Directory) { Assert.That(reached, Is.False); } } }
public void InfoTest() { SvnSandBox sbox = new SvnSandBox(this); Uri CollabReposUri = sbox.CreateRepository(SandBoxRepository.MergeScenario); string dir = sbox.Wc; SvnUpdateResult r; Client.CheckOut(CollabReposUri, dir, out r); int i = 0; Assert.That(Client.Info(dir, delegate(object sender, SvnInfoEventArgs e) { i++; Assert.That(e.Revision, Is.EqualTo(r.Revision)); Assert.That(e.LastChangeRevision, Is.EqualTo(r.Revision)); }), Is.True); Assert.That(i, Is.EqualTo(1)); i = 0; SvnInfoArgs aa = new SvnInfoArgs(); aa.Depth = SvnDepth.Children; Assert.That(Client.Info(dir, aa, delegate(object sender, SvnInfoEventArgs e) { i++; Assert.That(e.Revision, Is.EqualTo(r.Revision)); Assert.That(e.LastChangeRevision, Is.LessThanOrEqualTo(r.Revision)); }), Is.True); Assert.That(i, Is.EqualTo(4)); // trunk branches tags }
public void Authentication_ASFCertSafe() { using (SvnClient client = new SvnClient()) { client.Authentication.Clear(); bool arrived = false; SvnInfoArgs ia = new SvnInfoArgs(); ia.AddExpectedError(SvnErrorCode.SVN_ERR_AUTHN_NO_PROVIDER); ia.AddExpectedError(SvnErrorCode.SVN_ERR_RA_CANNOT_CREATE_SESSION); Assert.That(client.Info(new Uri("https://svn.apache.org/repos/asf/"), ia, delegate(object sender, SvnInfoEventArgs e) { arrived = true; }), Is.False); Assert.That(arrived, Is.False); Assert.That(ia.LastException, Is.Not.Null, "Has exception"); Assert.That(ia.LastException.ContainsError(SvnErrorCode.SVN_ERR_AUTHN_NO_PROVIDER), "Right error code in chain"); } using (SvnClient client = new SvnClient()) { client.Authentication.Clear(); client.Authentication.SslAuthorityTrustHandlers += SvnAuthentication.SubversionWindowsSslAuthorityTrustHandler; client.Authentication.SslServerTrustHandlers += SvnAuthentication.SubversionWindowsSslServerTrustHandler; bool arrived = false; Assert.That(client.Info(new Uri("https://svn.apache.org/repos/asf/"), delegate(object sender, SvnInfoEventArgs e) { arrived = true; })); Assert.That(arrived); } }
public void Authentication_ASFCertSafe() { using (SvnClient client = new SvnClient()) { client.Authentication.Clear(); bool arrived = false; SvnInfoArgs ia = new SvnInfoArgs(); ia.AddExpectedError(SvnErrorCode.SVN_ERR_AUTHN_NO_PROVIDER); ia.AddExpectedError(SvnErrorCode.SVN_ERR_RA_CANNOT_CREATE_SESSION); Assert.That(client.Info(new Uri("https://svn.apache.org/repos/asf/"), ia, delegate(object sender, SvnInfoEventArgs e) { arrived = true; }), Is.False); Assert.That(arrived, Is.False); Assert.That(ia.LastException, Is.Not.Null, "Has exception"); Assert.That(ia.LastException.ContainsError(SvnErrorCode.SVN_ERR_AUTHN_NO_PROVIDER), "Right error code in chain"); } using (SvnClient client = new SvnClient()) { client.Authentication.Clear(); client.Authentication.SslAuthorityTrustHandlers += SvnAuthentication.SubversionWindowsSslAuthorityTrustHandler; client.Authentication.SslServerTrustHandlers += SvnAuthentication.SubversionWindowsSslServerTrustHandler; bool arrived = false; Assert.That(client.Info(new Uri("https://svn.apache.org/repos/asf/"), delegate(object sender, SvnInfoEventArgs e) { arrived = true; })); Assert.That(arrived); } }
static bool CheckoutWorkingCopyForSolution(CommandEventArgs e, ref bool confirmed) { using (SvnClient cl = e.GetService<ISvnClientPool>().GetClient()) using (AddToSubversion dialog = new AddToSubversion()) { dialog.PathToAdd = e.Selection.SolutionFilename; if (dialog.ShowDialog(e.Context) == DialogResult.OK) { confirmed = true; Collection<SvnInfoEventArgs> info; SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; if (!cl.GetInfo(dialog.RepositoryAddUrl, ia, out info)) { // Target uri doesn't exist in the repository, let's create if (!RemoteCreateDirectory(e, dialog.Text, dialog.RepositoryAddUrl, cl)) return false; // Create failed; bail out } // Create working copy SvnCheckOutArgs coArg = new SvnCheckOutArgs(); coArg.AllowObstructions = true; cl.CheckOut(dialog.RepositoryAddUrl, dialog.WorkingCopyDir, coArg); // Add solutionfile so we can set properties (set managed) AddPathToSubversion(e, e.Selection.SolutionFilename); IAnkhSolutionSettings settings = e.GetService<IAnkhSolutionSettings>(); IProjectFileMapper mapper = e.GetService<IProjectFileMapper>(); IFileStatusMonitor monitor = e.GetService<IFileStatusMonitor>(); settings.ProjectRoot = SvnTools.GetNormalizedFullPath(dialog.WorkingCopyDir); if (monitor != null && mapper != null) { // Make sure all visible glyphs are updated to reflect a new working copy monitor.ScheduleSvnStatus(mapper.GetAllFilesOfAllProjects()); } return true; } return false; // User cancelled the "Add to subversion" dialog, don't set as managed by Ankh } }
/// <summary> /// Returns false if the AddToSubversionDialog has been cancelled, true otherwise /// </summary> /// <param name="e"></param> /// <param name="projectInfo"></param> /// <param name="solutionReposRoot"></param> /// <param name="shouldMarkAsManaged"></param> /// <param name="storeReference"></param> /// <returns></returns> static bool CheckoutWorkingCopyForProject(CommandEventArgs e, ISvnProjectInfo projectInfo, Uri solutionReposRoot, out bool shouldMarkAsManaged, out bool storeReference) { shouldMarkAsManaged = false; storeReference = false; using (SvnClient cl = e.GetService<ISvnClientPool>().GetClient()) using (AddProjectToSubversion dialog = new AddProjectToSubversion()) { dialog.Context = e.Context; dialog.PathToAdd = projectInfo.ProjectDirectory; dialog.RepositoryAddUrl = solutionReposRoot; if (dialog.ShowDialog(e.Context) != DialogResult.OK) return false; // User cancelled the "Add to subversion" dialog, don't set as managed by Ankh Collection<SvnInfoEventArgs> info; SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; if (!cl.GetInfo(dialog.RepositoryAddUrl, ia, out info)) { // Target uri doesn't exist in the repository, let's create if (!RemoteCreateDirectory(e, dialog.Text, dialog.RepositoryAddUrl, cl)) return false; // Create failed; bail out } // Create working copy SvnCheckOutArgs coArg = new SvnCheckOutArgs(); coArg.AllowObstructions = true; cl.CheckOut(dialog.RepositoryAddUrl, dialog.WorkingCopyDir, coArg); shouldMarkAsManaged = dialog.MarkAsManaged; storeReference = dialog.WriteCheckOutInformation; } return true; }
static bool CheckoutWorkingCopyForSolution(CommandEventArgs e, ref bool confirmed) { using (SvnClient cl = e.GetService <ISvnClientPool>().GetClient()) using (AddToSubversion dialog = new AddToSubversion()) { dialog.PathToAdd = e.Selection.SolutionFilename; if (e.Argument is IAnkhSccService) { dialog.CommitAllVisible = false; dialog.CommitAllFiles = false; } else { dialog.CommitAllFiles = true; } if (dialog.ShowDialog(e.Context) != DialogResult.OK) { return(false); // Don't set as managed by AnkhSVN } confirmed = true; if (dialog.CommitAllFiles) { HybridCollection <string> allFiles = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase); string logMessage; string wcPath = dialog.WorkingCopyDir; Uri reposUrl = dialog.RepositoryAddUrl; allFiles.UniqueAddRange(e.GetService <IProjectFileMapper>().GetAllFilesOfAllProjects(true)); using (CreateDirectoryDialog dlg = new CreateDirectoryDialog()) { dlg.Text = CommandStrings.ImportingTitle; dlg.NewDirectoryName = dialog.RepositoryAddUrl.ToString(); dlg.NewDirectoryReadonly = true; if (dlg.ShowDialog(e.Context) != DialogResult.OK) { return(false); } logMessage = dlg.LogMessage; } IAnkhOpenDocumentTracker documentTracker = e.GetService <IAnkhOpenDocumentTracker>(); documentTracker.SaveDocuments(allFiles); // Make sure all files are saved before updating/merging! using (DocumentLock lck = documentTracker.LockDocuments(allFiles, DocumentLockType.NoReload)) using (lck.MonitorChangesForReload()) { e.GetService <IProgressRunner>().RunModal(CommandStrings.ImportingTitle, delegate(object sender, ProgressWorkerArgs a) { SvnImportArgs importArgs = new SvnImportArgs(); importArgs.LogMessage = logMessage; importArgs.Filter += delegate(object ieSender, SvnImportFilterEventArgs ie) { if (ie.NodeKind != SvnNodeKind.Directory) { ie.Filter = !allFiles.Contains(ie.FullPath); } else { bool filter = true; foreach (string p in allFiles) { if (SvnItem.IsBelowRoot(p, ie.FullPath)) { filter = false; break; } } if (filter) { ie.Filter = true; } } }; a.Client.Import(wcPath, reposUrl, importArgs); }); } } else { Collection <SvnInfoEventArgs> info; SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; if (!cl.GetInfo(dialog.RepositoryAddUrl, ia, out info)) { // Target uri doesn't exist in the repository, let's create if (!RemoteCreateDirectory(e, dialog.Text, dialog.RepositoryAddUrl, cl)) { return(false); // Create failed; bail out } } // Create working copy SvnCheckOutArgs coArg = new SvnCheckOutArgs(); coArg.AllowObstructions = true; cl.CheckOut(dialog.RepositoryAddUrl, dialog.WorkingCopyDir, coArg); // Add solutionfile so we can set properties (set managed) AddPathToSubversion(e, e.Selection.SolutionFilename); IAnkhSolutionSettings settings = e.GetService <IAnkhSolutionSettings>(); IProjectFileMapper mapper = e.GetService <IProjectFileMapper>(); IFileStatusMonitor monitor = e.GetService <IFileStatusMonitor>(); settings.ProjectRoot = SvnTools.GetNormalizedFullPath(dialog.WorkingCopyDir); if (monitor != null && mapper != null) { // Make sure all visible glyphs are updated to reflect a new working copy monitor.ScheduleSvnStatus(mapper.GetAllFilesOfAllProjects()); } } return(true); } }
/// <summary> /// Returns false if the AddToSubversionDialog has been cancelled, true otherwise /// </summary> /// <param name="e"></param> /// <param name="projectInfo"></param> /// <param name="solutionReposRoot"></param> /// <param name="shouldMarkAsManaged"></param> /// <param name="storeReference"></param> /// <returns></returns> static bool CheckoutWorkingCopyForProject(CommandEventArgs e, SccProject project, ISccProjectInfo projectInfo, Uri solutionReposRoot, out bool shouldMarkAsManaged, out bool storeReference) { shouldMarkAsManaged = false; storeReference = false; using (SvnClient cl = e.GetService <ISvnClientPool>().GetClient()) using (AddProjectToSubversion dialog = new AddProjectToSubversion()) { dialog.Context = e.Context; dialog.PathToAdd = projectInfo.ProjectDirectory; dialog.RepositoryAddUrl = solutionReposRoot; if (e.Argument is IAnkhSccService) { dialog.CommitAllVisible = false; dialog.CommitAllFiles = false; } else { dialog.CommitAllFiles = true; } if (dialog.ShowDialog(e.Context) != DialogResult.OK) { return(false); // User cancelled the "Add to subversion" dialog, don't set as managed by Ankh } if (!dialog.CommitAllFiles) { Collection <SvnInfoEventArgs> info; SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; if (!cl.GetInfo(dialog.RepositoryAddUrl, ia, out info)) { // Target uri doesn't exist in the repository, let's create if (!RemoteCreateDirectory(e, dialog.Text, dialog.RepositoryAddUrl, cl)) { return(false); // Create failed; bail out } } // Create working copy SvnCheckOutArgs coArg = new SvnCheckOutArgs(); coArg.AllowObstructions = true; cl.CheckOut(dialog.RepositoryAddUrl, dialog.WorkingCopyDir, coArg); } else { // Cache some values before thread marshalling HybridCollection <string> projectFiles = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase); string wcDir = dialog.WorkingCopyDir; Uri reposUrl = dialog.RepositoryAddUrl; string logMessage; projectFiles.UniqueAddRange(e.GetService <IProjectFileMapper>().GetAllFilesOf(project)); using (CreateDirectoryDialog dlg = new CreateDirectoryDialog()) { dlg.Text = CommandStrings.ImportingTitle; dlg.NewDirectoryName = reposUrl.ToString(); dlg.NewDirectoryReadonly = true; if (dlg.ShowDialog(e.Context) != DialogResult.OK) { return(false); } logMessage = dlg.LogMessage; } IAnkhOpenDocumentTracker documentTracker = e.GetService <IAnkhOpenDocumentTracker>(); documentTracker.SaveDocuments(projectFiles); // Make sure all files are saved before updating/merging! using (DocumentLock lck = documentTracker.LockDocuments(projectFiles, DocumentLockType.NoReload)) using (lck.MonitorChangesForReload()) { e.GetService <IProgressRunner>().RunModal(CommandStrings.ImportingTitle, delegate(object sender, ProgressWorkerArgs a) { SvnImportArgs importArgs = new SvnImportArgs(); importArgs.LogMessage = logMessage; importArgs.Filter += delegate(object ieSender, SvnImportFilterEventArgs ie) { if (ie.NodeKind != SvnNodeKind.Directory) { ie.Filter = !projectFiles.Contains(ie.FullPath); } else { bool filter = true; foreach (string p in projectFiles) { if (SvnItem.IsBelowRoot(p, ie.FullPath)) { filter = false; break; } } if (filter) { ie.Filter = true; } } }; a.Client.Import(wcDir, reposUrl, importArgs); }); } } shouldMarkAsManaged = dialog.MarkAsManaged; storeReference = dialog.WriteCheckOutInformation; } return(true); }
public void Authentication_SimpleSslCert() { using (SvnClient client = new SvnClient()) { client.Authentication.Clear(); client.Authentication.SslServerTrustHandlers += Authenticator_SslServerTrustHandlers; client.Authentication.UserNamePasswordHandlers += Authenticator_UserNamePasswordHandlers; bool arrived = false; SvnInfoArgs a = new SvnInfoArgs(); a.ThrowOnCancel = false; a.ThrowOnError = false; Assert.That(client.Info(new Uri("https://svn.apache.org/repos/private/committers"), a, delegate(object sender, SvnInfoEventArgs e) { arrived = true; }), Is.False); Assert.That(a.LastException, Is.Not.Null); Assert.That(a.LastException, Is.InstanceOf(typeof(SvnException))); Assert.That(arrived, Is.False); Assert.That(_serverTrustTicked); Assert.That(_userNamePasswordTicked); Assert.That(_userArgs, Is.Not.Null); Assert.That(_userArgs.InitialUserName, Is.Not.Null); Assert.That(_userArgs.Realm, Is.EqualTo("<https://svn.apache.org:443> ASF Members")); Assert.That(_userArgs.RealmUri, Is.EqualTo(new Uri("https://svn.apache.org/"))); } }
protected virtual void ValidateAdd(object sender, CancelEventArgs e) { ISvnClientPool clientPool = Context.GetService<ISvnClientPool>(); if (localFolder.SelectedItem == null) { errorProvider1.SetError(localFolder, "Please select a working copy path"); e.Cancel = true; return; } if (RepositoryAddUrl == null) { errorProvider1.SetError(repositoryTree, "Please select a location in the repository to add to"); e.Cancel = true; return; } using (SvnClient sc = clientPool.GetClient()) { SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; Collection<SvnInfoEventArgs> info; bool result = sc.GetInfo(repositoryTree.SelectedNode.RawUri, ia, out info); if (!result) { errorProvider1.SetError(repositoryTree, "Please select a valid location in the repository to add to"); e.Cancel = true; return; } } }
public override void OnExecute(CommandEventArgs e) { HybridCollection <string> dirs = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase); foreach (SvnItem i in e.Selection.GetSelectedSvnItems(true)) { SvnDirectory dir = i.ParentDirectory; if (dir != null && dir.NeedsWorkingCopyUpgrade && !dirs.Contains(dir.FullPath)) { dirs.Add(dir.FullPath); } else if (i.IsDirectory && i.AsDirectory().NeedsWorkingCopyUpgrade&& !dirs.Contains(i.FullPath)) { dirs.Add(i.FullPath); } } e.GetService <IProgressRunner>().RunModal(CommandStrings.UpgradingWorkingCopy, delegate(object sender, ProgressWorkerArgs a) { HybridCollection <string> done = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase); foreach (string dir in dirs) { SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; if (done.Contains(dir)) { continue; } if (a.Client.Info(dir, ia, null) || ia.LastException.SvnErrorCode != SvnErrorCode.SVN_ERR_WC_UPGRADE_REQUIRED) { continue; } SvnUpgradeArgs ua = new SvnUpgradeArgs(); ua.ThrowOnError = false; /* Capture the already upgraded directories to avoid a lot of work */ ua.Notify += delegate(object sender2, SvnNotifyEventArgs n) { if (n.Action == SvnNotifyAction.UpgradedDirectory) { if (!done.Contains(n.FullPath)) { done.Add(n.FullPath); } } }; string tryDir = dir; while (true) { if (a.Client.Upgrade(tryDir, ua) || ua.LastException.SvnErrorCode != SvnErrorCode.SVN_ERR_WC_INVALID_OP_ON_CWD) { break; } string pd = SvnTools.GetNormalizedDirectoryName(tryDir); if (pd == tryDir || string.IsNullOrEmpty(pd)) { break; } tryDir = pd; } } }); if (dirs.Count > 0) { StatusCache.ResetUpgradeWarning(); } }
Exception GetNotFoundError() { SvnClient client = new SvnClient(); SvnInfoArgs a = new SvnInfoArgs(); a.ThrowOnError = false; Assert.That(client.Info("c:/does/not/ever/exist/on/windows", a, delegate(object sender, SvnInfoEventArgs e) { }), Is.False, "Should fail"); return a.LastException; }
public SvnUriTarget GetCopyOrigin(SvnItem item) { if (item == null) throw new ArgumentNullException("item"); // TODO: Maybe handle cases where the parent was copied instead of the child? SvnUriTarget copiedFrom = null; using (SvnClient client = GetService<ISvnClientPool>().GetNoUIClient()) { SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; ia.Depth = SvnDepth.Empty; client.Info(item.FullPath, ia, delegate(object sender, SvnInfoEventArgs ee) { if (ee.CopyFromUri != null) { copiedFrom = new SvnUriTarget(ee.CopyFromUri, ee.CopyFromRevision); } }); } return copiedFrom; }
public override void OnExecute(CommandEventArgs e) { SvnItem root = GetRoot(e); if (root == null) return; using (CreateBranchDialog dlg = new CreateBranchDialog()) { if (e.Command == AnkhCommand.ProjectBranch) dlg.Text = CommandStrings.BranchProject; dlg.SrcFolder = root.FullPath; dlg.SrcUri = root.Uri; dlg.EditSource = false; dlg.Revision = root.Status.Revision; RepositoryLayoutInfo info; if (RepositoryUrlUtils.TryGuessLayout(e.Context, root.Uri, out info)) dlg.NewDirectoryName = new Uri(info.BranchesRoot, "."); while (true) { if (DialogResult.OK != dlg.ShowDialog(e.Context)) return; string msg = dlg.LogMessage; bool retry = false; bool ok = false; ProgressRunnerResult rr = e.GetService<IProgressRunner>().RunModal("Creating Branch/Tag", delegate(object sender, ProgressWorkerArgs ee) { SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; if (ee.Client.Info(dlg.NewDirectoryName, ia, null)) { DialogResult dr = DialogResult.Cancel; ee.Synchronizer.Invoke((AnkhAction) delegate { AnkhMessageBox mb = new AnkhMessageBox(ee.Context); dr = mb.Show(string.Format("The Branch/Tag at Url '{0}' already exists.", dlg.NewDirectoryName), "Path Exists", MessageBoxButtons.RetryCancel); }, null); if (dr == DialogResult.Retry) { // show dialog again to let user modify the branch URL retry = true; } } else { SvnCopyArgs ca = new SvnCopyArgs(); ca.CreateParents = true; ca.LogMessage = msg; ok = dlg.CopyFromUri ? ee.Client.RemoteCopy(new SvnUriTarget(dlg.SrcUri, dlg.SelectedRevision), dlg.NewDirectoryName, ca) : ee.Client.RemoteCopy(new SvnPathTarget(dlg.SrcFolder), dlg.NewDirectoryName, ca); } }); if (rr.Succeeded && ok && dlg.SwitchToBranch) { e.GetService<IAnkhCommandService>().PostExecCommand(AnkhCommand.SolutionSwitchDialog, dlg.NewDirectoryName); } if (!retry) break; } } }
public override void OnExecute(CommandEventArgs e) { SvnItem root = GetRoot(e); if (root == null) { return; } using (CreateBranchDialog dlg = new CreateBranchDialog()) { if (e.Command == AnkhCommand.ProjectBranch) { dlg.Text = CommandStrings.BranchProject; } dlg.SrcFolder = root.FullPath; dlg.SrcUri = root.Uri; dlg.EditSource = false; dlg.Revision = root.Status.Revision; RepositoryLayoutInfo info; if (RepositoryUrlUtils.TryGuessLayout(e.Context, root.Uri, out info)) { dlg.NewDirectoryName = new Uri(info.BranchesRoot, "."); } while (true) { if (DialogResult.OK != dlg.ShowDialog(e.Context)) { return; } string msg = dlg.LogMessage; bool retry = false; bool ok = false; ProgressRunnerResult rr = e.GetService <IProgressRunner>().RunModal(CommandStrings.CreatingBranch, delegate(object sender, ProgressWorkerArgs ee) { SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; if (ee.Client.Info(dlg.NewDirectoryName, ia, null)) { DialogResult dr = DialogResult.Cancel; ee.Synchronizer.Invoke((AnkhAction) delegate { AnkhMessageBox mb = new AnkhMessageBox(ee.Context); dr = mb.Show(string.Format("The Branch/Tag at Url '{0}' already exists.", dlg.NewDirectoryName), "Path Exists", MessageBoxButtons.RetryCancel); }, null); if (dr == DialogResult.Retry) { // show dialog again to let user modify the branch URL retry = true; } } else { SvnCopyArgs ca = new SvnCopyArgs(); ca.CreateParents = true; ca.LogMessage = msg; ok = dlg.CopyFromUri ? ee.Client.RemoteCopy(new SvnUriTarget(dlg.SrcUri, dlg.SelectedRevision), dlg.NewDirectoryName, ca) : ee.Client.RemoteCopy(dlg.SrcFolder, dlg.NewDirectoryName, ca); } }); if (rr.Succeeded && ok && dlg.SwitchToBranch) { e.GetService <IAnkhCommandService>().PostExecCommand(AnkhCommand.SolutionSwitchDialog, dlg.NewDirectoryName); } if (!retry) { break; } } } }
public void Lock_ListLocks() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.DefaultBranched); Uri trunk = sbox.Uri; Uri src = new Uri(sbox.Uri, "src/"); Uri srcFile1 = new Uri(src, "file1.cs"); Client.RemoteLock(srcFile1, "Mine!"); Collection<SvnInfoEventArgs> lst; SvnInfoArgs ia = new SvnInfoArgs(); ia.Depth = SvnDepth.Unknown; Assert.That(Client.GetInfo(srcFile1, ia, out lst)); Assert.That(lst.Count == 1); Assert.That(lst[0].Lock, Is.Not.Null, "Is locked - Unknown"); ia.Depth = SvnDepth.Empty; Assert.That(Client.GetInfo(srcFile1, ia, out lst)); Assert.That(lst.Count == 1); Assert.That(lst[0].Lock, Is.Not.Null, "Is locked - Empty"); ia.Depth = SvnDepth.Infinity; Assert.That(Client.GetInfo(srcFile1, ia, out lst)); Assert.That(lst.Count == 1); Assert.That(lst[0].Lock, Is.Not.Null, "Is locked - Infinity"); ia.Depth = SvnDepth.Unknown; Assert.That(Client.GetInfo(src, ia, out lst)); Assert.That(lst.Count, Is.EqualTo(1)); // Just the dir // And the next cases where failing because .Info() didn't pass // an explicit operational revision to svn_client_info2(). ia.Depth = SvnDepth.Files; Assert.That(Client.GetInfo(src, ia, out lst)); Assert.That(lst.Count, Is.EqualTo(5)); bool found = false; foreach(SvnInfoEventArgs e in lst) { if (e.Path.EndsWith("file1.cs")) { found = true; Assert.That(e.Lock, Is.Not.Null, "Is locked - Dir - Files"); } } Assert.That(found); ia.Depth = SvnDepth.Children; Assert.That(Client.GetInfo(src, ia, out lst)); Assert.That(lst.Count, Is.EqualTo(5)); found = false; foreach (SvnInfoEventArgs e in lst) { if (e.Path.EndsWith("file1.cs")) { found = true; Assert.That(e.Lock, Is.Not.Null, "Is locked - Dir - Children"); } } Assert.That(found); ia.Depth = SvnDepth.Infinity; Assert.That(Client.GetInfo(src, ia, out lst)); Assert.That(lst.Count, Is.EqualTo(5)); found = false; foreach (SvnInfoEventArgs e in lst) { if (e.Path.EndsWith("file1.cs")) { found = true; Assert.That(e.Lock, Is.Not.Null, "Is locked - Dir - Infinity"); } } Assert.That(found); }
public void Lock_ListLocks() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.DefaultBranched); Uri trunk = sbox.Uri; Uri src = new Uri(sbox.Uri, "src/"); Uri srcFile1 = new Uri(src, "file1.cs"); Client.RemoteLock(srcFile1, "Mine!"); Collection <SvnInfoEventArgs> lst; SvnInfoArgs ia = new SvnInfoArgs(); ia.Depth = SvnDepth.Unknown; Assert.That(Client.GetInfo(srcFile1, ia, out lst)); Assert.That(lst.Count == 1); Assert.That(lst[0].Lock, Is.Not.Null, "Is locked - Unknown"); ia.Depth = SvnDepth.Empty; Assert.That(Client.GetInfo(srcFile1, ia, out lst)); Assert.That(lst.Count == 1); Assert.That(lst[0].Lock, Is.Not.Null, "Is locked - Empty"); ia.Depth = SvnDepth.Infinity; Assert.That(Client.GetInfo(srcFile1, ia, out lst)); Assert.That(lst.Count == 1); Assert.That(lst[0].Lock, Is.Not.Null, "Is locked - Infinity"); ia.Depth = SvnDepth.Unknown; Assert.That(Client.GetInfo(src, ia, out lst)); Assert.That(lst.Count, Is.EqualTo(1)); // Just the dir // And the next cases where failing because .Info() didn't pass // an explicit operational revision to svn_client_info2(). ia.Depth = SvnDepth.Files; Assert.That(Client.GetInfo(src, ia, out lst)); Assert.That(lst.Count, Is.EqualTo(5)); bool found = false; foreach (SvnInfoEventArgs e in lst) { if (e.Path.EndsWith("file1.cs")) { found = true; Assert.That(e.Lock, Is.Not.Null, "Is locked - Dir - Files"); } } Assert.That(found); ia.Depth = SvnDepth.Children; Assert.That(Client.GetInfo(src, ia, out lst)); Assert.That(lst.Count, Is.EqualTo(5)); found = false; foreach (SvnInfoEventArgs e in lst) { if (e.Path.EndsWith("file1.cs")) { found = true; Assert.That(e.Lock, Is.Not.Null, "Is locked - Dir - Children"); } } Assert.That(found); ia.Depth = SvnDepth.Infinity; Assert.That(Client.GetInfo(src, ia, out lst)); Assert.That(lst.Count, Is.EqualTo(5)); found = false; foreach (SvnInfoEventArgs e in lst) { if (e.Path.EndsWith("file1.cs")) { found = true; Assert.That(e.Lock, Is.Not.Null, "Is locked - Dir - Infinity"); } } Assert.That(found); }
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); } }
bool ItemExists(Uri target) { bool found = false; using (SvnClient client = NewSvnClient(false, false)) { SvnInfoArgs args = new SvnInfoArgs(); args.ThrowOnError = false; args.Depth = SvnDepth.Empty; return client.Info(target, args, delegate(object sender, SvnInfoEventArgs e) { found = true; }) && found; } }
public void TestChangeLists() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.Default); string WcPath = sbox.Wc; Uri WcUri = sbox.Uri; string file1 = Path.Combine(WcPath, "ChangeListFile1"); string file2 = Path.Combine(WcPath, "ChangeListFile2"); string file3 = Path.Combine(WcPath, "ChangeListFile3"); string file4 = Path.Combine(WcPath, "ChangeListFile4"); using (SvnClient client = NewSvnClient(true, false)) { SvnInfoArgs ia = new SvnInfoArgs(); ia.ThrowOnError = false; SvnInfoEventArgs iea; Collection <SvnInfoEventArgs> ee; Assert.That(client.GetInfo(new Uri(WcUri, "ChangeListFile1"), ia, out ee), Is.False); Assert.That(client.GetInfo(new Uri(WcUri, "ChangeListFile2"), ia, out ee), Is.False); Assert.That(client.GetInfo(new Uri(WcUri, "ChangeListFile3"), ia, out ee), Is.False); Assert.That(client.GetInfo(new Uri(WcUri, "ChangeListFile4"), ia, out ee), Is.False); TouchFile(file1); TouchFile(file2); TouchFile(file3); TouchFile(file4); client.Add(file1); client.Commit(WcPath); client.GetInfo(new Uri(WcUri, "ChangeListFile1"), out iea); Assert.That(iea, Is.Not.Null); client.Add(file2); client.Add(file3); client.Add(file4); client.AddToChangeList(file2, "ChangeListTest-2"); client.AddToChangeList(file3, "ChangeListTest-3"); Collection <SvnListChangeListEventArgs> paths; SvnListChangeListArgs a = new SvnListChangeListArgs(); a.ChangeLists.Add("ChangeListTest-2"); client.GetChangeList(WcPath, a, out paths); Assert.That(paths, Is.Not.Null); Assert.That(paths.Count, Is.EqualTo(1)); Assert.That(paths[0].Path, Is.EqualTo(Path.GetFullPath(file2))); a = new SvnListChangeListArgs(); a.ChangeLists.Add("ChangeListTest-4"); client.GetChangeList(WcPath, a, out paths); Assert.That(paths, Is.Not.Null); Assert.That(paths.Count, Is.EqualTo(0)); SvnCommitArgs ca = new SvnCommitArgs(); ca.ChangeLists.Add("ChangeListTest-2"); client.Commit(WcPath, ca); Assert.That(client.GetInfo(new Uri(WcUri, "ChangeListFile2"), ia, out ee), Is.True); Assert.That(client.GetInfo(new Uri(WcUri, "ChangeListFile3"), ia, out ee), Is.False); Assert.That(client.GetInfo(new Uri(WcUri, "ChangeListFile4"), ia, out ee), Is.False); bool visited = false; a = new SvnListChangeListArgs(); a.ChangeLists.Add("ChangeListTest-3"); client.ListChangeList(WcPath, a, delegate(object sender, SvnListChangeListEventArgs e) { Assert.That(e.Path, Is.EqualTo(file3)); visited = true; }); Assert.That(visited, Is.True); visited = false; client.Status(file4, delegate(object sender, SvnStatusEventArgs e) { Assert.That(e.FullPath, Is.EqualTo(file4)); Assert.That(e.LocalNodeStatus, Is.EqualTo(SvnStatus.Added)); Assert.That(e.IsRemoteUpdated, Is.False); Assert.That(e.Path, Is.EqualTo(file4)); visited = true; }); Assert.That(visited, Is.True); client.Commit(WcPath); Assert.That(client.GetInfo(new Uri(WcUri, "ChangeListFile3"), ia, out ee), Is.True); Assert.That(client.GetInfo(new Uri(WcUri, "ChangeListFile4"), ia, out ee), Is.True); } }