Esempio n. 1
0
        public void RenameMergeTest()
        {
            MigrationItemStrings file1 = new MigrationItemStrings(source.Name + "file1.txt", source.Name + "renamed-file1.txt", TestEnvironment, true);

            SourceAdapter.AddFile(file1.LocalPath);

            MigrationItemStrings file2 = new MigrationItemStrings(source.Name + "file2.txt", source.Name + "renamed-file2.txt", TestEnvironment, true);

            SourceAdapter.AddFile(file2.LocalPath);

            int changesetId = AddBranch();

            SourceAdapter.RenameItem(file.ServerPath, file.NewServerPath, AddComment);
            SourceAdapter.RenameItem(file1.ServerPath, file1.NewServerPath, AddComment);
            SourceAdapter.RenameItem(file2.ServerPath, file2.NewServerPath, AddComment);

            SourceWorkspace.Merge(source.LocalPath, target.LocalPath,
                                  VersionSpec.ParseSingleSpec(changesetId.ToString(), Environment.UserName),
                                  VersionSpec.Latest, LockLevel.None, RecursionType.Full, MergeOptions.ForceMerge);

            Conflict[] conflicts = SourceWorkspace.QueryConflicts(new string[] { "$/" }, true);

            foreach (Conflict conflict in conflicts)
            {
                conflict.Resolution = Resolution.AcceptTheirs;
                SourceWorkspace.ResolveConflict(conflict);
            }

            RunAndValidate();
        }
Esempio n. 2
0
        private void BtnGetInformation_Click(object sender, EventArgs e)
        {
            TfsTeamProjectCollection ProjectCollection = new TfsTeamProjectCollection(new Uri("http://example.com:8080/tfs/ProjectCollection"));

            ProjectCollection.Connect(ConnectOptions.None);

            var vcs = ProjectCollection.GetService <VersionControlServer>();

            VersionSpec versionFrom = VersionSpec.ParseSingleSpec("C529", null);

            VersionSpec versionTo = VersionSpec.Latest;

            string serverPath = @"$/";

            List <Changeset> Changesets = vcs.QueryHistory(serverPath,
                                                           VersionSpec.Latest,
                                                           0,
                                                           RecursionType.Full,
                                                           null,
                                                           versionFrom,
                                                           versionTo,
                                                           Int32.MaxValue,
                                                           true,
                                                           false
                                                           ).Cast <Changeset>().ToList <Changeset>();

            BaseChangesets = Changesets;

            if (BaseChangesets != null)
            {
                GrpDateFilter.Enabled = true;
            }
        }
