3

I am wondering if it's possible to fetch only a single file from a Git repository in order to commit a new change to it. We want to change the file on a Azure DevOps Hosted Agent however downloading the entire repo would take a significantly long time, as it is large.

I read of these options:

  1. --Filter option
  2. Git sparse checkout (I'm not sure if this is only available on GitHub)
  3. Microsoft GVFS

Filter command attempt

git clone --depth 1 --filter=sparse:path=ReadMe.md
warning: filtering not recognized by server, ignoring

Sparse checkout

git config core.sparsecheckout true
echo File.txt >> .git/info/sparse-checkout git pull origin master
However it still retrieved everything.

The server repository is running GIT v2.18.

  • Is there anything that needs to be configured on the server to make it these work?
  • Is the --filter option only available on certain versions?
  • Could GVFS achieve this and is it possible to setup on the Hosted Agent?

Thank you.

David Gardiner
  • 16,892
  • 20
  • 80
  • 117
user3167162
  • 445
  • 1
  • 6
  • 23

2 Answers2

3

The best way to download one file from Git repo is with Azure DevOps Rest API - Items - Get.

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/items?path={path}&api-version=5.0-preview.1

If you add the parameter download (for example: ?path={path}&download=true) the file will be downloaded on the agent.

So add a task with a simple PowerShell script (with Invoke-RestMethod) and get the file.

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
  • Hi @Shayki Abramczyk, this will download the file however I need to be able to make a change and commit it to the server. Thanks for your response. – user3167162 Jan 20 '19 at 22:28
  • 2
    If we use 'Items - Get' in conjunction 'Pushes - Create' to modify the file it will fill our need. Thank you. https://learn.microsoft.com/en-us/rest/api/azure/devops/git/Pushes/Create?view=azure-devops-rest-5.0&viewFallbackFrom=vsts-rest-4.1#update_a_file – user3167162 Jan 21 '19 at 00:35
3
  1. Indeed the filter method will not work. As is further noted in the question you link:

    There is no server support as of v2.19.0, but it can already be locally tested.

  2. Sparse checkout will still download all the files, it just won't check them out to disk.

  3. GVFS requires server changes, and is only supported by Azure Repos. It is not part of stock (you indicate that your Git server is 2.18.)

As Shayki Abramczyk noted, using a REST API may be your best option. If your hosting provider supports it, you can probably download a file directly from the hosting provider. Many hosting providers will allow you to commit those changes as well.

Community
  • 1
  • 1
Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
  • Thank you for the clarifications @Edward Thomson. The VSTS provider does support creating commits through their REST API. Pushes - Create: https://learn.microsoft.com/en-us/rest/api/azure/devops/git/Pushes/Create?view=azure-devops-rest-5.0&viewFallbackFrom=vsts-rest-4.1#update_a_file – user3167162 Jan 21 '19 at 00:31