Beispiel #1
0
        public void Copy_ReposCopy()
        {
            SvnSandBox sbox     = new SvnSandBox(this);
            Uri        reposUri = sbox.CreateRepository(SandBoxRepository.Default);
            Uri        trunk    = new Uri(reposUri, "trunk/");
            Uri        branch   = new Uri(reposUri, "my-branches/new-branch");

            SvnCopyArgs ca = new SvnCopyArgs();

            ca.LogMessage    = "Message";
            ca.CreateParents = true;
            Client.RemoteCopy(trunk, branch, ca);

            int n = 0;

            Client.List(branch, delegate(object sender, SvnListEventArgs e)
            {
                if (e.Entry.NodeKind == SvnNodeKind.File)
                {
                    n++;
                }
            });

            Assert.That(n, Is.GreaterThan(0), "Copied files");
        }
Beispiel #2
0
        internal bool CreateTag(SvnListEventArgs selectedTrunk, string tagName)
        {
            try
            {
                if (selectedTrunk != null)
                {
                    using (SvnClient client = new SvnClient())
                    {
                        // Bind the SharpSvn UI to our client for SSL certificate and credentials
                        SvnUIBindArgs bindArgs = new SvnUIBindArgs();
                        SvnUI.Bind(client, bindArgs);

                        string relativeComponentPath = selectedTrunk.BaseUri.AbsoluteUri;

                        Uri tagUri = new Uri(relativeComponentPath + "tags/" + tagName);

                        SvnTarget source = SvnTarget.FromUri(selectedTrunk.Uri);

                        SvnCopyArgs arg = new SvnCopyArgs();
                        arg.CreateParents = false;
                        arg.LogMessage    = string.Format("ADMIN-0: Tag Created from Trunk");

                        return(client.RemoteCopy(source, tagUri, arg));
                    }
                }
                return(false);
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #3
0
        protected override void ExecuteSVNTask(SvnClient client)
        {
            if (Dir == null)
            {
                Dir = new DirectoryInfo(Project.BaseDirectory);
            }

            if (!Dir.Exists)
            {
                throw new BuildException(string.Format(Resources.MissingDirectory, Dir.FullName), Location);
            }

            SVNFunctions svnFunctions = new SVNFunctions(Project, Properties);
            string sourceUri = svnFunctions.GetUriFromPath(Dir.FullName);
            Log(Level.Info, Resources.SVNCopyCopying, sourceUri, SvnUri);

            SvnCopyArgs args = new SvnCopyArgs();
            args.ThrowOnError = true;
            args.LogMessage = Message;

            SvnCommitResult result;
            client.RemoteCopy(SvnTarget.FromString(sourceUri), SvnUri, args, out result);

            if (result != null)
            {
                Log(Level.Info, Resources.SVNCopyResult, Dir.FullName, SvnUri, result.Revision, result.Author);
            }
        }
Beispiel #4
0
        internal bool CreateBranch(SvnListEventArgs selectedTag, string branchName)
        {
            try
            {
                if (selectedTag != null)
                {
                    using (SvnClient client = new SvnClient())
                    {
                        // Bind the SharpSvn UI to our client for SSL certificate and credentials
                        SvnUIBindArgs bindArgs = new SvnUIBindArgs();
                        SvnUI.Bind(client, bindArgs);

                        string relativeComponentPath = string.Join(string.Empty, selectedTag.BaseUri.Segments.Take(selectedTag.BaseUri.Segments.Count() - 1).ToArray());
                        string server = selectedTag.BaseUri.GetComponents(UriComponents.SchemeAndServer, UriFormat.SafeUnescaped);

                        Uri barnchUri = new Uri(server + relativeComponentPath + "branches/project/" + branchName);

                        SvnTarget source = SvnTarget.FromUri(selectedTag.Uri);

                        SvnCopyArgs arg = new SvnCopyArgs();
                        arg.CreateParents = false;
                        arg.LogMessage    = string.Format("ADMIN-0: Branch Created from Tag {0}", selectedTag.Name);

                        return(client.RemoteCopy(source, barnchUri, arg));
                    }
                }
                return(false);
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #5
0
        public void MetaCopy(string from, string newName)
        {
            SvnCopyArgs ca = new SvnCopyArgs();

            ca.ThrowOnError = false;
            ca.MetaDataOnly = true;

            Client.Copy(from, newName, ca);
        }
Beispiel #6
0
        public void Copy_ReposToWcWithParents()
        {
            SvnSandBox sbox = new SvnSandBox(this);

            sbox.Create(SandBoxRepository.AnkhSvnCases);
            string WcPath = sbox.Wc;

            Uri         srcUri = new Uri(sbox.RepositoryUri, "trunk/Form.cs");
            SvnCopyArgs ca     = new SvnCopyArgs();

            ca.CreateParents = true;
            Client.Copy(srcUri, Path.Combine(WcPath, "dir/sub/with/more/levels"), ca);
        }
Beispiel #7
0
        public void Copy_SimpleBranch0()
        {
            SvnSandBox sbox     = new SvnSandBox(this);
            Uri        reposUri = sbox.CreateRepository(SandBoxRepository.Default);
            Uri        trunk    = new Uri(reposUri, "trunk/");

            SvnCopyArgs ca = new SvnCopyArgs();

            ca.CreateParents = true;

            // Subversion 1.5.4 throws an AccessViolationException here
            Client.RemoteCopy(trunk, new Uri(reposUri, "branch/"), ca);
        }
Beispiel #8
0
        public void Tag(string name, string taggerName, string taggerEmail, string comment, DateTime localTime, string taggedPath)
        {
            /*
             * TempFile commentFile;
             *
             * var args = "tag";
             * AddComment(comment, ref args, out commentFile);
             *
             * // tag names are not quoted because they cannot contain whitespace or quotes
             * args += " -- " + name;
             *
             * using (commentFile)
             * {
             *  var startInfo = GetStartInfo(args);
             *  startInfo.EnvironmentVariables["GIT_COMMITTER_NAME"] = taggerName;
             *  startInfo.EnvironmentVariables["GIT_COMMITTER_EMAIL"] = taggerEmail;
             *  startInfo.EnvironmentVariables["GIT_COMMITTER_DATE"] = GetUtcTimeString(localTime);
             *
             *  ExecuteUnless(startInfo, null);
             * }
             */
            using (var client = new SvnClient())
            {
                SvnUI.Bind(client, parentWindow);
                var svnCopyArgs = new SvnCopyArgs {
                    LogMessage = comment, CreateParents = true, AlwaysCopyAsChild = false
                };

                var workingCopyUri = client.GetUriFromWorkingCopy(workingCopyPath);
                var tagsUri        = client.GetUriFromWorkingCopy(tagPath);
                var sourceUri      = useSvnStandardDirStructure ? client.GetUriFromWorkingCopy(trunkPath) : workingCopyUri;
                var tagUri         = new Uri(useSvnStandardDirStructure ? tagsUri : workingCopyUri, name);

                var svnCommitResult = (SvnCommitResult)null;
                var result          = client.RemoteCopy(sourceUri, tagUri, svnCopyArgs, out svnCommitResult);
                if (result)
                {
                    result &= client.SetRevisionProperty(svnCommitResult.RepositoryRoot, new SvnRevision(svnCommitResult.Revision), SvnPropertyNames.SvnAuthor, taggerName);
                    result &= client.SetRevisionProperty(svnCommitResult.RepositoryRoot, new SvnRevision(svnCommitResult.Revision), SvnPropertyNames.SvnDate, SvnPropertyNames.FormatDate(localTime));
                }
                result &= client.Update(workingCopyPath, new SvnUpdateArgs {
                    AddsAsModifications = false, AllowObstructions = false, Depth = SvnDepth.Infinity, IgnoreExternals = true, KeepDepth = true, Revision = SvnRevision.Head, UpdateParents = false
                });
            }
        }
Beispiel #9
0
        /// <summary>
        ///     Копирование базового ветки в ветку фитчи
        /// </summary>
        /// <param name="featureName">Название фитчи</param>
        /// <param name="featureNewUrl">URL новой ветки фитчи</param>
        /// <param name="revision">Номер ревизии из которой выделяется копия</param>
        /// <returns>Результат</returns>
        private bool CopyBaseBranch(string featureName, string featureNewUrl, long revision)
        {
            var svnCopyArgs = new SvnCopyArgs {
                LogMessage = string.Format(Resources.SvnUtils_CopyBaseBranch_Init_Feature, featureName),
                Revision   = new SvnRevision(revision)
            };

            svnCopyArgs.Notify += SvnCopyArgsOnNotify;
            try {
                return(RemoteCopy(SvnTarget.FromString(BranchReleaseUrl), new Uri(featureNewUrl), svnCopyArgs));
            } catch (ArgumentNullException argumentNullException) {
                Logger.LogError(argumentNullException.Message,
                                $"Parameter {argumentNullException.ParamName} is empty.");
                return(false);
            } finally {
                svnCopyArgs.Notify -= SvnCopyArgsOnNotify;
            }
        }
Beispiel #10
0
        static public void CreateBranch(Uri fromUri, Uri toUri)
        {
            using (SvnClient svnClient = new SvnClient())
            {
                try
                {
                    SvnTarget target = SvnTarget.FromUri(fromUri);
                    SvnUriTarget targetBranch = new SvnUriTarget(toUri);

                    SvnCopyArgs args = new SvnCopyArgs();
                    args.LogMessage = Properties.Settings.Default.SVN_Commit_Msg;

                    svnClient.RemoteCopy(target, toUri, args);
                }
                catch (Exception ex)
                {
                    LogMessage(ex.Message);
                }
            }
        }
Beispiel #11
0
        public void ChangedDirs()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            Uri        uri  = sbox.CreateRepository(SandBoxRepository.Empty);

            using (InstallHook(uri, SvnHookType.PreCommit, OnChangedDirs))
            {
                using (SvnClient cl = new SvnClient())
                {
                    SvnCreateDirectoryArgs da = new SvnCreateDirectoryArgs();
                    da.CreateParents = true;
                    da.LogMessage    = "Created!";
                    cl.RemoteCreateDirectories(
                        new Uri[]
                    {
                        new Uri(uri, "a/b/c/d/e/f"),
                        new Uri(uri, "a/b/c/d/g/h"),
                        new Uri(uri, "i/j/k"),
                        new Uri(uri, "l/m/n"),
                        new Uri(uri, "l/m/n/o/p")
                    }, da);
                }
            }

            using (InstallHook(uri, SvnHookType.PreCommit, OnCopyDir))
            {
                using (SvnClient cl = new SvnClient())
                {
                    SvnCopyArgs ca = new SvnCopyArgs();
                    ca.CreateParents = true;
                    ca.LogMessage    = "Created!";
                    cl.RemoteCopy(
                        new SvnUriTarget[]
                    {
                        new Uri(uri, "a/b/c/d"),
                        new Uri(uri, "i/j")
                    }, uri, ca);
                }
            }
        }
Beispiel #12
0
        public void ChangedDirs()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            Uri uri = sbox.CreateRepository(SandBoxRepository.Empty);
            using (InstallHook(uri, SvnHookType.PreCommit, OnChangedDirs))
            {
                using (SvnClient cl = new SvnClient())
                {
                    SvnCreateDirectoryArgs da = new SvnCreateDirectoryArgs();
                    da.CreateParents = true;
                    da.LogMessage = "Created!";
                    cl.RemoteCreateDirectories(
                    new Uri[]
                        {
                        new Uri(uri, "a/b/c/d/e/f"),
                        new Uri(uri, "a/b/c/d/g/h"),
                        new Uri(uri, "i/j/k"),
                        new Uri(uri, "l/m/n"),
                        new Uri(uri, "l/m/n/o/p")
                        }, da);
                }
            }

            using (InstallHook(uri, SvnHookType.PreCommit, OnCopyDir))
            {
                using (SvnClient cl = new SvnClient())
                {
                    SvnCopyArgs ca = new SvnCopyArgs();
                    ca.CreateParents = true;
                    ca.LogMessage = "Created!";
                    cl.RemoteCopy(
                    new SvnUriTarget[]
                        {
                        new Uri(uri, "a/b/c/d"),
                        new Uri(uri, "i/j")
                        }, uri, ca);
                }
            }
        }
Beispiel #13
0
        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;
                    }
                }
            }
        }
        private static void CheckOutAndOpenProject(CommandEventArgs e, SvnUriTarget checkoutLocation, SvnRevision revision, Uri projectTop, string localDir, Uri projectUri)
        {
            IProgressRunner runner = e.GetService <IProgressRunner>();

            runner.RunModal(CommandStrings.CheckingOutSolution,
                            delegate(object sender, ProgressWorkerArgs ee)
            {
                PerformCheckout(ee, checkoutLocation, revision, localDir);
            });

            Uri file = projectTop.MakeRelativeUri(projectUri);

            string projectFile = SvnTools.GetNormalizedFullPath(Path.Combine(localDir, SvnTools.UriPartToPath(file.ToString())));

            AddProject(e, projectFile);

            using (ProjectAddInfoDialog pai = new ProjectAddInfoDialog())
            {
                IAnkhSolutionSettings ss    = e.GetService <IAnkhSolutionSettings>();
                ISvnStatusCache       cache = e.GetService <ISvnStatusCache>();
                SvnItem rootItem;

                pai.EnableSlnConnection = false;

                if (ss == null || cache == null ||
                    string.IsNullOrEmpty(ss.ProjectRoot) ||
                    !SvnItem.IsBelowRoot(localDir, ss.ProjectRoot) ||
                    null == (rootItem = cache[localDir]))
                {
                    pai.EnableExternal = false;
                    pai.EnableCopy     = false;
                }
                else
                {
                    SvnItem dir = rootItem.Parent;

                    if (ss.ProjectRootSvnItem != null &&
                        ss.ProjectRootSvnItem.IsVersioned)
                    {
                        HybridCollection <string> dirs = new HybridCollection <string>();
                        SvnItem exDir = dir;

                        while (exDir != null && exDir.IsBelowPath(ss.ProjectRoot))
                        {
                            if (exDir.IsVersioned && exDir.WorkingCopy == ss.ProjectRootSvnItem.WorkingCopy)
                            {
                                dirs.Add(exDir.FullPath);
                            }

                            exDir = exDir.Parent;
                        }
                        pai.SetExternalDirs(dirs);
                        pai.EnableExternal = true;
                    }
                    else
                    {
                        pai.EnableExternal = false;
                    }

                    if (rootItem.WorkingCopy != null && dir.WorkingCopy != null)
                    {
                        pai.EnableCopy = (rootItem.WorkingCopy.RepositoryRoot == dir.WorkingCopy.RepositoryRoot) &&
                                         (rootItem.WorkingCopy.RepositoryId == dir.WorkingCopy.RepositoryId);
                    }
                    else
                    {
                        pai.EnableCopy = false;
                    }
                }

                if (pai.ShowDialog(e.Context) == DialogResult.OK)
                {
                    switch (pai.SelectedMode)
                    {
                    case ProjectAddMode.External:
                        if (pai.ExternalLocation != null)
                        {
                            using (SvnClient cl = e.GetService <ISvnClientPool>().GetNoUIClient())
                            {
                                string externals;
                                if (!cl.TryGetProperty(pai.ExternalLocation, SvnPropertyNames.SvnExternals, out externals))
                                {
                                    externals = "";
                                }

                                SvnExternalItem sei;
                                if (pai.ExternalLocked)
                                {
                                    sei = new SvnExternalItem(SvnItem.SubPath(localDir, pai.ExternalLocation), checkoutLocation.Uri, revision, revision);
                                }
                                else
                                {
                                    sei = new SvnExternalItem(SvnItem.SubPath(localDir, pai.ExternalLocation), checkoutLocation.Uri);
                                }

                                externals = sei.ToString(true) + Environment.NewLine + externals;
                                cl.SetProperty(pai.ExternalLocation, SvnPropertyNames.SvnExternals, externals);
                            }
                        }
                        break;

                    case ProjectAddMode.Copy:
                        using (SvnClient cl = e.GetService <ISvnClientPool>().GetClient())
                        {
                            string tmpDir = localDir + "-Src-copyTmp";
                            Directory.CreateDirectory(tmpDir);
                            Directory.Move(Path.Combine(localDir, SvnClient.AdministrativeDirectoryName), Path.Combine(tmpDir, SvnClient.AdministrativeDirectoryName));
                            SvnCopyArgs ma = new SvnCopyArgs();
                            ma.MetaDataOnly = true;
                            cl.Copy(tmpDir, localDir, ma);
                            SvnItem.DeleteDirectory(tmpDir, true);
                            cache.MarkDirtyRecursive(localDir);
                        }
                        break;

                    case ProjectAddMode.Unversioned:
                        cache.MarkDirtyRecursive(localDir);
                        SvnItem.DeleteDirectory(Path.Combine(localDir, SvnClient.AdministrativeDirectoryName), true);
                        e.GetService <IFileStatusMonitor>().ScheduleGlyphUpdate(projectFile);    // And everything else in the project
                        break;
                    }
                }
            }
        }
