I have an Check-In-Policy extension for VS2017 (using TFS 2017) that checks if the pending check-in contains files matching a given regex.
In case matching files are contained in CheckedPendingChanges
the Evaluate
method returns the PolicyFailure
to avoid checking in these files.
[Serializable]
public class FileWarningPolicy : PolicyBase
{
// ...
public override PolicyFailure[] Evaluate()
{
Regex regex = new Regex(Pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
if (PendingCheckin.Policies.EvaluationState != PolicyEvaluationState.Evaluated) return new PolicyFailure[0];
var matchingFiles = from change in PendingCheckin.PendingChanges.CheckedPendingChanges
where change.IsEdit && regex.IsMatch(change.ServerItem)
select change;
return matchingFiles.Any()
? new [] { new PolicyFailure("some error message", this)
: new PolicyFailure[0];
}
}
This works fine. But it would be far more comfortable if I were able to simply "uncheck" these files to exclude them from the current check-in but not abort the whole check-in.
Through the PendingCheckin.PendingChanges
property I have access to the current Workspace
which has a lot of methods to download, check-in, check-out, shelve etc. the repository items, but nothing to only uncheck/exclude them from the checked pending changes (only to add an exclude entry to .tfignore
, which is not what I want).
Is there a way to achieve this?