Esempio n. 3
0
        public void RenameUndeleteMergeTest()
        {
            int changesetId = AddBranch();

            PendUndeleteRename(file);
            SourceWorkspace.Merge(source.LocalPath, target.LocalPath,
                                  VersionSpec.ParseSingleSpec(changesetId.ToString(), Environment.UserName),
                                  VersionSpec.Latest, LockLevel.None, RecursionType.Full, MergeOptions.None);

            CheckinMergeResolve(changesetId);

            if (TestEnvironment.SourceTFSVersion == TFSVersionEnum.TFS2010)
            {
                Run();

                // 1 extra merge item on source side is expected in dev10
                VerifyHistory(1, 1);

                //Changeset targetChangeset = diff.TargetChanges[0];
                //Changeset sourceChangeset = diff.SourceChanges[0];
                //diff.ChangesetDiff(ref targetChangeset, ref sourceChangeset);
                //Assert.AreEqual(1, sourceChangeset.Changes.Length);
                //Assert.AreEqual(ChangeType.Merge, sourceChangeset.Changes[0].ChangeType);
                //Assert.AreEqual(0, targetChangeset.Changes.Length);

                // verify content matches
                Assert.IsTrue(VerifyContents());
            }
            else
            {
                RunAndValidate();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Compares changesets
        /// </summary>
        /// <param name="sourceChangesetId">Source changeset Id</param>
        /// <param name="targetChangesetId">Target changeset Id</param>
        /// <param name="serverUrl">Server Uri</param>
        /// <param name="srcPath">Source item path</param>
        /// <param name="targetPath">Target item path</param>
        public static void Compare(string sourceChangesetId, string targetChangesetId, string serverUri, string srcPath, string targetPath)
        {
            if (String.IsNullOrWhiteSpace(sourceChangesetId))
            {
                throw new ArgumentException("'sourceChangesetId' is null or empty.");
            }
            if (String.IsNullOrWhiteSpace(targetChangesetId))
            {
                throw new ArgumentException("'targetChangesetId' is null or empty.");
            }
            if (String.IsNullOrWhiteSpace(serverUri))
            {
                throw new ArgumentException("'serverUri' is null or empty.");
            }
            if (String.IsNullOrWhiteSpace(srcPath))
            {
                throw new ArgumentException("'srcPath' is null or empty.");
            }
            if (String.IsNullOrWhiteSpace(targetPath))
            {
                throw new ArgumentException("'targetPath' is null or empty.");
            }

            TfsTeamProjectCollection tc  = new TfsTeamProjectCollection(new Uri(serverUri));
            VersionControlServer     vcs = tc.GetService(typeof(VersionControlServer)) as VersionControlServer;

            VersionSpec sourceVersion = VersionSpec.ParseSingleSpec(sourceChangesetId, vcs.AuthorizedUser);
            VersionSpec targetVersion = VersionSpec.ParseSingleSpec(targetChangesetId, vcs.AuthorizedUser);

            Difference.VisualDiffItems(vcs,
                                       Difference.CreateTargetDiffItem(vcs, srcPath, sourceVersion, 0, sourceVersion),
                                       Difference.CreateTargetDiffItem(vcs, targetPath, targetVersion, 0, targetVersion));
        }
Esempio n. 5
0
        public void RenameEditUndeleteMergeTest()
        {
            int changesetId = AddBranch();

            MergeDeletePendUndelete(m_file, changesetId);
            SourceWorkspace.PendRename(m_file.ServerPath, m_file.NewServerPath);
            SourceAdapter.EditFile(m_file.NewLocalPath);

            SourceWorkspace.Merge(m_source.LocalPath, m_target.LocalPath,
                                  VersionSpec.ParseSingleSpec(changesetId.ToString(), Environment.UserName),
                                  VersionSpec.Latest, LockLevel.None, RecursionType.Full, MergeOptions.None);

            resolveConflictAcceptThiers();

            if (TestEnvironment.SourceEndPoint.IsTfsAdapter &&
                TestEnvironment.SourceEndPoint.AdapterType >= AdapterType.TFS2010VC)
            {
                Run();
                Assert.IsTrue(VerifyContents());
            }
            else
            {
                RunAndValidate();
            }
        }
Esempio n. 6
0
        public void MergeMovesTest()
        {
            MigrationItemStrings branch = new MigrationItemStrings("source/", "target/", TestEnvironment, true);
            MigrationItemStrings file   = new MigrationItemStrings("source/file.txt", "source/sub/file.txt", TestEnvironment, true);
            MigrationItemStrings file2  = new MigrationItemStrings("source/file2.txt", "source/sub/file2.txt", TestEnvironment, true);

            SourceAdapter.AddFile(file.LocalPath);
            SourceAdapter.AddFile(file2.LocalPath);

            int branchChangeset = SourceAdapter.BranchItem(branch.ServerPath, branch.NewServerPath);

            SourceAdapter.EditFile(file.LocalPath);
            SourceAdapter.EditFile(file.LocalPath);
            SourceAdapter.EditFile(m_extraFile.LocalPath);

            SourceAdapter.RenameItem(file.ServerPath, file.NewServerPath);
            SourceAdapter.RenameItem(file2.ServerPath, file2.NewServerPath);

            SourceWorkspace.Merge(branch.ServerPath, branch.NewServerPath,
                                  VersionSpec.ParseSingleSpec(branchChangeset.ToString(),
                                                              Environment.UserName), VersionSpec.Latest, LockLevel.None, RecursionType.Full, MergeOptions.None);
            ResolveConflicts(Resolution.AcceptTheirs);
            SourceWorkspace.CheckIn(SourceWorkspace.GetPendingChanges(), MergeComment);

            RunAndValidate();
        }
Esempio n. 7
0
        /// <summary>
        /// Compares changesets
        /// </summary>
        /// <param name="localPath"></param>
        /// <param name="sourceChangesetId">Source changeset Id</param>
        /// <param name="serverUrl">Server Uri</param>
        /// <param name="srcPath">Source item path</param>
        public static void CompareLocal(string localPath, string sourceChangesetId, string serverUri, string srcPath)
        {
            if (String.IsNullOrWhiteSpace(sourceChangesetId))
            {
                throw new ArgumentException("'sourceChangesetId' is null or empty.");
            }
            if (String.IsNullOrWhiteSpace(serverUri))
            {
                throw new TfsHistorySearchException("'serverUri' is null or empty.");
            }
            if (String.IsNullOrWhiteSpace(srcPath))
            {
                throw new TfsHistorySearchException("'srcPath' is null or empty.");
            }
            if (String.IsNullOrWhiteSpace(localPath))
            {
                throw new TfsHistorySearchException("'localPath' is null or empty.");
            }

            TfsTeamProjectCollection tc  = new TfsTeamProjectCollection(new Uri(serverUri));
            VersionControlServer     vcs = tc.GetService(typeof(VersionControlServer)) as VersionControlServer;

            //VersionSpec sourceVersion = VersionSpec.ParseSingleSpec(sourceChangesetId, vcs.TeamFoundationServer.AuthenticatedUserName);
            VersionSpec sourceVersion = VersionSpec.ParseSingleSpec(sourceChangesetId, vcs.AuthorizedUser);

            //VersionSpec targetVersion = VersionSpec.ParseSingleSpec(targetChangesetId, vcs.TeamFoundationServer.AuthenticatedUserName);

            //Difference.DiffFiles(
            Difference.VisualDiffItems(vcs, Difference.CreateTargetDiffItem(vcs, srcPath, sourceVersion, 0, sourceVersion), Difference.CreateTargetDiffItem(vcs, localPath, null, 0, null));
            //Difference.VisualDiffFiles();
            //Difference.VisualDiffItems(vcs,
            //                           Difference.CreateTargetDiffItem(vcs, srcPath, sourceVersion, 0, sourceVersion),
            //                           Difference.CreateTargetDiffItem(vcs, targetPath, targetVersion, 0, targetVersion));
        }
Esempio n. 8
0
        public int MergeItem(MigrationItemStrings branch, int mergeFrom, int mergeTo)
        {
            m_workspace.Merge(branch.ServerPath, branch.NewServerPath,
                              VersionSpec.ParseSingleSpec(mergeFrom.ToString(), Environment.UserName),
                              VersionSpec.ParseSingleSpec(mergeTo.ToString(), Environment.UserName), LockLevel.None, RecursionType.Full, MergeOptions.None);

            return(m_workspace.CheckIn(m_workspace.GetPendingChanges(), MergeComment));
        }
Esempio n. 9
0
        private void CheckinMergeResolve(int changesetId)
        {
            SourceWorkspace.CheckIn(SourceWorkspace.GetPendingChanges(), MultiActionComment);

            SourceWorkspace.Merge(source.LocalPath, target.LocalPath,
                                  VersionSpec.ParseSingleSpec(changesetId.ToString(),
                                                              Environment.UserName), VersionSpec.Latest, LockLevel.None, RecursionType.Full, MergeOptions.None);

            resolveConflictAcceptThiers();
        }
Esempio n. 10
0
        /// <summary>
        /// Perform a merge specifying the start and end changeset
        /// </summary>
        /// <param name="branch">The source server pah is the server namd the target path is the NewServerPath</param>
        /// <param name="mergeFrom">changeset to start merge from</param>
        /// <param name="mergeTo">changeset to merge up to</param>
        private void MergeTfsItem(MigrationItemStrings branch, int mergeFrom, int mergeTo)
        {
            string mergeComment = "Migration test merge";

            SourceWorkspace.Merge(branch.ServerPath, branch.NewServerPath,
                                  VersionSpec.ParseSingleSpec(mergeFrom.ToString(), Environment.UserName),
                                  VersionSpec.ParseSingleSpec(mergeTo.ToString(), Environment.UserName), LockLevel.None, RecursionType.Full, MergeOptions.None);

            SourceWorkspace.CheckIn(SourceWorkspace.GetPendingChanges(), mergeComment);
        }
Esempio n. 11
0
 public VersionSpec VersionFromString(string version)
 {
     if (!String.IsNullOrEmpty(version))
     {
         return(VersionSpec.ParseSingleSpec(version, Driver.Username));
     }
     else
     {
         return(VersionSpec.Latest);
     }
 }
Esempio n. 12
0
        public void MergeDeleteTest()
        {
            int changesetId = AddBranch();

            SourceAdapter.DeleteItem(file.ServerPath);
            SourceWorkspace.Merge(source.LocalPath, target.LocalPath,
                                  VersionSpec.ParseSingleSpec(changesetId.ToString(),
                                                              Environment.UserName), VersionSpec.Latest, LockLevel.None, RecursionType.Full, MergeOptions.ForceMerge);

            RunAndValidate();
        }
Esempio n. 13
0
 public TFVersionSpec(string value)
 {
     if (String.IsNullOrWhiteSpace(value))
     {
         this.vs = null;
     }
     else
     {
         this.vs = VersionSpec.ParseSingleSpec(value, null);
     }
 }
Esempio n. 14
0
        public void MergeTwoCyclicRenamesTest()
        {
            MigrationItemStrings branch = new MigrationItemStrings("source/", "target/", TestEnvironment, true);

            MigrationItemStrings folder1 = new MigrationItemStrings("source/folder1/", null, TestEnvironment, true);
            MigrationItemStrings folder2 = new MigrationItemStrings("source/folder2/", null, TestEnvironment, true);
            MigrationItemStrings folder3 = new MigrationItemStrings("source/folder3/", null, TestEnvironment, true);
            MigrationItemStrings temp    = new MigrationItemStrings("source/temp/", null, TestEnvironment, true);

            MigrationItemStrings file1    = new MigrationItemStrings("source/folder1/file1.txt", null, TestEnvironment, true);
            MigrationItemStrings file2    = new MigrationItemStrings("source/folder1/file2.txt", null, TestEnvironment, true);
            MigrationItemStrings tempFile = new MigrationItemStrings("source/folder1/tempFile.txt", null, TestEnvironment, true);

            SourceAdapter.AddFolder(folder1.LocalPath);
            SourceAdapter.AddFolder(folder2.LocalPath);
            SourceAdapter.AddFolder(folder3.LocalPath);

            SourceAdapter.AddFile(file1.LocalPath);
            SourceAdapter.AddFile(file2.LocalPath);

            int branchChangeset = SourceAdapter.BranchItem(branch);

            // Create a cyclic rename of two files
            SourceWorkspace.PendRename(file1.ServerPath, tempFile.ServerPath);
            SourceWorkspace.PendRename(file2.ServerPath, file1.ServerPath);
            SourceWorkspace.PendRename(tempFile.ServerPath, file2.ServerPath);

            // Create a three-way cyclic rename of the parent folder with two other folders
            SourceWorkspace.PendRename(folder1.ServerPath, temp.ServerPath);
            SourceWorkspace.PendRename(folder2.ServerPath, folder1.ServerPath);
            SourceWorkspace.PendRename(folder3.ServerPath, folder2.ServerPath);
            SourceWorkspace.PendRename(temp.ServerPath, folder3.ServerPath);
            SourceWorkspace.CheckIn(SourceWorkspace.GetPendingChanges(), RenameComment);

            SourceWorkspace.Merge(branch.ServerPath, branch.NewServerPath,
                                  VersionSpec.ParseSingleSpec(branchChangeset.ToString(), Environment.UserName),
                                  VersionSpec.Latest, LockLevel.None, RecursionType.Full, MergeOptions.AlwaysAcceptMine);
            SourceWorkspace.CheckIn(SourceWorkspace.GetPendingChanges(), MergeComment);

            Run();

            if (TestEnvironment.SourceEndPoint.AdapterType == AdapterType.TFS2008VC)
            {
                VerifyHistory(0, 0);
                // For orcas, there should be no difference.
            }
            else
            {
                VerifyHistory(1, 1);
                // Need more comparison here.
                // On dev 10 server, rename becomes sourceDelete+targetbranch. So the rename-from-name will exist in the original place as a deleted item.
                // The merge will then merge the item as a Merge|Delete. We will skip the change in this case.
            }
        }
Esempio n. 15
0
        private static void CheckChangeset(TfsPluginProfile settings, VersionControlServer versionControl, TeamProject teamProject = null)
        {
            string startRevision = int.Parse(settings.StartRevision) > 1 ?
                                   (int.Parse(settings.StartRevision) - 1).ToString(CultureInfo.InvariantCulture) :
                                   settings.StartRevision;

            if (teamProject == null)
            {
                var teamProjects = versionControl.GetAllTeamProjects(false);

                foreach (var project in teamProjects)
                {
                    try
                    {
                        var changeset = versionControl.QueryHistory(
                            project.ServerItem,
                            VersionSpec.Latest,
                            0,
                            RecursionType.Full,
                            null,
                            VersionSpec.ParseSingleSpec(startRevision, null),
                            null,
                            1,
                            false,
                            false).Cast <Changeset>().FirstOrDefault();

                        if (changeset != null)
                        {
                            return;
                        }
                    }
                    catch (ChangesetNotFoundException) { }
                }

                throw new ChangesetNotFoundException(string.Format("There’s no such revision: {0}", settings.StartRevision));
            }

            var projectChangeset = versionControl.QueryHistory(
                teamProject.ServerItem,
                VersionSpec.Latest,
                0,
                RecursionType.Full,
                null,
                VersionSpec.ParseSingleSpec(startRevision, null),
                null,
                1,
                false,
                false).Cast <Changeset>().FirstOrDefault();

            if (projectChangeset == null)
            {
                throw new ChangesetNotFoundException(string.Format("There’s no such revision: {0}", settings.StartRevision));
            }
        }
Esempio n. 16
0
        private void PendMergeUndelete(MigrationItemStrings item, int changesetId)
        {
            MergeDeletePendUndelete(item, changesetId);

            SourceWorkspace.CheckIn(SourceWorkspace.GetPendingChanges(), MultiActionComment);

            SourceWorkspace.Merge(m_source.LocalPath, m_target.LocalPath,
                                  VersionSpec.ParseSingleSpec(changesetId.ToString(), Environment.UserName),
                                  VersionSpec.Latest, LockLevel.None, RecursionType.Full, MergeOptions.None);

            resolveConflictAcceptThiers();
        }
Esempio n. 17
0
        public void MergeEditTest()
        {
            int changesetId = AddBranch();

            SourceAdapter.EditFile(m_file.LocalPath);

            SourceWorkspace.Merge(m_source.LocalPath, m_target.LocalPath,
                                  VersionSpec.ParseSingleSpec(changesetId.ToString(),
                                                              Environment.UserName), VersionSpec.Latest, LockLevel.None, RecursionType.Full, MergeOptions.None);

            RunAndValidate();
        }
Esempio n. 18
0
        private static VersionSpec ParseVersion(Match versionParts, string captureName)
        {
            string versionSpec = versionParts.Groups[captureName].Value;

            if (String.IsNullOrEmpty(versionSpec))
            {
                return(VersionSpec.Latest);
            }
            else
            {
                return(VersionSpec.ParseSingleSpec(versionSpec, null));
            }
        }
Esempio n. 19
0
        private void MergeDeletePendUndelete(MigrationItemStrings item, int changesetId)
        {
            int deletionId = SourceTfsClient.GetChangeset(SourceAdapter.DeleteItem(item.ServerPath)).Changes[0].Item.DeletionId;

            SourceWorkspace.Merge(source.LocalPath, target.LocalPath,
                                  VersionSpec.ParseSingleSpec(changesetId.ToString(), Environment.UserName),
                                  VersionSpec.Latest, LockLevel.None, RecursionType.Full, MergeOptions.None);

            // Check in only the merge|delete; so that the undelete may be merged over
            SourceWorkspace.CheckIn(SourceWorkspace.GetPendingChanges(), MergeComment);

            // pend undelete
            SourceWorkspace.PendUndelete(item.ServerPath, deletionId);
        }
Esempio n. 20
0
        public void MergeEditUndeleteTest()
        {
            int changesetId = AddBranch();

            MergeDeletePendUndelete(file, changesetId);
            SourceAdapter.EditFile(file.LocalPath);

            SourceWorkspace.Merge(source.LocalPath, target.LocalPath,
                                  VersionSpec.ParseSingleSpec(changesetId.ToString(), Environment.UserName),
                                  VersionSpec.Latest, LockLevel.None, RecursionType.Full, MergeOptions.None);

            resolveConflictAcceptThiers();

            RunAndValidate();
        }
        /// <summary>
        /// Validates the version spec string.
        /// </summary>
        private void ValidateSelectedVersionSpecString()
        {
            var    value             = SelectedVersionSpecString;
            string validationMessage = null;
            string latestVersionSpecOption;

            _versionSpecToDisplayStringDictionary.TryGetValue(VersionSpec.Latest.DisplayString, out latestVersionSpecOption);

            if (string.IsNullOrEmpty(value) && !SelectedVersionSpecs.Equals(latestVersionSpecOption, StringComparison.OrdinalIgnoreCase))
            {
                validationMessage = "Version spec is required!";
            }
            else
            {
                string versionSpecOption;
                // ReSharper disable AssignNullToNotNullAttribute
                _displayStringToVersionSpecDictionary.TryGetValue(SelectedVersionSpecs, out versionSpecOption);
                // ReSharper restore AssignNullToNotNullAttribute
                try
                {
                    // ReSharper disable PossibleNullReferenceException
                    if (versionSpecOption.Equals("W", StringComparison.OrdinalIgnoreCase))
                    // ReSharper restore PossibleNullReferenceException
                    {
                        var user = value.Split(';')[1];
                        VersionSpec.ParseSingleSpec(string.Concat(versionSpecOption, value), user);
                    }
                    else
                    {
                        VersionSpec.ParseSingleSpec(string.Concat(versionSpecOption, value), null);
                    }
                }
                catch (Exception)
                {
                    validationMessage = string.Format("{0} version spec is invalid!", SelectedVersionSpecs);
                }
            }

            if (validationMessage != null)
            {
                AddError("SelectedVersionSpecString", validationMessage);
            }
            else
            {
                RemoveError("SelectedVersionSpecString");
            }
        }
Esempio n. 22
0
        public void GetSource(TfsSourcePath sourcePath, WorkspaceInfo workspaceInfo, string targetDirectory, string label = null)
        {
            this.collection.EnsureAuthenticated();

            var versionControlServer = this.collection.GetService <VersionControlServer>();

            using (var workspace = MappedWorkspace.Create(workspaceInfo, versionControlServer, sourcePath, this.log))
            {
                var versionSpec = label == null
                    ? VersionSpec.Latest
                    : VersionSpec.ParseSingleSpec("L" + label, versionControlServer.AuthorizedUser);

                workspace.Workspace.Get(new GetRequest(new ItemSpec(sourcePath.AbsolutePath, RecursionType.Full), versionSpec), GetOptions.Overwrite);

                CopyNonTfsFiles(workspace.DiskPath, targetDirectory);
            }
        }
        /// <summary>
        /// Downloads all items in current folder and items in subfolders by calling itself.
        /// </summary>
        /// <param name="root">Root of copy operation</param>
        /// <param name="source">A valid TFS version control path to a folder that shall be downloaded.</param>
        /// <param name="destination">A valid directory to which all the files will be downloaded to.</param>
        /// <param name="versionString">The version string to determine the version to download.</param>
        /// <param name="includeFilters">The filter for file types to include.</param>
        /// <param name="excludeFilters">List of filters to exclude files and folders.</param>
        /// <param name="watermark">The watermark can be used to perform incremental updates and cleanup operations.</param>
        /// <param name="force">Indicates that we want to force a get operation and all files have to be overwritten</param>
        private void DownloadFolder(string root, string source, string destination, string versionString, IEnumerable <string> includeFilters, IEnumerable <string> excludeFilters, IDependencyDownloaderWatermark watermark, bool force)
        {
            var version = VersionSpec.ParseSingleSpec(versionString, _workspace.OwnerName);

            var includes = ConvertFilterToRegex(includeFilters, root);
            var excludes = ConvertFilterToRegex(excludeFilters, root);

            var items = _vcs.GetItems(source, version, RecursionType.Full, DeletedState.NonDeleted, ItemType.File, true).Items;

            items = items.Where(x => includes.Any(y => y.IsMatch(x.ServerItem))).ToArray();
            items = items.Where(x => !excludes.Any(y => y.IsMatch(x.ServerItem))).ToArray();

            Parallel.ForEach(items, new ParallelOptions {
                MaxDegreeOfParallelism = 8
            }, item =>
            {
                var subpath         = item.ServerItem.Substring(source.Length).Trim(new[] { '/' }).Replace("//", "\\");
                var destinationpath = Path.Combine(destination, subpath);

                var wm = watermark.GetWatermark <int>(item.ServerItem);
                if (force || 0 == wm || item.ChangesetId != wm || !File.Exists(destinationpath))
                {
                    if (File.Exists(destinationpath))
                    {
                        File.SetAttributes(destinationpath, FileAttributes.Normal);
                    }

                    lock (this)
                    {
                        watermark.ArtifactsToClean.Add(destinationpath);
                    }

                    Logger.Instance().Log(TraceLevel.Verbose, "{0}: Downloading file {1}", DownloadType, item.ServerItem);
                    item.DownloadFile(destinationpath);

                    lock (this)
                    {
                        watermark.UpdateWatermark(item.ServerItem, item.ChangesetId);
                    }
                }
                else
                {
                    Logger.Instance().Log(TraceLevel.Verbose, "{0}: Skipping file {1}", DownloadType, item.ServerItem);
                }
            });
        }
Esempio n. 24
0
        public void ReverseMergeTest()
        {
            MigrationItemStrings branch = new MigrationItemStrings("source/", "target/", TestEnvironment, true);
            MigrationItemStrings file   = new MigrationItemStrings("source/file.txt", "target/file.txt", TestEnvironment, true);

            SourceAdapter.AddFile(file.LocalPath);
            int branchChangeset = SourceAdapter.BranchItem(branch.ServerPath, branch.NewServerPath);

            SourceAdapter.EditFile(file.NewLocalPath);

            SourceWorkspace.Merge(branch.NewServerPath, branch.ServerPath,
                                  VersionSpec.ParseSingleSpec(branchChangeset.ToString(), Environment.UserName),
                                  VersionSpec.Latest, LockLevel.None, RecursionType.Full, MergeOptions.None);
            SourceWorkspace.CheckIn(SourceWorkspace.GetPendingChanges(), MergeComment);

            RunAndValidate();
        }
Esempio n. 25
0
        // Fill in the workspace name if it is null.
        static VersionSpec ParseVersionSpec(String spec, Workspace workspace)
        {
            String user = workspace.VersionControlServer.TeamFoundationServer.AuthenticatedUserName;

            VersionSpec version = VersionSpec.ParseSingleSpec(spec, user);

            // If the user happened to specify only W for the workspace spec, we'll have to
            // fill in the workspace here (the parse method doesn't know it).
            WorkspaceVersionSpec wvs = version as WorkspaceVersionSpec;

            if (wvs != null && wvs.Name == null)
            {
                wvs.Name = workspace.Name;
            }

            return(version);
        }
Esempio n. 26
0
    public override void Run()
    {
        Workspace workspace = GetWorkspaceFromCache();

        if (OptionOld || OptionModified)
        {
            ProcessOldAndModified(workspace);
            Environment.Exit((int)ExitCode.Success);
        }

        if (Arguments.Length > 0)
        {
            string arg = Arguments[0];
            if (!(File.Exists(arg) || Directory.Exists(arg)))
            {
                VersionSpec versionSpec = null;
                try
                {
                    versionSpec = VersionSpec.ParseSingleSpec(Arguments[0], OwnerFromString(OptionOwner));
                }
                catch (System.FormatException exception)
                {
                    Console.WriteLine("Invalid version specification: " + Arguments[0]);
                    Environment.Exit((int)ExitCode.Failure);
                }

                if (versionSpec is ChangesetVersionSpec)
                {
                    DiffHelper.ShowChangeset(VersionControlServer,
                                             versionSpec as ChangesetVersionSpec,
                                             OptionBrief, GetDiffOptions());
                }
                Environment.Exit((int)ExitCode.Success);
            }
        }

        List <string> paths;

        paths = VerifiedFullPaths(Arguments);
        if (paths.Count == 0)
        {
            paths.Add(Environment.CurrentDirectory);
        }
        ShowPendingChanges(workspace, paths.ToArray());
    }
Esempio n. 27
0
        protected void BranchParitalScenario()
        {
            MigrationItemStrings branch = new MigrationItemStrings("source/", "target/", TestEnvironment, true);
            MigrationItemStrings file1  = new MigrationItemStrings("source/file1.txt", null, TestEnvironment, true);
            MigrationItemStrings file2  = new MigrationItemStrings("source/file2.txt", null, TestEnvironment, true);

            SourceAdapter.AddFolder(branch.LocalPath);
            SourceAdapter.AddFile(file1.LocalPath);
            int branchFrom = SourceAdapter.AddFile(file2.LocalPath);

            SourceAdapter.EditFile(file2.LocalPath);
            SourceAdapter.EditFile(file1.LocalPath);

            SourceWorkspace.Get(VersionSpec.Latest, GetOptions.Overwrite);
            SourceWorkspace.PendBranch(branch.ServerPath, branch.NewServerPath, VersionSpec.ParseSingleSpec(branchFrom.ToString(), Environment.UserName));

            RunAndValidate();
        }
        public IVCDiffItem InitializeForDiff(string treeFilterSpecifier, string version)
        {
            string tfsTreeRoot = VersionControlPath.GetFullPath(treeFilterSpecifier);

            if (string.IsNullOrEmpty(version))
            {
                m_versionSpec = VersionSpec.Latest;
            }
            else
            {
                m_versionSpec = VersionSpec.ParseSingleSpec(version, null);
            }

            TfsVCDiffItem rootDiffItem = null;

            List <IVCDiffItem> subDiffItems = new List <IVCDiffItem>();

            ItemSet tfsItemSet = m_tfsClient.GetItems(tfsTreeRoot, m_versionSpec, RecursionType.OneLevel);

            foreach (Item item in tfsItemSet.Items)
            {
                if (string.Equals(item.ServerItem, tfsTreeRoot, StringComparison.OrdinalIgnoreCase))
                {
                    rootDiffItem = new TfsVCDiffItem(item, 0);
                }
                else
                {
                    TfsVCDiffItem diffItem = new TfsVCDiffItem(item, 1);
                    subDiffItems.Add(diffItem);
                }
            }

            if (rootDiffItem == null)
            {
                return(null);
            }

            rootDiffItem.SubItems.AddRange(subDiffItems);
            m_cachedFolderItems.Add(rootDiffItem.ServerPath, rootDiffItem);

            return(rootDiffItem);
        }
Esempio n. 29
0
        static void GetVersionByChangeset(Uri tfsUri, string serverPath, int changesetId)
        {
            TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(tfsUri);
            VersionControlServer     vcs = tpc.GetService <VersionControlServer>();
            Changeset changeset          = vcs.GetChangeset(changesetId);

            WorkingFolder workfolder = new WorkingFolder(serverPath, @"C:\tsf_" + changesetId);
            Workspace     workspace  = vcs.CreateWorkspace(changesetId.ToString());

            workspace.CreateMapping(workfolder);
            GetStatus status = workspace.Get(VersionSpec.ParseSingleSpec(
                                                 String.Format("C{0}", changesetId), null)
                                             , GetOptions.GetAll);

            workspace.Delete();
            StreamWriter fileWriter = new StreamWriter(@"C:\tsf_" + changesetId + @"\Database_snapshot.txt", false);

            fileWriter.WriteLine(changeset.Comment);
            fileWriter.Close();
            fileWriter.Dispose();
        }
Esempio n. 30
0
        public IEnumerable <TfsCheckin> QueryChangesetHistory(DateTime?from, DateTime?to)
        {
            var fromSpec   = from.HasValue ? VersionSpec.ParseSingleSpec("D" + from, null) : VersionSpec.ParseSingleSpec("D" + DateTime.Today.ToShortDateString() + " 00:00:01", null);
            var toSpec     = to.HasValue ? VersionSpec.ParseSingleSpec("D" + to, null) : VersionSpec.ParseSingleSpec("D" + DateTime.Now, null);
            var changesets = new List <TfsCheckin>();

            lock (_lock)
            {
                foreach (string folderId in _monitoredItems.Keys)
                {
                    var changesetsFolder = _versionControlServer.QueryHistory(_monitoredItems[folderId], VersionSpec.Latest, 0, RecursionType.Full, null, fromSpec, toSpec, int.MaxValue, false, false);

                    foreach (Changeset c in changesetsFolder)
                    {
                        changesets.Add(new TfsCheckin(c, ServerConfiguration.Id, ServerConfiguration.TfsTeamProjectCollection, folderId, _monitoredItems[folderId]));
                    }
                }
            }

            return(changesets);
        }