sohail
sohail

Reputation: 649

How to preserve server change timestamps on files get using GET in TFS?

I am using workspace.get() in TFS 2013 environment. It works perfectly, however, the timestamps on files downloaded are set to current timestamp.

Is there a way to get files and set the file timestamps to either the checkin time or actual file edit time on server?

I tried to look for answers on Google as well as Stackoverflow. The closest thing I found was a thread on MSDN which didn't have a conclusive answer.

Hopefully, someone can provide a quick answer to this.

Thank you for your help.

Upvotes: 2

Views: 1711

Answers (2)

sohail
sohail

Reputation: 649

Finally, after searching through the internet and Microsoft document, I was able to create workspace with above property with following code:

$tfsServer = Get-TfsServer -Name $props.tfsURI -Credential $tfsRepoCredentials
$structureService = $tfsServer.GetService("Microsoft.TeamFoundation.Server.ICommonStructureService")
$versionControlService = $tfsServer.GetService("Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer")

$workSpaceName = $env:USERNAME "-"+ $patchNumber

$wsParams = New-Object Microsoft.TeamFoundation.VersionCotrol.Client.CreateWorkspaceParameters -ArgumentList $workSpaceName
$wsParams.WorkspaceOptions = [Microsoft.TeamFoundation.VersionControl.Common.WorkspaceOptions]::SetFileTimeToCheckin

$versionControlService.CreateWorkspace($wsParams)

The answers in the question Automating workspace creation in Team Foundation Server provided helpful information on how to set workspace options.

Thanks to @Andy for help.

Upvotes: 0

Andy Li-MSFT
Andy Li-MSFT

Reputation: 30412

By default TFS will write file times to the "current" time when you retrieved the files from remote repository. This is the default behavior of most version control tools and generally considered safe.

Setting time to the remote time can have negative consequences in many scenarios. For example, make will scan for files newer than the last build time. Setting file times to the server's time can impact the ability to determine which files have changed since the last build.

However, if you want to get files and set the file timestamps to the checkin time, you can edit the specific Workspace by setting "File Time" to "Checkin":

Manage Workspaces... -> Select the specific workspace -> Edit -> Advanced -> File Time - Checkin  

Please note below things (See How do I choose advanced workspace options? for details. ) :

File Time:

  • Choose Checkin if you want the date and time stamp of each file to generally match the stamp of the changeset of the version in your workspace. A few issues and exceptions are:

    • When you modify the local file, the date and time stamp will match the date and time when you modified the file.

    • This feature is available only if you are using Visual Studio 2012 or later and Visual Studio Team Foundation Server 2012 or later.

    • The setting does not apply to folders, unless there is a pending add or delete operation to a file contained by the folder.

    • You might not be able to build your code project incrementally. Instead, you will have to rebuild).

  • Choose Current if you want the date and time stamp to match the date and time when you last modified the local file. For example, a team member checked in the latest change to the file on Monday. On Tuesday, you perform a get operation to update the file. The date and time stamp is set to Tuesday.

enter image description here

Upvotes: 2

Related Questions