GitGuardChanges
Check if certain files have been changed between two commits
YAML Snippet
- task: GitGuardChanges@0
  inputs:
    sourceCommitHash: #Oldest commit hash to check from
    targetCommitHash: HEAD #Newest commit hash to check to  (Default `HEAD`)
    matchPattern: #Files to match
    matchStrategy: all #If single only a `single` result from `matchPattern` needs to be matched, else all.
    breakOnFailure: false #Break the build in addition to setting the result variables
Arguments
| Argument | Description | 
|---|---|
sourceCommitHash Source Commit Hash  | (Required) Oldest commit hash to check from  | 
targetCommitHash Target Commit Hash  | (Required) Newest commit hash to check to (Default HEAD) Default value: HEAD | 
matchPattern Match Pattern  | (Required) Files to match  | 
matchStrategy Match Strategy  | (Required) If single only a single result from matchPattern needs to be matched, else all. Options: all, single Default value: all | 
breakOnFailure Break on failure  | (Optional) Break the build in addition to setting the result variables  | 
Output variables
These are the output variables the task sets:
| Name | Description | 
|---|---|
| gitGuardChangesResult | Match result | 
| gitGuardChangesCount | Count of number of matched files that was changed | 
| gitGuardChangesMatches | List of file paths of files that was changed | 
📜 Commit Query
"Commit Query" allows you resolve certain git hashes dynamically. It is basically just a selector for what git commands should be run in the background.
tag:<matchFormat>: Fetches the latest tag matching the format
Examples
Assume the repo contains two tags, v0.0.7-dev, v0.0.8-dev, and v0.0.9 the following tag:v*-dev expression would resolve to the latest tag created. In this case v0.0.8-dev. The query tag:v*[!-dev] would resolve v0.0.9.
❓ Pipeline Examples
Verify a single file has been changed
Assume the latest tag created is v0.0.7-dev and in the commits made after the tag was created have changed the following files.
ci/pipeline.ymldocs/CHANGELOG.mddocs/README.md
Given the following pipeline configuration:
steps:
  - task: GitGuardChanges@0
    displayName: 'Verify changelog'
    inputs:
      sourceCommitHash: 'tag:*-dev'
      targetCommitHash: 'HEAD'
      matchPattern: 'docs/CHANGELOG.md'
      matchStrategy: 'single'
      breakOnFailure: true
assume matchPattern will resolve the following files:
docs/CHANGELOG.md
and the task will output:
gitGuardChangesResult:truegitGuardChangesCount:1gitGuardChangesMatches:docs/CHANGELOG.md
Verify all matched files have been changed
Assume the latest tag created is v0.0.7-dev and in the commits made after the tag was created have changed the following files.
ci/pipeline.ymldocs/CHANGELOG.mddocs/README.mdpackages/package-one/index.jspackages/package-one/index2.jspackages/package-two/index2.js
Given the following pipeline configuration:
steps:
  - task: GitGuardChanges@0
    displayName: 'Verify changelog'
    inputs:
      sourceCommitHash: 'tag:*-dev'
      targetCommitHash: 'HEAD'
      matchPattern: '**/*/index2.js'
      matchStrategy: 'all'
      breakOnFailure: true
assume matchPattern will resolve the following files:
packages/package-one/index2.jspackages/package-two/index2.js
and the task will output:
gitGuardChangesResult:truegitGuardChangesCount:2gitGuardChangesMatches:packages/package-one/index2.jspackages/package-two/index2.js
and assume matchPattern will resolve the following files:
packages/package-one/index2.jspackages/package-two/index2.jspackages/package-three/index2.js
and the task will output:
gitGuardChangesResult:falsegitGuardChangesCount:2gitGuardChangesMatches:packages/package-one/index2.jspackages/package-two/index2.js