How to disable or remove candidate changes in TFS

2019-09-17 04:43发布

When files in a tfs workspace are moved outside of tfs (eg. through windows explorer), tfs picks these moves up as a delete and an add.

To get around this, I have a program running that monitors for changes and when a move happens I do a Workspace.PendRename with updateDisk set to false.

This works fine except that tfs adds the delete as a candidate change.

Is there anyway to remove this candidate change? It causes issues if people try and promote these changes.

By using Workspace.GetPendingChangesWithCandidates I can get the candidate change, but there doesn't seem to be anything I can do with it to remove it from the list.

Before doing the PendRename, I tried moving the file back to it's original location (File.Move) and then doing the PendRename with updateDisk set to true. This actually works well for single files, but gets complicated when folders and such are involved.

I'm hoping there's a simple way to either remove the candidate change from the list, or to even disable the candidate changes functionality altogether for certain files/folders. I tried adding the folder to the .tfignore file but that doesn't work.

Promote Candidate Changes shows deletes even though files were renamed

标签: c# api tfs
1条回答
The star\"
2楼-- · 2019-09-17 05:21

In TFS there are two kinds of moving files. I have crated a sample for both :

Local Workspace (window exploer) directly move/drag file

  1. In the disk my workspace, I'm going to move 2.PNG to Main-branch folder

enter image description here

  1. Then we could check what TFS detects in VS. One with add(in new place), one with delete(in old place) in Promote Candidate Changes.

    enter image description here

  2. You need to check in both the add and delete ( promote first). Finally you will get what you want both server and local.

Move a file in solution explorer directly

  1. In the solution explorer , I'm going to move 1.PNG to Main folder by right click and select move.

enter image description here

  1. You will get a pending change with rename status directly and not any Promote Candidate Changes.

    enter image description here

  2. Then we could check our local workspace, you will see 1.PNG is automatically deleted in the workspace folder even though you haven't check in changes. Finally checking pending changes, everything is fine and clean. enter image description here


Back to your question: Promote Candidate Changes shows deletes even though files were renamed.

The TFS API should be using the way 2 above. Look at the parameters :

updateDisk

If true, the local disk is updated according to the pending changes; if false, the disk is not modified and changes are not acknowledged.

So if you set the updateDisk to false , the 1.PNG should still exist in the disk and TFS detect it and adding to promote Candidate Changes shows deleted. Which meets your screenshot. The solution should be change the value from false to true.

查看更多
登录 后发表回答