SYSK 372: TFS – Enforcing Comments on Check-In & Violations Query

As many web sites point out, TFS uses policies to implement a requirement that developers provide comments when checking in code. The policy must be deployed to each developer (client machines). The Team Foundation Server Power Tools include the Changeset Comments Policy, which allows you to verify that the Comments text box in the Check In dialog box is not empty (see attached… the configuration can also be done via a batch file). Once the policy is deployed, developers will not be able to check in a file if the Comments text box is empty.

 

To download Power Tools for VSTS 2005, go to http://msdn.microsoft.com/en-us/teamsystem/aa718351.aspx

To download Power Tools for VSTS 2008, go to http://msdn.microsoft.com/en-us/teamsystem/bb980963.aspx

 

Since check-in policies are evaluated on the client, so it’s not possible to completely prevent someone from disabling the policy, or not installing it in the first place, and, thus, checking in code without entering comments.

 

However, a manager can subscribe to an alert (Power Tools include an Alert Editor), and receive an e-mail when comments are not entered at check-in, or other policies are violated.

 

 

Alternatively, you can create a report that goes directly against SQL tables. The query below returns all project name, change request (work item) title, source control changeset id, datetime, person ‘s name and e-mail for all checked-in files with empty comment. The query below filters out changes done before 1/1/2008.

 

-- Specifically, empty comments

SELECT

tn.Name,

      wi.Title,

      cs.ChangeSetId,

cs.CreationDate,

pr.Person,

pr.Email

FROM   

    TfsVersionControl..tbl_ChangeSet cs

INNER JOIN

    TfsVersionControl..tbl_Identity i ON cs.OwnerId=i.IdentityId

INNER JOIN

    TfsWarehouse..Person pr ON (i.DisplayName COLLATE SQL_Latin1_General_CP1_CI_AS) = (pr.Domain + N'\' + pr.Alias)

INNER JOIN

      TfsWarehouse..[Work Item Changeset] w ON cs.ChangeSetId = w.Changeset

INNER JOIN

      TfsWorkItemTracking..WorkItemsAre wi ON w.[Work Item] = wi.ID

INNER JOIN

      TfsWorkItemTracking..TreeNodes tn ON w.[Team Project] = tn.ID

WHERE Comment IS NULL

      AND cs.CreationDate > '2008-01-01'

      AND tn.ParentID = 0

      AND tn.TypeID = -42

ORDER BY

    cs.ChangeSetId DESC

 

 

 

Another query (below) returns information on policy overrides:

 

-- Policy overrides

SELECT

      tn.Name,

      wi.Title,

    p.ChangeSetId,

    cs.CreationDate,

    cs.Comment,

    p.Comment,

    pr.Person,

    pr.Email

FROM

    TfsVersionControl..tbl_PolicyOverride p

INNER JOIN

    TfsVersionControl..tbl_ChangeSet cs ON p.ChangeSetId=cs.ChangeSetId

INNER JOIN

    TfsVersionControl..tbl_Identity i ON cs.OwnerId=i.IdentityId

INNER JOIN

    TfsWarehouse..Person pr ON (i.DisplayName COLLATE SQL_Latin1_General_CP1_CI_AS) = (pr.Domain + N'\' + pr.Alias)

INNER JOIN

      TfsWarehouse..[Work Item Changeset] w ON cs.ChangeSetId = w.Changeset

INNER JOIN

      TfsWorkItemTracking..WorkItemsAre wi ON w.[Work Item] = wi.ID

INNER JOIN

      TfsWorkItemTracking..TreeNodes tn ON w.[Team Project] = tn.ID

WHERE

      tn.ParentID = 0

      AND tn.TypeID = -42

ORDER BY

    cs.ChangeSetId DESC