boredDev
boredDev

Reputation: 346

How to monitor a TFVC branch for folder addition?

I'm looking for something that would let me know if a new folder has been added directly under my branch in TFVC. I tried using the tf client but though I can fetch the changesets and get history but I couldn't find what I was looking for.

What I want is, suppose there is a TFS branch TestBranch my script will poll that branch at regular intervals and return the folder name if a new folder has been added under that branch directly (sub-folders should be ignored).

Is there any tf command for this ? or how should I try to achieve my desired result?

Note : We are using TFS 2015. Also I tried looking into TFS service hooks so I don't have to poll the branch but creating service hooks requires administrator access which I don't have.

Upvotes: 0

Views: 61

Answers (1)

Andy Li-MSFT
Andy Li-MSFT

Reputation: 30442

No such a built-in trigger to achieve that.

However you can try list the folders under the specific branch directory (local workspace, you need to get latest version first every time) and output the list to a text file, then compare the text files and output the differents periodically/timely as needed based on your requirements.

You can try below PowerShell script sample to achieve that: (The first time to run the script will report the error such as "get-content : Could not find a part of the path 'C:\LC\temp\'", just ignore it. It will works from the second time.)


#Create a folder to store the output text files first, "C:\LC\temp" for example here.
$TempFolder = "C:\LC\temp"

$LocalBranchFolder = "C:\Workspaces\0418Scrum\WorkItemComments" #the path of the branch in local workspace.

$filename = (Get-Date).ToString("yyyyMMdd-HHmmss") + "_" + "FolderList"

$OldFileName = Get-ChildItem -Path $TempFolder | Select-Object -Last 1
$OldFile = "$TempFolder\$OldFileName" 
$NewFile = "$TempFolder\$filename.txt"

write-host $OldFile

#List all the folders under the specific branch (branch folder in local workspace)
Get-ChildItem -Path $LocalBranchFolder –Directory  | Out-File -FilePath $NewFile -Width 200

#Compare the folder lists and output the differents (New added folder)
compare-object (get-content $OldFile) (get-content $NewFile) | format-list

enter image description here

Upvotes: 0

Related Questions