Beispiel #15
0
        public override void OnExecute(CommandEventArgs e)
        {
            Uri  target = null;
            Uri  root   = null;
            bool up     = false;

            List <SvnUriTarget> copyFrom = new List <SvnUriTarget>();

            foreach (ISvnRepositoryItem item in e.Selection.GetSelection <ISvnRepositoryItem>())
            {
                SvnUriTarget utt = item.Origin.Target as SvnUriTarget;

                if (utt == null)
                {
                    utt = new SvnUriTarget(item.Origin.Uri, item.Origin.Target.Revision);
                }

                copyFrom.Add(utt);

                if (root == null)
                {
                    root = item.Origin.RepositoryRoot;
                }

                if (target == null)
                {
                    target = item.Origin.Uri;
                }
                else
                {
                    Uri itemUri = SvnTools.GetNormalizedUri(item.Origin.Uri);

                    Uri r = item.Origin.Uri.MakeRelativeUri(target);

                    if (r.IsAbsoluteUri)
                    {
                        target = null;
                        break;
                    }

                    string rs = r.ToString();

                    if (r.ToString().StartsWith("/", StringComparison.Ordinal))
                    {
                        target = new Uri(target, "/");
                        break;
                    }

                    if (!up && r.ToString().StartsWith("../"))
                    {
                        target = new Uri(target, "../");
                        up     = true;
                    }
                }
            }

            bool   isMove = e.Command == AnkhCommand.ReposMoveTo;
            Uri    toUri;
            string logMessage;

            using (CopyToDialog dlg = new CopyToDialog())
            {
                dlg.RootUri     = root;
                dlg.SelectedUri = target;

                dlg.Text = isMove ? "Move to Url" : "Copy to Url";

                if (dlg.ShowDialog(e.Context) != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }

                toUri      = dlg.SelectedUri;
                logMessage = dlg.LogMessage;
            }

            // TODO: BH: Make sure the 2 attempts actually make sense

            e.GetService <IProgressRunner>().RunModal(isMove ? CommandStrings.Moving : CommandStrings.Copying,
                                                      delegate(object snd, ProgressWorkerArgs a)
            {
                if (isMove)
                {
                    List <Uri> uris = new List <Uri>();
                    foreach (SvnUriTarget ut in copyFrom)
                    {
                        uris.Add(ut.Uri);
                    }

                    SvnMoveArgs ma   = new SvnMoveArgs();
                    ma.LogMessage    = logMessage;
                    ma.CreateParents = true;

                    try
                    {
                        // First try with the full new name
                        a.Client.RemoteMove(uris, toUri, ma);
                    }
                    catch (SvnFileSystemException fs)
                    {
                        if (fs.SvnErrorCode != SvnErrorCode.SVN_ERR_FS_ALREADY_EXISTS)
                        {
                            throw;
                        }

                        // If exists retry below this directory with the existing name
                        ma.AlwaysMoveAsChild = true;
                        a.Client.RemoteMove(uris, toUri, ma);
                    }
                }
                else
                {
                    SvnCopyArgs ca   = new SvnCopyArgs();
                    ca.LogMessage    = logMessage;
                    ca.CreateParents = true;

                    try
                    {
                        // First try with the full new name
                        a.Client.RemoteCopy(copyFrom, toUri, ca);
                    }
                    catch (SvnFileSystemException fs)
                    {
                        if (fs.SvnErrorCode != SvnErrorCode.SVN_ERR_FS_ALREADY_EXISTS)
                        {
                            throw;
                        }

                        // If exists retry below this directory with the existing name
                        ca.AlwaysCopyAsChild = true;
                        a.Client.RemoteCopy(copyFrom, toUri, ca);
                    }
                }
            });

            // TODO: Send some notification to the repository explorer on this change?
        }
