示例#1
0
        public void TestImportFile()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            Uri ReposUrl = sbox.CreateRepository(SandBoxRepository.Empty);
            string WcPath = sbox.Wc;

            string truePath = CreateTextFile(WcPath, "testfile.txt");
            Uri trueDstUrl = new Uri(ReposUrl, "testfile.txt");

            SvnImportArgs a = new SvnImportArgs();
            a.Depth = SvnDepth.Empty;

            Assert.That(Client.RemoteImport(truePath, trueDstUrl, a));

            String cmd = this.RunCommand("svn", "list " + ReposUrl.ToString());
            Assert.That(cmd.IndexOf("testfile.txt") >= 0, "File wasn't imported ");
        }
示例#2
0
        public void TestImportDir()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            string WcPath = sbox.Wc;
            Uri ReposUrl = sbox.CreateRepository(SandBoxRepository.Empty);

            string dir1, dir2, testFile1, testFile2;
            CreateSubdirectories(WcPath, out dir1, out dir2, out testFile1, out testFile2);

            Uri trueDstUrl = new Uri(ReposUrl + "newDir2/");
            SvnImportArgs a = new SvnImportArgs();
            a.Depth = SvnDepth.Infinity;

            Assert.That(Client.Import(dir1, trueDstUrl, a));

            String cmd = this.RunCommand("svn", "list " + ReposUrl);
            Assert.That(cmd.IndexOf("newDir2") >= 0, "File wasn't imported");
        }
示例#3
0
        public void TestImportFile()
        {
            SvnSandBox sbox     = new SvnSandBox(this);
            Uri        ReposUrl = sbox.CreateRepository(SandBoxRepository.Empty);
            string     WcPath   = sbox.Wc;

            string truePath   = CreateTextFile(WcPath, "testfile.txt");
            Uri    trueDstUrl = new Uri(ReposUrl, "testfile.txt");

            SvnImportArgs a = new SvnImportArgs();

            a.Depth = SvnDepth.Empty;

            Assert.That(Client.RemoteImport(truePath, trueDstUrl, a));

            String cmd = this.RunCommand("svn", "list " + ReposUrl.ToString());

            Assert.That(cmd.IndexOf("testfile.txt") >= 0, "File wasn't imported ");
        }
示例#4
0
        public void TestImportDir()
        {
            SvnSandBox sbox     = new SvnSandBox(this);
            string     WcPath   = sbox.Wc;
            Uri        ReposUrl = sbox.CreateRepository(SandBoxRepository.Empty);

            string dir1, dir2, testFile1, testFile2;

            CreateSubdirectories(WcPath, out dir1, out dir2, out testFile1, out testFile2);

            Uri           trueDstUrl = new Uri(ReposUrl + "newDir2/");
            SvnImportArgs a          = new SvnImportArgs();

            a.Depth = SvnDepth.Infinity;

            Assert.That(Client.Import(dir1, trueDstUrl, a));

            String cmd = this.RunCommand("svn", "list " + ReposUrl);

            Assert.That(cmd.IndexOf("newDir2") >= 0, "File wasn't imported");
        }
示例#5
0
        private static bool ImportDirectories()
        {
            var    uri = new Uri(string.Format("{0}{1}", svnURL, svnPROJ));
            string dir = Path.Combine(repoDIR, vssPROJ.Substring(2).Replace("/", "\\"));

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            using (SvnClient svnClient = GetSvnClient())
            {
                var importArgs = new SvnImportArgs
                {
                    LogMessage = string.Format("Initial import from VSS on {0}", DateTime.Now)
                };

                SvnInfoEventArgs infoEventArgs;
                try
                {
                    trunkexists = svnClient.GetInfo(SvnTarget.FromUri(uri), out infoEventArgs);
                    migrateLog.DebugFormat(svnClient.GetInfo(SvnTarget.FromUri(uri), out infoEventArgs) ?
                                           "Getting trunk revision was successful." :
                                           "Getting trunk revision was NOT successful!");

                    migrateLog.DebugFormat("Base Revision: " + infoEventArgs.Revision);

                    if (infoEventArgs.Revision == 0)
                    {
                        if (!svnClient.Import(dir, uri, importArgs))
                        {
                            return(false);
                        }
                    }
                }
                catch (Exception)
                {
                    if (!svnClient.Import(dir, uri, importArgs))
                    {
                        return(false);
                    }
                }

                var tagurl    = new Uri(String.Format("{1}/{0}", svnTAG, svnURL));
                var branchurl = new Uri(String.Format("{1}/{0}", svnBRANCH, svnURL));

                try
                {
                    svnClient.GetInfo(tagurl, out infoEventArgs);
                    svnClient.GetInfo(branchurl, out infoEventArgs);
                    migrateLog.DebugFormat(svnClient.GetInfo(tagurl, out infoEventArgs)?
                                           "Getting tag dir revision was successful." :
                                           "Getting tag dir revision was NOT successful!");

                    migrateLog.DebugFormat(svnClient.GetInfo(branchurl, out infoEventArgs)?
                                           "Getting branch dir revision was successful." :
                                           "Getting branch dir revision was NOT successful!");
                }
                catch (SvnRepositoryIOException)
                {
                    var tagdircreated = svnClient.RemoteCreateDirectory((tagurl), new SvnCreateDirectoryArgs
                    {
                        LogMessage = "Initial creation of tag directory", CreateParents = true
                    });
                    var branchdircreated = svnClient.RemoteCreateDirectory((branchurl),
                                                                           new SvnCreateDirectoryArgs
                    {
                        LogMessage = "Initial creation of branch directory", CreateParents = true
                    });
                }

                try
                {
                    svnClient.GetInfo(uri, out infoEventArgs);
                }
                catch (SvnRepositoryIOException)
                {
                    svnClient.RemoteCreateDirectory((uri),
                                                    new SvnCreateDirectoryArgs
                    {
                        LogMessage = "Initial import", CreateParents = true
                    });
                }


                migrateLog.DebugFormat(dir);
                //Update the author and time of the first import revision to correspond to the first file revision
                //minus a minute in time for proper ordering of the revisions in time);
                if (!string.IsNullOrEmpty(svnREVPROPSPATH))
                {
                    svnClient.GetInfo(trunkexists
                                          ? SvnTarget.FromUri(uri)
                                          : SvnTarget.FromString(dir),
                                      out infoEventArgs);

                    var props = new SvnRevProps(svnREVPROPSPATH, infoEventArgs.Revision);

                    //This helps to make sure the revisions are imported in chronological order
                    props.SetDate(revisions.Keys[0].Time.AddMinutes(-1));
                }

                Cleanup();

                var checkOutArgs = new SvnCheckOutArgs {
                    Depth = SvnDepth.Infinity
                };
                return(svnClient.CheckOut(uri, dir, checkOutArgs));
            }
        }
示例#6
0
        /// <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);
        }
示例#7
0
        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);
                }
        }