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; } } } }
public SvnCheckoutResult Checkout(string from, string to, SvnCheckoutSettings settings) { var arguments = settings.ToSharpSvn(); SharpSvn.SvnUpdateResult result; CheckOut(SvnUriTarget.FromString(from), to, arguments, out result); return(new SvnCheckoutResult(result.Revision)); }
public bool RefreshWorkingCopy() { _Logger.Info("Starting to refresh the working copy folder"); if (!IsSvnControlled(WorkingCopyPath)) { _Logger.Info("No working copy folder or currently not under SVN control. Checking out content"); SvnCheckOutArgs checkoutArgs = new SvnCheckOutArgs(); checkoutArgs.Depth = SvnDepth.Infinity; checkoutArgs.Notify += new EventHandler <SvnNotifyEventArgs>(CheckoutNotificationHandler); try { SvnUpdateResult result; bool returncode = _SvnClient.CheckOut(SvnUriTarget.FromString(RepositoryUri), WorkingCopyPath, out result); if (returncode) { _RepositoryRevision = (int)result.Revision; _Logger.Info(String.Format("Sucessfully checked out revision {0} from {1} to {2}", _RepositoryRevision, RepositoryUri, WorkingCopyPath)); } } catch (Exception ex) { _Logger.Fatal(String.Format("Checkout from {0} to {1} failed! - {2}", RepositoryUri, WorkingCopyPath, ex)); return(false); } } else { _Logger.Info("Updating working copy folder"); SvnUpdateArgs updateArgs = new SvnUpdateArgs(); updateArgs.Depth = SvnDepth.Infinity; updateArgs.Notify += new EventHandler <SvnNotifyEventArgs>(CheckoutNotificationHandler); updateArgs.Conflict += new EventHandler <SvnConflictEventArgs>(ConflictHandler); try { SvnUpdateResult result; bool returncode = _SvnClient.Update(WorkingCopyPath, updateArgs, out result); if (!returncode || (result.Revision < 0)) { _Logger.Error(String.Format("Updating from {0} to {1} failed!", RepositoryUri, WorkingCopyPath)); return(false); } _RepositoryRevision = (int)result.Revision; _Logger.Info(String.Format("Sucessfully updated to revision {0}", _RepositoryRevision)); } catch (Exception ex) { _Logger.Fatal(String.Format("Checkout from {0} to {1} failed! - {2}", RepositoryUri, WorkingCopyPath, ex)); return(false); } } return(true); }
/// <summary> /// Выгрузка бранча в рабочую копию /// </summary> /// <param name="workingCopyPath">Путь к рабочей копии</param> /// <param name="url"></param> /// <returns>Результат</returns> private bool CheckoutWorkingCopy(string workingCopyPath, string url) { var svnCheckOutArgs = new SvnCheckOutArgs { IgnoreExternals = false }; svnCheckOutArgs.Notify += SvnCheckOutArgsOnNotify; try { return(CheckOut(SvnUriTarget.FromString(url), workingCopyPath, svnCheckOutArgs)); } catch (ArgumentNullException argumentNullException) { Logger.LogError(argumentNullException.Message, $"Parameter {argumentNullException.ParamName} is empty."); return(false); } finally { svnCheckOutArgs.Notify -= SvnCheckOutArgsOnNotify; } }
/// <summary> /// Слияние родительской ветки в ветку фитчи /// </summary> /// <param name="workingCopyPath">Рабочая папка</param> /// <param name="basePathUrl">URL родительской ветки</param> /// <returns>Результат слияния</returns> private bool MergeBaseBranchIntoFeature(string workingCopyPath, string basePathUrl) { var svnMergeArgs = new SvnMergeArgs { Force = true }; svnMergeArgs.Notify += OnSvnMergeArgsOnNotify; svnMergeArgs.Conflict += OnSvnMergeArgsOnConflict; try { var mergeRange = new SvnRevisionRange(SvnRevision.One, SvnRevision.Head); return(Merge(workingCopyPath, SvnUriTarget.FromString(basePathUrl), mergeRange, svnMergeArgs)); } catch (SvnException svnException) { Logger.LogError(svnException.Message); } finally { svnMergeArgs.Notify -= OnSvnMergeArgsOnNotify; svnMergeArgs.Conflict -= OnSvnMergeArgsOnConflict; } return(false); }
/// <summary> /// Реинтеграция фитчи в родительскую ветку /// </summary> public void ReintegrationMergeToBaseBranch() { string baseWorkingCopyPath = BaseWorkingCopyPath ?? WorkingCopyPath + "_Release"; string baseWorkingCopyUrl = GetBaseBranchPath(GetFeatureFirstRevisionNumber(WorkingCopyPath), WorkingCopyPath); var svnCheckOutArgs = new SvnCheckOutArgs(); svnCheckOutArgs.Notify += SvnCheckOutArgsOnNotify; try { CheckOut(SvnUriTarget.FromString(baseWorkingCopyUrl), baseWorkingCopyPath, svnCheckOutArgs); } finally { svnCheckOutArgs.Notify -= SvnCheckOutArgsOnNotify; } Info(SvnTarget.FromString(WorkingCopyPath), (sender, args) => { }); var svnReintegrationMergeArgs = new SvnReintegrationMergeArgs(); svnReintegrationMergeArgs.Notify += SvnReintegrationMergeArgsOnNotify; svnReintegrationMergeArgs.Conflict += SvnReintegrationMergeArgsOnConflict; try { string workingCopyUrl = string.Empty; Info(WorkingCopyPath, new SvnInfoArgs { Revision = new SvnRevision(SvnRevisionType.Head) } , (sender, args) => workingCopyUrl = args.Uri.ToString()); ReintegrationMerge(baseWorkingCopyPath , SvnTarget.FromString(workingCopyUrl) , svnReintegrationMergeArgs); } catch (SvnClientNotReadyToMergeException e) { Logger.LogError(e.Message, e.Targets.ToString()); } finally { svnReintegrationMergeArgs.Notify -= SvnReintegrationMergeArgsOnNotify; svnReintegrationMergeArgs.Conflict -= SvnReintegrationMergeArgsOnConflict; } RemovePackageProperty(baseWorkingCopyPath); }
public IEnumerable <string> LogUniqueUsers(GitMigrationRequest request, string checkoutPath) { var authors = new List <string>(); SetCredentials(request); try { using (var client = GetSvnClient()) { var repoUrl = SvnUriTarget.FromString(request.RepositorylUrl); var args = GetSvnLogArgs(); client.Log(repoUrl.Uri, args, (o, e) => { authors.Add(e.Author); }); } } catch (SvnRepositoryIOException ex) { throw new SvnMigrationException(ex.Message, ex); } return(authors.Distinct()); }
private static void CheckoutUpdate(Parameters parameters) { using (var client = new SharpSvn.SvnClient()) { SetUpClient(parameters, client); var target = SvnTarget.FromString(parameters.Path); SvnInfoEventArgs svnInfoEventArgs; SvnUpdateResult svnUpdateResult; var nonExistentUrl = false; EventHandler <SvnErrorEventArgs> ignoreNonexistent = (o, eventArgs) => { nonExistentUrl = false; //if (eventArgs.Exception.SubversionErrorCode == 170000) if (eventArgs.Exception.Message.Contains("non-existent in revision")) { nonExistentUrl = true; eventArgs.Cancel = true; } }; if (client.GetWorkingCopyRoot(parameters.Path) == null) { client.SvnError += ignoreNonexistent; var getInfoSucceeded = client.GetInfo(SvnUriTarget.FromString(parameters.Url), out svnInfoEventArgs); client.SvnError -= ignoreNonexistent; if (!getInfoSucceeded) { if (nonExistentUrl) { Console.WriteLine("SVN info reported nonexistent URL; creating remote directory."); if (!client.RemoteCreateDirectory(new Uri(parameters.Url), new SvnCreateDirectoryArgs { CreateParents = true, LogMessage = parameters.Message })) { throw new Exception("Create directory failed on " + parameters.Url); } } else { throw new Exception("SVN info failed"); } } DebugMessage(parameters, "Checking out"); if (client.CheckOut(SvnUriTarget.FromString(parameters.Url), parameters.Path, out svnUpdateResult)) { DebugMessage(parameters, "Done"); Console.WriteLine("Checked out r" + svnUpdateResult.Revision); return; } throw new Exception("SVN checkout failed"); } if (!client.GetInfo(target, out svnInfoEventArgs)) { throw new Exception("SVN info failed"); } if (!UrlsMatch(svnInfoEventArgs.Uri.ToString(), parameters.Url)) { throw new Exception(string.Format("A different URL is already checked out ({0} != {1})", svnInfoEventArgs.Uri, parameters.Url)); } if (parameters.Cleanup) { DebugMessage(parameters, "Cleaning up"); client.CleanUp(parameters.Path); DebugMessage(parameters, "Done"); } if (parameters.Revert) { DebugMessage(parameters, "Reverting"); client.Revert(parameters.Path); DebugMessage(parameters, "Done"); } if (parameters.DeleteUnversioned) { DebugMessage(parameters, "Deleting unversioned files"); Collection <SvnStatusEventArgs> changedFiles; client.GetStatus(parameters.Path, out changedFiles); foreach (var changedFile in changedFiles) { if (changedFile.LocalContentStatus == SvnStatus.NotVersioned) { if (changedFile.NodeKind == SvnNodeKind.Directory) { DebugMessage(parameters, "NodeKind is directory for [" + changedFile.FullPath + "]"); } if ((File.GetAttributes(changedFile.FullPath) & FileAttributes.Directory) == FileAttributes.Directory) { DebugMessage(parameters, "Deleting directory [" + changedFile.FullPath + "] recursively!"); Directory.Delete(changedFile.FullPath, true); } else { DebugMessage(parameters, "Deleting file [" + changedFile.FullPath + "]"); File.Delete(changedFile.FullPath); } } } DebugMessage(parameters, "Done"); } DebugMessage(parameters, "Updating"); if (client.Update(parameters.Path, out svnUpdateResult)) { DebugMessage(parameters, "Done"); Console.WriteLine("Updated to r" + svnUpdateResult.Revision); return; } throw new Exception("SVN update failed"); } }
public override void OnExecute(CommandEventArgs e) { SvnItem theItem = null; string path; bool allowObstructions = false; string projectRoot = e.GetService <IAnkhSolutionSettings>().ProjectRoot; if (e.Command == AnkhCommand.SolutionSwitchDialog) { path = projectRoot; } else if (e.Command == AnkhCommand.SwitchProject) { IProjectFileMapper mapper = e.GetService <IProjectFileMapper>(); path = null; foreach (SccProject item in e.Selection.GetSelectedProjects(true)) { ISccProjectInfo pi = mapper.GetProjectInfo(item); if (pi == null) { continue; } path = pi.ProjectDirectory; break; } if (string.IsNullOrEmpty(path)) { return; } } else { foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false)) { if (item.IsVersioned) { theItem = item; break; } return; } path = theItem.FullPath; } ISvnStatusCache statusCache = e.GetService <ISvnStatusCache>(); SvnItem pathItem = statusCache[path]; Uri uri = pathItem.Uri; if (uri == null) { return; // Should never happen on a real workingcopy } SvnUriTarget target; SvnRevision revision = SvnRevision.None; if (e.Argument is string) { target = SvnUriTarget.FromString((string)e.Argument, true); revision = (target.Revision != SvnRevision.None) ? target.Revision : SvnRevision.Head; } else if (e.Argument is Uri) { target = (Uri)e.Argument; } else { using (SwitchDialog dlg = new SwitchDialog()) { dlg.Context = e.Context; dlg.LocalPath = path; dlg.RepositoryRoot = e.GetService <ISvnStatusCache>()[path].WorkingCopy.RepositoryRoot; dlg.SwitchToUri = uri; dlg.Revision = SvnRevision.Head; if (dlg.ShowDialog(e.Context) != DialogResult.OK) { return; } target = dlg.SwitchToUri; revision = dlg.Revision; allowObstructions = dlg.AllowUnversionedObstructions; } } // Get a list of all documents below the specified paths that are open in editors inside VS HybridCollection <string> lockPaths = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase); IAnkhOpenDocumentTracker documentTracker = e.GetService <IAnkhOpenDocumentTracker>(); foreach (string file in documentTracker.GetDocumentsBelow(path)) { if (!lockPaths.Contains(file)) { lockPaths.Add(file); } } documentTracker.SaveDocuments(lockPaths); // Make sure all files are saved before merging! using (DocumentLock lck = documentTracker.LockDocuments(lockPaths, DocumentLockType.NoReload)) using (lck.MonitorChangesForReload()) { Uri newRepositoryRoot = null; e.GetService <IProgressRunner>().RunModal(CommandStrings.SwitchingTitle, delegate(object sender, ProgressWorkerArgs a) { SvnSwitchArgs args = new SvnSwitchArgs(); args.AllowObstructions = allowObstructions; args.AddExpectedError(SvnErrorCode.SVN_ERR_WC_INVALID_SWITCH); if (revision != SvnRevision.None) { args.Revision = revision; } e.GetService <IConflictHandler>().RegisterConflictHandler(args, a.Synchronizer); if (!a.Client.Switch(path, target, args)) { if (args.LastException.SvnErrorCode != SvnErrorCode.SVN_ERR_WC_INVALID_SWITCH) { return; } // source/target repository is different, check if we can fix this by relocating SvnInfoEventArgs iea; if (a.Client.GetInfo(target, out iea)) { if (pathItem.WorkingCopy.RepositoryId != iea.RepositoryId) { e.Context.GetService <IAnkhDialogOwner>() .MessageBox.Show("Cannot switch to different repository because the repository UUIDs are different", "Cannot switch", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (pathItem.WorkingCopy.RepositoryRoot != iea.RepositoryRoot) { newRepositoryRoot = iea.RepositoryRoot; } else if (pathItem.WorkingCopy.RepositoryId == Guid.Empty) { // No UUIDs and RepositoryRoot equal. Throw/show error? throw args.LastException; } } } }); if (newRepositoryRoot != null && DialogResult.Yes == e.Context.GetService <IAnkhDialogOwner>() .MessageBox.Show(string.Format("The repository root specified is different from the one in your " + "working copy. Would you like to relocate '{0}' from '{1}' to '{2}'?", pathItem.WorkingCopy.FullPath, pathItem.WorkingCopy.RepositoryRoot, newRepositoryRoot), "Relocate", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { // We can fix this by relocating string wcRoot = pathItem.WorkingCopy.FullPath; try { e.GetService <IProgressRunner>().RunModal( CommandStrings.RelocatingTitle, delegate(object sender, ProgressWorkerArgs a) { a.Client.Relocate(wcRoot, pathItem.WorkingCopy.RepositoryRoot, newRepositoryRoot); }); } finally { statusCache.MarkDirtyRecursive(wcRoot); e.GetService <IFileStatusMonitor>().ScheduleGlyphUpdate(statusCache.GetCachedBelow(wcRoot)); } if (DialogResult.Yes == e.Context.GetService <IAnkhDialogOwner>() .MessageBox.Show(string.Format("Would you like to try to switch '{0}' to '{1}' again?", path, target), "Switch", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { // Try to switch again e.GetService <IProgressRunner>().RunModal( CommandStrings.SwitchingTitle, delegate(object sender, ProgressWorkerArgs a) { SvnSwitchArgs args = new SvnSwitchArgs(); if (revision != SvnRevision.None) { args.Revision = revision; } args.AllowObstructions = allowObstructions; e.GetService <IConflictHandler>().RegisterConflictHandler(args, a.Synchronizer); a.Client.Switch(path, target, args); }); } } } }