Beispiel #16
0
        public void Copy_ReposCopy()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            Uri reposUri = sbox.CreateRepository(SandBoxRepository.Default);
            Uri trunk = new Uri(reposUri, "trunk/");
            Uri branch = new Uri(reposUri, "my-branches/new-branch");

            SvnCopyArgs ca = new SvnCopyArgs();
            ca.LogMessage = "Message";
            ca.CreateParents = true;
            Client.RemoteCopy(trunk, branch, ca);

            int n = 0;
            Client.List(branch, delegate(object sender, SvnListEventArgs e)
            {
                if (e.Entry.NodeKind == SvnNodeKind.File)
                    n++;
            });

            Assert.That(n, Is.GreaterThan(0), "Copied files");
        }
Beispiel #17
0
        public override void OnExecute(CommandEventArgs e)
        {
            ISvnRepositoryItem item = EnumTools.GetSingle(e.Selection.GetSelection <ISvnRepositoryItem>());

            if (item == null)
            {
                return;
            }

            string          copyTo;
            bool            copyBelow     = false;
            bool            suggestExport = false;
            ISvnStatusCache cache         = e.GetService <ISvnStatusCache>();

            if (item.NodeKind == SharpSvn.SvnNodeKind.Directory)
            {
                using (FolderBrowserDialog fd = new FolderBrowserDialog())
                {
                    fd.ShowNewFolderButton = false;

                    if (DialogResult.OK != fd.ShowDialog(e.Context.DialogOwner))
                    {
                        return;
                    }

                    copyTo    = fd.SelectedPath;
                    copyBelow = true;

                    SvnItem dirItem = cache[copyTo];

                    if (dirItem == null || !dirItem.IsVersioned)
                    {
                        suggestExport = true;
                    }
                }
            }
            else
            {
                using (SaveFileDialog sfd = new SaveFileDialog())
                {
                    sfd.CheckPathExists = true;
                    sfd.OverwritePrompt = true;
                    string name = item.Origin.Target.FileName;
                    string ext  = Path.GetExtension(item.Origin.Target.FileName);
                    sfd.Filter   = string.Format("{0} files|*.{0}|All files (*.*)|*", ext.TrimStart('.'));
                    sfd.FileName = name;

                    if (DialogResult.OK != sfd.ShowDialog(e.Context.DialogOwner))
                    {
                        return;
                    }

                    copyTo = SvnTools.GetNormalizedFullPath(sfd.FileName);

                    SvnItem fileItem = cache[copyTo];

                    if (File.Exists(copyTo))
                    {
                        // We prompted to confirm; remove the file!

                        if (fileItem.IsVersioned)
                        {
                            e.GetService <IProgressRunner>().RunModal(CommandStrings.Copying,
                                                                      delegate(object sender, ProgressWorkerArgs a)
                            {
                                SvnDeleteArgs da = new SvnDeleteArgs();
                                da.Force         = true;
                                a.Client.Delete(copyTo, da);
                            });
                        }
                        else
                        {
                            SvnItem.DeleteNode(copyTo);
                        }
                    }

                    SvnItem dir = fileItem.Parent;

                    if (dir == null || !(dir.IsVersioned && dir.IsVersionable))
                    {
                        suggestExport = true;
                    }
                }
            }

            if (!suggestExport)
            {
                e.GetService <IProgressRunner>().RunModal(CommandStrings.Copying,
                                                          delegate(object sender, ProgressWorkerArgs a)
                {
                    SvnCopyArgs ca   = new SvnCopyArgs();
                    ca.CreateParents = true;
                    if (copyBelow)
                    {
                        ca.AlwaysCopyAsChild = true;
                    }

                    a.Client.Copy(item.Origin.Target, copyTo, ca);
                });
            }
            else
            {
                AnkhMessageBox mb = new AnkhMessageBox(e.Context);

                if (DialogResult.Yes == mb.Show(CommandStrings.NotInWorkingCopyExportInstead,
                                                CommandStrings.NotInWorkingCopyTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                {
                    e.GetService <IProgressRunner>().RunModal(CommandStrings.Exporting,
                                                              delegate(object sender, ProgressWorkerArgs a)
                    {
                        SvnExportArgs ea = new SvnExportArgs();
                        ea.Revision      = item.Revision;
                        ea.Overwrite     = true;

                        a.Client.Export(item.Origin.Target, copyTo, ea);
                    });
                }
            }
        }
Beispiel #18
0
        public void Copy_SimpleBranch1()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            Uri reposUri = sbox.CreateRepository(SandBoxRepository.Default);
            Uri trunk = new Uri(reposUri, "trunk/");

            Client.RemoteCopy(trunk, new Uri(reposUri, "branch/"));

            SvnCopyArgs ca = new SvnCopyArgs();
            ca.CreateParents = true;

            // Subversion 1.5.4 throws an AccessViolationException here
            Client.RemoteCopy(trunk, new Uri(reposUri, "branch/"), ca);
        }
Beispiel #19
0
        public void Copy_ReposToWcWithParents()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            sbox.Create(SandBoxRepository.AnkhSvnCases);
            string WcPath = sbox.Wc;

            Uri srcUri = new Uri(sbox.RepositoryUri, "trunk/Form.cs");
            SvnCopyArgs ca = new SvnCopyArgs();
            ca.CreateParents = true;
            Client.Copy(srcUri, Path.Combine(WcPath, "dir/sub/with/more/levels"), ca);
        }
