コード例 #1
0
        public bool Run(TfsTask task, Request req, Response resp)
        {
            VersionedAssetList statAssets = new VersionedAssetList();

            try
            {
                for (int i = 0; i < req.Assets.Count; i++)
                {
                    var firstAsset = req.Assets[i];
                    var srcPath    = firstAsset.GetPath();

                    ++i;
                    if (i >= req.Assets.Count)
                    {
                        req.Conn.ErrorLine("No destination path while moving source path " + srcPath);
                        break;
                    }

                    var dstPath = req.Assets[i].GetPath();

                    task.Workspace.PendRename(srcPath, dstPath, task.ShouldLock(firstAsset) ? task.GetLockLevel() : LockLevel.None, true, true);

                    statAssets.Add(req.Assets[i]);
                }
            }
            catch (Exception e)
            {
                req.Conn.ErrorLine(e.Message);
            }

            task.GetStatus(statAssets, resp.Assets, false, true);

            resp.Write();
            return(true);
        }
コード例 #2
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);
        }
コード例 #3
0
        public static void Resolve(TfsTask task, Resolution resolution, VersionedAssetList assets)
        {
            Conflict[] conflicts = task.GetConflicts(assets);

            foreach (var item in conflicts)
            {
                if (resolution == Resolution.AcceptMerge)
                {
                    item.Resolution = Resolution.AcceptYours;
                    task.Workspace.ResolveConflict(item);
                }
                else
                {
                    Conflict[] resolved;
                    item.Resolution = resolution;

                    task.Workspace.ResolveConflict(item, out resolved);

                    if (resolution == Resolution.AcceptTheirs && resolved.Length == 0)
                    {
                        item.Resolution = Resolution.OverwriteLocal;
                        task.Workspace.ResolveConflict(item, out resolved);
                    }
                }
            }
        }
コード例 #4
0
        public static void PendEdit(TfsTask task, Connection connection, VersionedAssetList req)
        {
            string[] toLock;
            string[] notToLock;
            task.SplitByLockPolicy(req, out toLock, out notToLock);

            if (toLock != null && toLock.Length != 0)
            {
                try
                {
                    var level = task.GetLockLevel();
                    task.Workspace.PendEdit(toLock, RecursionType.None, null, level);
                }
                catch (Exception e)
                {
                    connection.WarnLine(e.Message);
                }
            }

            if (notToLock != null && notToLock.Length != 0)
            {
                try
                {
                    task.Workspace.PendEdit(notToLock, RecursionType.None, null, LockLevel.None);
                }
                catch (Exception e)
                {
                    connection.WarnLine(e.Message);
                }
            }
        }
コード例 #5
0
        public void GetStatus(IEnumerable <VersionedAsset> assets, VersionedAssetList result, bool recursive, bool queryRemote)
        {
            if (string.IsNullOrEmpty(tpcPath))
            {
                m_Connection.LogInfo("Status requested without server.");
            }

            GetStatus(assets.Select(each => each.GetPath()).ToArray(), result, recursive, queryRemote);
        }
コード例 #6
0
 /// <summary>
 /// a user can manually make a file not readonly to notify unity it is "checked out" locally and can be modified.
 /// </summary>
 /// <param name="result"></param>
 private void MergeInWorkLocalStatus(VersionedAssetList result)
 {
     foreach (var item in result)
     {
         if (!item.HasPendingLocalChange && item.IsKnownByVersionControl && item.IsWritable)
         {
             item.AddState(State.kOutOfSync | State.kCheckedOutLocal);
         }
     }
 }
コード例 #7
0
        void ToVersionedAssetList(ExtendedItem[][] items, VersionedAssetList result)
        {
            foreach (var item in items)
            {
                foreach (var eachItem in item)
                {
                    VersionedAsset asset = ToVersionedAsset(eachItem);

                    result.Add(asset);
                }
            }
        }
コード例 #8
0
        public VersionedAssetList GetStatus()
        {
            VersionedAssetList result = new VersionedAssetList();

            var projectFolder = new VersionedAsset(GetAssetPath(projectPath, Workspace.GetServerItemForLocalItem(projectPath), ItemType.Folder, Workspace));

            GetStatus(new VersionedAssetList {
                projectFolder
            }, result, true, true);

            return(result);
        }
コード例 #9
0
        internal void MergeInMoreDetailedPendingChanges(VersionedAssetList result, bool isRecursive)
        {
            if (result.Count == 0)
            {
                return;
            }

            var conflicts = GetConflicts(result);

            foreach (var item in conflicts)
            {
                var found = FindVersionedAsset(item, result);

                if (found != null)
                {
                    found.AddState(State.kConflicted);
                    found.RemoveState(State.kSynced);
                    found.AddState(State.kOutOfSync);
                }
            }

            if (Workspace.Location == Microsoft.TeamFoundation.VersionControl.Common.WorkspaceLocation.Server)
            {
                var time    = DateTime.Now;
                var pending = GetProjectPendingSets(result, isRecursive);

                var localPending  = pending.Where(item => item.Type == PendingSetType.Workspace && item.OwnerName == Workspace.OwnerName && item.Name == Workspace.Name).ToArray();
                var remotePending = pending.Where(item => item.Type == PendingSetType.Workspace && !(item.OwnerName == Workspace.OwnerName && item.Name == Workspace.Name)).ToArray();

                TfsFileStatusCache.RefreshPendingChanges(result.Select(each => each.GetPath()), Workspace, remotePending, localPending, time);

                foreach (var item in pending)
                {
                    if (item.Type != PendingSetType.Workspace)
                    {
                        continue;
                    }

                    if (item.OwnerName == Workspace.OwnerName && item.Name == Workspace.Name)
                    {
                        ApplyStatusFromPendingSet(result, item, true);
                    }
                    else
                    {
                        ApplyStatusFromPendingSet(result, item, false);
                    }
                }
            }
        }
