示例#1
0
 public void Copy(string from, string to)
 {
     Debug("SVN: Copy(" + from + ", " + to);
     BeforeWriteOperation("copy");
     try {
         client.Copy(from, to);
     } catch (SvnException ex) {
         throw new SvnClientException(ex);
     } finally {
         AfterOperation();
     }
 }
示例#2
0
        private int BranchItem(string source, string target)
        {
            Trace.TraceInformation("SVNTCAdapter BranchItem {0} {1}", source, target);
            SvnTarget sourceTarget = SvnTarget.FromString(source);

            m_client.Copy(sourceTarget, target);
            m_client.Commit(target, new SvnCommitArgs()
            {
                LogMessage = BranchComment
            });

            return(GetLatestRevisionNumber());
        }
示例#3
0
        public void Copy_CopyTest()
        {
            SvnSandBox sbox = new SvnSandBox(this);

            sbox.Create(SandBoxRepository.Default);

            string WcPath = sbox.Wc;
            Uri    WcUri  = sbox.Uri;

            using (SvnClient client = NewSvnClient(true, false))
            {
                string file = Path.Combine(WcPath, "CopyBase");

                TouchFile(file);
                client.Add(file);

                client.Commit(WcPath);

                client.RemoteCopy(new Uri(WcUri, "CopyBase"), new Uri(WcUri, "RemoteCopyBase"));
                bool visited = false;
                bool first   = true;
                client.Log(new Uri(WcUri, "RemoteCopyBase"), delegate(object sender, SvnLogEventArgs e)
                {
                    if (first)
                    {
                        first = false;
                        foreach (SvnChangeItem i in e.ChangedPaths)
                        {
                            Assert.That(i.Path, Is.StringEnding("trunk/RemoteCopyBase"), "Path ends with folder/RemoteCopyBase");
                            Assert.That(i.Action, Is.EqualTo(SvnChangeAction.Add));
                            Assert.That(i.CopyFromPath, Is.StringEnding("trunk/CopyBase"), "CopyFromPath ends with folder/CopyBase");
                            Assert.That(i.CopyFromRevision, Is.GreaterThan(0L));
                            Assert.That(i.NodeKind, Is.EqualTo(SvnNodeKind.File));
                        }
                    }
                    else
                    {
                        foreach (SvnChangeItem i in e.ChangedPaths)
                        {
                            Assert.That(i.Action, Is.EqualTo(SvnChangeAction.Add));
                            Assert.That(i.Path, Is.StringEnding("trunk/CopyBase"), "Path ends with folder/CopyBase");
                            Assert.That(i.NodeKind, Is.EqualTo(SvnNodeKind.File));
                            visited = true;
                        }
                    }
                });
                Assert.That(visited, "Visited log item");

                client.Copy(new SvnPathTarget(file), Path.Combine(WcPath, "LocalCopy"));
                client.Commit(WcPath);
                visited = false;
                first   = true;
                client.Log(new Uri(WcUri, "LocalCopy"), delegate(object sender, SvnLogEventArgs e)
                {
                    if (first)
                    {
                        foreach (SvnChangeItem i in e.ChangedPaths)
                        {
                            Assert.That(i.Path, Is.StringEnding("trunk/LocalCopy"), "Path ends with folder/LocalCopy");
                            Assert.That(i.Action, Is.EqualTo(SvnChangeAction.Add));
                            Assert.That(i.CopyFromPath, Is.StringEnding("trunk/CopyBase"), "CopyFromPath ensd with folder/CopyBase");
                            Assert.That(i.CopyFromRevision, Is.GreaterThan(0L));
                        }
                        first = false;
                    }
                    else
                    {
                        foreach (SvnChangeItem i in e.ChangedPaths)
                        {
                            Assert.That(i.Action, Is.EqualTo(SvnChangeAction.Add));
                            Assert.That(i.Path, Is.StringEnding("trunk/CopyBase"), "Path ends with folder/CopyBase");
                            visited = true;
                        }
                    }
                });
                Assert.That(visited, "Visited local log item");
            }
        }
        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;
                    }
                }
            }
        }