Beispiel #20
0
        private static void ApplyTag(IVSSItem vssFile, SvnClient svnClient, IVSSVersion vssVersion, Tag tag)
        {
            var copyArgs = new SvnCopyArgs
            {
                LogMessage =
                    string.Format("Released {0}\n{1}", vssVersion.Label, vssVersion.LabelComment)
            };

            migrateLog.DebugFormat("------------------------------------");
            migrateLog.DebugFormat(string.Format("Setting Tag:"));
            migrateLog.DebugFormat(string.Format("Label: {0}", vssVersion.Label));
            migrateLog.DebugFormat(string.Format("Comment: {0}", vssVersion.LabelComment));
            migrateLog.DebugFormat(string.Format("from Url: {0}", tag.fromUrlString));
            migrateLog.DebugFormat(string.Format("to Url: {0}", tag.tagString));


            try
            {
                svnClient.RemoteCopy(SvnTarget.FromString(tag.fromUrlString),
                                     new Uri(tag.tagString),
                                     copyArgs);

                CounterfeitRevProps(svnClient, SvnTarget.FromUri(new Uri(tag.tagString)), vssVersion);
            }


            catch (SvnFileSystemException e)
            {
                //tags with same names get handled here

                if (e.ToString().Contains("already exists"))
                {
                    int index = tag.tagString.IndexOf(svnTAG) + svnTAG.Length + 1;
                    //FIXME: correct calculation of // and /
                    string newstring = tag.tagString.Insert(index, vssFile.Parent.Name + "_");
                    tag.tagString = newstring;
                    migrateLog.DebugFormat("Tag already existing, adding parent name ...");

                    ApplyTag(vssFile, svnClient, vssVersion, tag);

                    return;
                }

                migrateLog.ErrorFormat("Error: Line was: " + tag.fromUrlString);
                migrateLog.ErrorFormat(e.ToString());
                migrateLog.InfoFormat(String.Format("Fallback, tagging repository successful: "
                                                    + (svnClient.RemoteCopy(
                                                           SvnTarget.FromString(String.Format("{0}/{1}", svnURL,
                                                                                              svnPROJ)),
                                                           new Uri(tag.tagString)
                                                           , copyArgs))));


                CounterfeitRevProps(svnClient, SvnTarget.FromUri(new Uri(tag.tagString)), vssVersion);
            }

            catch (Exception e)
            {
                migrateLog.ErrorFormat(e.ToString());
                //Console.Out.WriteLine("Press a key to continue");
                //Console.ReadKey();
            }

            migrateLog.DebugFormat("------------------------------------");
        }
