1

I needed to get the modified/new files alone in my TFS build get source task.

So far I've found We can disable the Get Source task by defining the variable Build.SyncSources = false

This will Just ignore of getting all the sources, which will eventually make my CopyFile Task to Fail since it using the $(Build.SourcesDirectory) as the source

> 2018-07-28T03:13:46.5709194Z Task         : 
> Copy Files 2018-07-28T03:13:46.5709194Z Description  : Copy files from source
> folder to target folder using match patterns (The match patterns will
> only match file paths, not folder paths) 2018-07-28T03:13:46.5709194Z
> Version      : 2.117.0 2018-07-28T03:13:46.5709194Z Author       :
> Microsoft Corporation 2018-07-28T03:13:46.5709194Z Help         :
> [More Information](https://go.microsoft.com/fwlink/?LinkID=708389)
> 2018-07-28T03:13:46.5709194Z
>     ============================================================================== 2018-07-28T03:13:47.1855024Z ##[error]Unhandled: Not found
> SourceFolder: $(Build.SourcesDirectory)

The Question in my Git Source Control there are many files which I don't want all to fetch while Building, Instead of that the files which are modified on that commit/PR merge I need to fetch.

How can I achieve this?

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
Jayendran
  • 9,638
  • 8
  • 60
  • 103

1 Answers1

0

Once a build server has synced the Git repository it will be able to just fetch the differences between the last build. Since Git relies on the full repository state being present (a commit is a pointer to a state of the working folder which includes all files at that state), it's not possible to just grab the changed files.

There is a switch in the Agent Phase step which controls whether the working directory will be cleaned, in which case the agent will have to sync the whole git repo. There's also an option there to only fetch the latest snapshot, instead of the full history:

Control clean and fetch

Shallow Fetch: Allows you to download only the latest snapshot of the repository. Will download much faster, but may cause tools like GitVersion to fail (it relies on the history data to calculate a version number).

Clean: False: will retain the contents of the previous build allowing you to do incremental fetches of sources, incremental builds with tools that support it. You can combine Clean:False with a custom step which performs more targeted clean up.

If you need the changed files you can issue a git command to copy them from your synced git repo. See: https://stackoverflow.com/a/4126342/736079.

Alternatively, don't sync the sources and use a custom VSTS Git REST API based script in Powershell to fetch the exact files you're after. See: https://learn.microsoft.com/en-us/rest/api/vsts/git/items?view=vsts-rest-4.1.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • Thanks for the response. Actually, I'm using on-prem TFS and not VSTS. The 1st link which you shared will be used for local modification which is not committed, however, this will not help in my case, where the files have been already committed and pushed. The second link which is purely based on VSTS – Jayendran Jul 29 '18 at 03:31
  • First link also explains modified in last commit: `git diff --name-only HEAD^`. The VSTS rest api works on tfs as well, depending on the version you're on. – jessehouwing Jul 29 '18 at 06:09
  • See https://learn.microsoft.com/en-us/vsts/integrate/concepts/rest-api-versioning?view=vsts – jessehouwing Jul 29 '18 at 06:11
  • Yes, you are right I modified the above git command like `cp -pv --parents `git diff --name-only HEAD^` DESTINATION-DIRECTORY` to copy all the modified contents alone. But I couldn't able to execute cp command in TFS since it's a `UNIX command` Could you please help me to tell some equivalent command in Cmd/ Powershell? – Jayendran Jul 29 '18 at 10:06