示例#5
0
        public void Merge_MinimalMergeTest()
        {
            SvnSandBox sbox = new SvnSandBox(this);

            sbox.Create(SandBoxRepository.Empty);

            using (SvnClient client = NewSvnClient(true, false))
            {
                string merge1 = Path.Combine(sbox.Wc, "mmerge-1");
                string merge2 = Path.Combine(sbox.Wc, "mmerge-2");
                client.CreateDirectory(merge1);

                string f1 = Path.Combine(merge1, "myfile.txt");

                using (StreamWriter fs = File.CreateText(f1))
                {
                    fs.WriteLine("First line");
                    fs.WriteLine("Second line");
                    fs.WriteLine("Third line");
                    fs.WriteLine("Fourth line");
                }

                client.Add(f1);

                SvnCommitResult ci;
                client.Commit(sbox.Wc, out ci);
                client.Copy(new SvnPathTarget(merge1), merge2);
                client.Commit(sbox.Wc);
                client.Update(sbox.Wc);

                SvnMergeSourcesCollection sources;
                client.GetSuggestedMergeSources(new SvnPathTarget(merge1), out sources);

                Assert.That(sources.Count, Is.EqualTo(0));

                client.GetSuggestedMergeSources(new SvnPathTarget(merge2), out sources);

                Assert.That(sources.Count, Is.EqualTo(1));

                Uri fromUri = new Uri(sbox.RepositoryUri, new Uri("mmerge-1", UriKind.Relative));
                Assert.That(sources[0].Uri, Is.EqualTo(fromUri));

                SvnAppliedMergeInfo applied;
                client.GetAppliedMergeInfo(new SvnPathTarget(merge2), out applied);

                Assert.That(applied, Is.Null);
                //Assert.That(applied.AppliedMerges.Count, Is.EqualTo(0));
                //Assert.That(applied.Target, Is.Not.Null);

                Collection <SvnMergesEligibleEventArgs> available;
                client.GetMergesEligible(new SvnPathTarget(merge2), fromUri, out available);
                Assert.That(available, Is.Not.Null);
                Assert.That(available.Count, Is.EqualTo(0));

                /*Assert.That(available[0].Revision, Is.EqualTo(ci.Revision));
                 * //Assert.That(available.MergeRanges[0].End, Is.EqualTo(ci.Revision + 1));
                 * //Assert.That(available.MergeRanges[0].Inheritable, Is.True);
                 * Assert.That(available[0].SourceUri, Is.Not.Null);*/

                using (StreamWriter fs = File.AppendText(f1))
                {
                    fs.WriteLine("Fifth line");
                }
                client.Commit(merge1);

                client.GetMergesEligible(new SvnPathTarget(merge2), fromUri, out available);
                Assert.That(available, Is.Not.Null);
                Assert.That(available.Count, Is.EqualTo(1));
                Assert.That(available[0].Revision, Is.EqualTo(3));
                Assert.That(available[0].SourceUri, Is.Not.Null);

                client.Merge(merge2, fromUri, available[0].AsRange());

                client.GetMergesEligible(new SvnPathTarget(merge2), fromUri, out available);
                Assert.That(available, Is.Not.Null);
                Assert.That(available.Count, Is.EqualTo(0));

                client.Commit(sbox.Wc);

                client.GetMergesEligible(new SvnPathTarget(merge2), fromUri, out available);
                Assert.That(available, Is.Not.Null);
                Assert.That(available.Count, Is.EqualTo(0));

                client.GetAppliedMergeInfo(new SvnPathTarget(merge2), out applied);

                Assert.That(applied, Is.Not.Null);
                Assert.That(applied.AppliedMerges.Count, Is.EqualTo(1));
                Assert.That(applied.AppliedMerges[0].Uri, Is.EqualTo(fromUri));
                Assert.That(applied.AppliedMerges[0].MergeRanges, Is.Not.Null);
                Assert.That(applied.AppliedMerges[0].MergeRanges.Count, Is.EqualTo(1));
                Assert.That(applied.AppliedMerges[0].MergeRanges[0].Start, Is.EqualTo(ci.Revision + 1));
                Assert.That(applied.AppliedMerges[0].MergeRanges[0].End, Is.EqualTo(ci.Revision + 2));
                Assert.That(applied.AppliedMerges[0].MergeRanges[0].Inheritable, Is.True);
                Assert.That(applied.Target, Is.Not.Null);
            }
        }