Beispiel #21
0
        public void Tag(string name, string taggerName, string taggerEmail, string comment, DateTime localTime, string taggedPath)
        {
            /*
            TempFile commentFile;

            var args = "tag";
            AddComment(comment, ref args, out commentFile);

            // tag names are not quoted because they cannot contain whitespace or quotes
            args += " -- " + name;

            using (commentFile)
            {
                var startInfo = GetStartInfo(args);
                startInfo.EnvironmentVariables["GIT_COMMITTER_NAME"] = taggerName;
                startInfo.EnvironmentVariables["GIT_COMMITTER_EMAIL"] = taggerEmail;
                startInfo.EnvironmentVariables["GIT_COMMITTER_DATE"] = GetUtcTimeString(localTime);

                ExecuteUnless(startInfo, null);
            }
            */
            using (var client = new SvnClient())
            {
                SvnUI.Bind(client, parentWindow);
                var svnCopyArgs = new SvnCopyArgs { LogMessage = comment, CreateParents = true, AlwaysCopyAsChild = false };

                var workingCopyUri = client.GetUriFromWorkingCopy(workingCopyPath);
                var tagsUri = client.GetUriFromWorkingCopy(tagPath);
                var sourceUri = useSvnStandardDirStructure ? client.GetUriFromWorkingCopy(trunkPath) : workingCopyUri;
                var tagUri = new Uri(useSvnStandardDirStructure ? tagsUri : workingCopyUri, name);

                var svnCommitResult = (SvnCommitResult)null;
                var result = client.RemoteCopy(sourceUri, tagUri, svnCopyArgs, out svnCommitResult);
                if (result)
                {
                    result &= client.SetRevisionProperty(svnCommitResult.RepositoryRoot, new SvnRevision(svnCommitResult.Revision), SvnPropertyNames.SvnAuthor, taggerName);
                    result &= client.SetRevisionProperty(svnCommitResult.RepositoryRoot, new SvnRevision(svnCommitResult.Revision), SvnPropertyNames.SvnDate, SvnPropertyNames.FormatDate(localTime));
                }
                result &= client.Update(workingCopyPath, new SvnUpdateArgs { AddsAsModifications = false, AllowObstructions = false, Depth = SvnDepth.Infinity, IgnoreExternals = true, KeepDepth = true, Revision = SvnRevision.Head, UpdateParents = false });
            }
        }
