0

I want to create a TFS policy that blocks a changeset from being checked in if a certain keyword is found in the diff.

This will allow me to make local changes for testing ideas without worrying that these changes will be mistakanly checked in, as long as I add something like //nocommit in the code.

How can this be done?

liorda
  • 1,552
  • 2
  • 15
  • 38
  • What if you forget to add that magical keyword? – danish Apr 17 '18 at 08:53
  • @danish then the changeset will be checked in after a gated build. I know I could implement what I want on top of the gated check in mechanism on the build server, but it wouldn't be as instantaneous as a local policy could be. – liorda Apr 17 '18 at 09:30
  • I don't think there is a robust way to do this though policies. You might want to check cloaking feature if that can be utilized or write a custom code analysis rule which will be evaluated during check in. This rule should look for the comment (use TODO) and throw error. However, this is too much work. Check in policies can be enforced like putting in comments and assigning work items etc and if the dev still doesn't realize, we will need to do a rollback. – danish Apr 17 '18 at 10:55

1 Answers1

0

There is no out-of-box check-in policy to achieve your requirement, you have to customize your own check-in policy and use command tf diff itemspec /noprompt to compare files.

As a suggestion, you could consider using Git version control, create a branch from master and work on the branch. When you are ready to merge your code to master, create a pull request to review the code. In order to protect master, you could set branch policy on master. After you set up a branch policy, you cannot directly push changes to the branch. Changes to the branch are only made through pull requests.

Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39