Exemplo n.º 1
0
        public bool Run(TfsTask task, RevertChangesRequest req, RevertChangesResponse resp)
        {
            bool unchangedOnly = req.Args.Count > 1 && req.Args[1] == "unchangedOnly";

            bool keepLocalModifications = req.Args.Count > 1 && req.Args[1] == "keepLocalModifications";

            foreach (var item in req.Revisions)
            {
                if (item.Value == ChangelistRevision.kDefaultListRevision)
                {
                    var pending = task.Workspace.GetPendingChanges(new[] { new ItemSpec(task.ProjectPath, RecursionType.Full) });

                    var itemSpecs = pending.Select(each => new ItemSpec(each.LocalItem, RecursionType.None)).ToArray();

                    TfsRevertCommand.RevertCore(task, unchangedOnly, keepLocalModifications, itemSpecs);

                    var versionedAssets = new VersionedAssetList();
                    versionedAssets.AddRange(pending.Select(each => new VersionedAsset(TfsTask.GetAssetPath(each, task.Workspace, true))));

                    task.GetStatus(versionedAssets, resp.Assets, false, true);
                }
            }

            resp.Write();
            return(true);
        }
Exemplo n.º 2
0
        private static void ExpandFoldersIntoFiles(TfsTask task, Connection connection, VersionedAssetList versionedAssets)
        {
            List <string> enumeratedFiles = new List <string>();

            //Check each asset to see if it is a folder
            for (int i = versionedAssets.Count - 1; i >= 0; i--)
            {
                VersionedAsset asset = versionedAssets[i];

                if (!asset.IsFolder())
                {
                    continue;
                }

                try
                {
                    //Get all files in the folder
                    enumeratedFiles.AddRange(Directory.GetFiles(asset.Path, "*.*", SearchOption.AllDirectories));
                    connection.LogInfo("Expanding Folder: " + asset.Path);
                }
                catch (Exception e)
                {
                    connection.WarnLine(e.Message);
                }

                //Remove the folder from the checkout
                versionedAssets.RemoveAt(i);
            }

            //Get the status of the enumerated files
            VersionedAssetList newVersionedAssets = new VersionedAssetList();

            task.GetStatus(enumeratedFiles.ToArray(), newVersionedAssets, false, true);

            //Remove any local-only files
            for (int i = newVersionedAssets.Count - 1; i >= 0; i--)
            {
                VersionedAsset asset = newVersionedAssets[i];
                if (!asset.IsKnownByVersionControl || asset.HasPendingLocalChange)
                {
                    newVersionedAssets.RemoveAt(i);
                }
            }

            //Add the new assets to the asset list
            versionedAssets.AddRange(newVersionedAssets);
        }