Beispiel #22
0
        static bool MakeTagBranch(SvnClient client, ref SvnExternalItem ei, string hostUrl, string releaseName, string branchTagType)
        {
            Exter.EPinType oldType;
            if (!Exter.GetExternalType(ei, out oldType))
            {
                return(false);
            }

            string fullRefUrl;

            if (!Exter.GetFullReferenceUrl(client, ei, hostUrl, out fullRefUrl))
            {
                return(false);
            }

            var origBaseUrl     = Exter.StripStdSvnLayoutFromUrl(ei.Reference);
            var origTaggizedUrl = $"{origBaseUrl}/{branchTagType}/{releaseName}";

            var fullBaseUrl     = Exter.StripStdSvnLayoutFromUrl(fullRefUrl);
            var fullTaggizedUrl = $"{fullBaseUrl}/{branchTagType}/{releaseName}";

            switch (oldType)
            {
            case Exter.EPinType.Head:
            case Exter.EPinType.Branch:
            {
                // create tag by svncopying from the head

                try
                {
                    SvnCommitResult copyResult;
                    var             args = new SvnCopyArgs();
                    args.LogMessage    = "";
                    args.CreateParents = true;
                    if (!client.RemoteCopy(new SvnUriTarget(fullRefUrl, SvnRevision.Head), new Uri(fullTaggizedUrl), args, out copyResult))
                    {
                        return(false);
                    }
                }
                catch (SvnException ex)
                {
                    Logger.Warn(ex, $"Failed creating tag/branch '{fullTaggizedUrl}'");
                }

                ei = new SvnExternalItem(ei.Target, origTaggizedUrl);

                return(true);
            }

            case Exter.EPinType.Peg:
            {
                // create tag by svncopying from given peg revision
                try
                {
                    SvnCommitResult copyResult;
                    var             args = new SvnCopyArgs();
                    args.LogMessage    = "";
                    args.CreateParents = true;
                    if (!client.RemoteCopy(new SvnUriTarget(fullRefUrl, ei.Revision), new Uri(fullTaggizedUrl), args, out copyResult))
                    {
                        return(false);
                    }
                }
                catch (SvnException ex)
                {
                    Logger.Warn(ex, $"Failed creating tag/branch '{fullTaggizedUrl}'");
                }

                ei = new SvnExternalItem(ei.Target, origTaggizedUrl);

                return(true);
            }

            case Exter.EPinType.Tag:
            {
                // leave the tag as is
                return(false);
            }

            default:
            {
                // unknown Pin type
                return(false);
            }
            }

            //return false;
        }