コード例 #10
0
        public static List <string> Paths(VersionedAssetList assets)
        {
            List <string> result = new List <string>(assets.Count);

            foreach (var i in assets)
            {
                string p = i.GetPath();
                if (i.IsFolder())
                {
                    p = p.Remove(p.Length - 1, 1); // strip ending /
                }
                result.Add(p);
            }
            return(result);
        }
コード例 #11
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);
        }
コード例 #12
0
        private void ApplyStatusFromPendingSet(VersionedAssetList result, PendingSet item, bool isLocal)
        {
            // each local pending change
            foreach (var eachPendingChange in item.PendingChanges)
            {
                var asset = FindVersionedAsset(eachPendingChange, result);

                if (asset == null)
                {
                    continue;
                }

                if (eachPendingChange.IsLock)
                {
                    asset.AddState(isLocal ? State.kLockedLocal : State.kLockedRemote);
                }

                if (eachPendingChange.IsAdd)
                {
                    asset.AddState(isLocal ? State.kAddedLocal : State.kAddedRemote);
                }
                else if (eachPendingChange.IsDelete)
                {
                    asset.AddState(isLocal ? State.kDeletedLocal : State.kDeletedRemote);

                    if (isLocal)
                    {
                        asset.RemoveState(State.kMissing);
                        asset.AddState(State.kSynced);
                    }
                }
                else if (eachPendingChange.IsEdit || eachPendingChange.IsRename || eachPendingChange.IsBranch || eachPendingChange.IsMerge || eachPendingChange.IsRollback || eachPendingChange.IsUndelete || eachPendingChange.IsEncoding)
                {
                    asset.AddState(isLocal ? State.kCheckedOutLocal : State.kCheckedOutRemote);
                }
            }
        }
コード例 #13
0
 internal PendingChange[] GetProjectPendingChanges(VersionedAssetList versionedAssetList)
 {
     return(Workspace.GetPendingChanges(versionedAssetList.Select(each => each.GetPath()).ToArray()));
 }
コード例 #14
0
        VersionedAsset FindVersionedAsset(Conflict item, VersionedAssetList list)
        {
            var path = GetAssetPath(item, Workspace);

            return(list.FirstOrDefault(each => each.Path.Equals(path, StringComparison.CurrentCultureIgnoreCase)));
        }
コード例 #15
0
        internal PendingSet[] GetProjectPendingSets(VersionedAssetList versionedAssetList, bool isRecursive = true)
        {
            var list = versionedAssetList.Select(each => each.GetPath()).ToArray();

            return(VersionControlServer.GetPendingSets(list, isRecursive ? RecursionType.Full : RecursionType.None));
        }
コード例 #16
0
        internal void GetStatus(string[] assets, VersionedAssetList result, bool recursive, bool queryRemote)
        {
            var timer = new Stopwatch();

            timer.Start();
            var time = DateTime.Now;

            // if we are not connected to tfs
            if (this.Workspace == null)
            {
                return;
            }

            if (recursive)
            {
                if (assets.Length == 0)
                {
                    // Empty means all in recursive mode

                    var status = GetProjectExtendedStatus();

                    tfsFileStatusCache.RefreshExtendedStatus(status, Workspace, time);
                    ToVersionedAssetList(status, result);
                }
                else
                {
                    var status = GetProjectExtendedStatus(assets, true);
                    tfsFileStatusCache.RefreshExtendedStatus(status, Workspace, time);
                    ToVersionedAssetList(status, result);
                }
            }
            else
            {
                if (assets.Length != 0)
                {
                    var status = GetProjectExtendedStatus(assets, false);
                    tfsFileStatusCache.RefreshExtendedStatus(status, Workspace, time);
                    ToVersionedAssetList(status, result);
                }
            }

            // Make sure that we have status for local only assets as well
            foreach (var i in assets)
            {
                if (i.Contains("*"))
                {
                    continue;
                }

                if (!result.Any(each => each.GetPath().Equals(i, StringComparison.CurrentCultureIgnoreCase)))
                {
                    result.Add(new VersionedAsset(i, State.kLocal, "0"));
                }
            }


            timer.Restart();
            MergeInMoreDetailedPendingChanges(result, recursive);

            if (IsPartiallyOffline)
            {
                MergeInWorkLocalStatus(result);
            }
        }
コード例 #17
0
        internal Conflict[] GetConflicts(VersionedAssetList versionedAssetList)
        {
            var conflicts = Workspace.QueryConflicts(versionedAssetList.Select(each => each.GetPath()).ToArray(), true);

            return(conflicts);
        }
コード例 #18
0
 public ChangesetData(string comment, VersionedAssetList assets)
 {
     this.Comment = comment;
     Changes      = assets;
 }