Beispiel #23
0
        /// <summary>
        /// Creates a release by copying an existing one and changing the externals type
        /// Only the root externals are changed. All in repository, no WC involved.
        /// </summary>
        /// <param name="srcUrl">
        ///    svn://server/releases/head
        ///    svn://server/releases/candidate/2.0.1
        ///    svn://server/releases/final/2.0.1
        /// </param>
        /// <param name="destUrl">new url
        ///    svn://server/releases/head
        ///    svn://server/releases/candidate/2.0.1
        ///    svn://server/releases/final/2.0.1
        /// </param>
        /// <param name="pinType">the resulting type of externals</param>
        /// <param name="releaseName">name of the release Can contain sub-folders like 'sub1/sub2/version'</param>
        /// <returns></returns>
        public static bool Copy(SvnClient client, string srcUrl, string destUrl, Exter.EPinType pinType, string releaseName = null)
        {
            /*
             * - udělá svn copy (to zkopíruje externalsy jak jsou)
             * - pozmění kořenové externalsy tak, že každý z nich napinuje (pokud ještě není) na konkrétní revizi
             */

            // args check
            if (pinType == Exter.EPinType.Branch || pinType == Exter.EPinType.Tag)
            {
                if (String.IsNullOrEmpty(releaseName))
                {
                    throw new ArgumentException("release Name can't be empty", "releaseName");
                }
            }

            // read externals from the root directory and parse them
            string externalsHostUrl = srcUrl;

            SvnExternalItem[] extItems;
            if (!Exter.ReadExternals(client, externalsHostUrl, out extItems))
            {
                return(false);
            }

            // modify each of them (will create new tags if needed on referenced shared resources!)
            {
                for (int i = 0; i < extItems.Length; i++)
                {
                    if (!ModifyExternal(client, ref extItems[i], pinType, externalsHostUrl, releaseName))
                    {
                        return(false);
                    }
                }
            }

            long dstRevision;

            if (srcUrl != destUrl)
            {
                // make svn copy Head Candidate/2.0.1 (copies the externals as they are)
                try
                {
                    SvnCommitResult copyResult;
                    var             args = new SvnCopyArgs();
                    args.LogMessage    = "";
                    args.CreateParents = true;
                    if (!client.RemoteCopy(new SvnUriTarget(srcUrl, SvnRevision.Head), new Uri(destUrl), args, out copyResult))
                    {
                        return(false);
                    }

                    dstRevision = copyResult.Revision;
                }
                catch (SvnException ex)
                {
                    Logger.Error(ex, $"Failed creating '{destUrl}'");
                    return(false);
                }
            }
            else
            {
                SvnInfoEventArgs info;
                if (!client.GetInfo(new Uri(srcUrl), out info))
                {
                    return(false);
                }
                dstRevision = info.Revision;
            }


            // update its root externals
            if (!Exter.WriteExternals(client, destUrl, extItems, dstRevision))
            {
                return(false);
            }

            return(true);
        }
Beispiel #24
0
        public override void OnExecute(CommandEventArgs e)
        {
            Uri target = null;
            Uri root = null;

            List<SvnUriTarget> copyFrom = new List<SvnUriTarget>();
            foreach (ISvnRepositoryItem item in e.Selection.GetSelection<ISvnRepositoryItem>())
            {
                SvnUriTarget utt = item.Origin.Target as SvnUriTarget;

                if(utt == null)
                    utt = new SvnUriTarget(item.Origin.Uri, item.Origin.Target.Revision);

                copyFrom.Add(utt);

                if(root == null)
                    root = item.Origin.RepositoryRoot;

                if (target == null)
                    target = item.Origin.Uri;
                else
                {
                    Uri itemUri = SvnTools.GetNormalizedUri(item.Origin.Uri);

                    Uri r = item.Origin.Uri.MakeRelativeUri(target);

                    if(r.IsAbsoluteUri)
                    {
                        target = null;
                        break;
                    }

                    string rs = r.ToString();

                    if(r.ToString().StartsWith("/", StringComparison.Ordinal))
                    {
                        target = new Uri(target, "/");
                        break;
                    }

                    while(r.ToString().StartsWith("../"))
                    {
                        target = new Uri(target, "../");
                        r = item.Origin.Uri.MakeRelativeUri(target);
                    }
                }
            }

            bool isMove = e.Command == AnkhCommand.ReposMoveTo;
            Uri toUri;
            string logMessage;
            using (CopyToDialog dlg = new CopyToDialog())
            {
                dlg.RootUri = root;
                dlg.SelectedUri = target;

                dlg.Text = isMove ? "Move to Url" : "Copy to Url";

                if (dlg.ShowDialog(e.Context) != System.Windows.Forms.DialogResult.OK)
                    return;

                toUri = dlg.SelectedUri;
                logMessage = dlg.LogMessage;
            }

            // TODO: BH: Make sure the 2 attempts actually make sense

            e.GetService<IProgressRunner>().RunModal(isMove ? "Moving" : "Copying",
                delegate(object snd, ProgressWorkerArgs a)
                {
                    if (isMove)
                    {
                        List<Uri> uris = new List<Uri>();
                        foreach (SvnUriTarget ut in copyFrom)
                            uris.Add(ut.Uri);

                        SvnMoveArgs ma = new SvnMoveArgs();
                        ma.LogMessage = logMessage;
                        ma.CreateParents = true;

                        try
                        {
                            // First try with the full new name
                            a.Client.RemoteMove(uris, toUri, ma);
                        }
                        catch (SvnFileSystemException fs)
                        {
                            if (fs.SvnErrorCode != SvnErrorCode.SVN_ERR_FS_ALREADY_EXISTS)
                                throw;

                            // If exists retry below this directory with the existing name
                            ma.AlwaysMoveAsChild = true;
                            a.Client.RemoteMove(uris, toUri, ma);
                        }
                    }
                    else
                    {
                        SvnCopyArgs ca = new SvnCopyArgs();
                        ca.LogMessage = logMessage;
                        ca.CreateParents = true;

                        try
                        {
                            // First try with the full new name
                            a.Client.RemoteCopy(copyFrom, toUri, ca);
                        }
                        catch (SvnFileSystemException fs)
                        {
                            if (fs.SvnErrorCode != SvnErrorCode.SVN_ERR_FS_ALREADY_EXISTS)
                                throw;

                            // If exists retry below this directory with the existing name
                            ca.AlwaysCopyAsChild = true;
                            a.Client.RemoteCopy(copyFrom, toUri, ca);
                        }
                    }
                });

            // TODO: Send some notification to the repository explorer on this change?
        }
Beispiel #25
0
        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;
                }
            }
        }
Beispiel #26
0
        public override void OnExecute(CommandEventArgs e)
        {
            ISvnRepositoryItem item = EnumTools.GetSingle(e.Selection.GetSelection<ISvnRepositoryItem>());

            if (item == null)
                return;

            string copyTo;
            bool copyBelow = false;
            bool suggestExport = false;
            IFileStatusCache cache = e.GetService<IFileStatusCache>();

            if (item.NodeKind == SharpSvn.SvnNodeKind.Directory)
            {
                using (FolderBrowserDialog fd = new FolderBrowserDialog())
                {
                    fd.ShowNewFolderButton = false;

                    if (DialogResult.OK != fd.ShowDialog(e.Context.DialogOwner))
                        return;

                    copyTo = fd.SelectedPath;
                    copyBelow = true;

                    SvnItem dirItem = cache[copyTo];

                    if (dirItem == null || !dirItem.IsVersioned)
                        suggestExport = true;
                }
            }
            else
            {
                using (SaveFileDialog sfd = new SaveFileDialog())
                {
                    sfd.CheckPathExists = true;
                    sfd.OverwritePrompt = true;
                    string name = item.Origin.Target.FileName;
                    string ext = Path.GetExtension(item.Origin.Target.FileName);
                    sfd.Filter = string.Format("{0} files|*.{0}|All files (*.*)|*", ext.TrimStart('.'));
                    sfd.FileName = name;

                    if (DialogResult.OK != sfd.ShowDialog(e.Context.DialogOwner))
                        return;

                    copyTo = SvnTools.GetNormalizedFullPath(sfd.FileName);

                    SvnItem fileItem = cache[copyTo];

                    if (File.Exists(copyTo))
                    {
                        // We prompted to confirm; remove the file!

                        if (fileItem.IsVersioned)
                            e.GetService<IProgressRunner>().RunModal("Copying",
                                delegate(object sender, ProgressWorkerArgs a)
                                {
                                    SvnDeleteArgs da = new SvnDeleteArgs();
                                    da.Force = true;
                                    a.Client.Delete(copyTo, da);
                                });
                        else
                            File.Delete(copyTo);
                    }

                    SvnItem dir = fileItem.Parent;

                    if (dir == null || !(dir.IsVersioned && dir.IsVersionable))
                        suggestExport = true;
                }
            }

            if (!suggestExport)
            {
                e.GetService<IProgressRunner>().RunModal("Copying",
                    delegate(object sender, ProgressWorkerArgs a)
                    {
                        SvnCopyArgs ca = new SvnCopyArgs();
                        ca.CreateParents = true;
                        if (copyBelow)
                            ca.AlwaysCopyAsChild = true;

                        a.Client.Copy(item.Origin.Target, copyTo, ca);
                    });
            }
            else
            {
                AnkhMessageBox mb = new AnkhMessageBox(e.Context);

                if (DialogResult.Yes == mb.Show("The specified path is not in a workingcopy; would you like to export the file instead?",
                    "No Working Copy", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                {
                    e.GetService<IProgressRunner>().RunModal("Exporting",
                    delegate(object sender, ProgressWorkerArgs a)
                    {
                        SvnExportArgs ea = new SvnExportArgs();
                        ea.Revision = item.Revision;

                        a.Client.Export(item.Origin.Target, copyTo, ea);
                    });
                }
            }
        }