microsoft / azure-devops-dotnet-samples

.NET/C# samples for integrating with Azure DevOps Services and Azure DevOps Server
https://docs.microsoft.com/azure/devops/integrate
MIT License
517 stars 510 forks source link

Example for git fork #140

Open xtreampb opened 6 years ago

xtreampb commented 6 years ago

Trying to follow the API for forking a repository (first step in a much larger chain). I've realized a fork is just creating a new repository with added source references. Trying to consume this api call: Git Create I'm not sure what to put for the source ref in the URL in addition to what data makes up the body of the request.

I would greatly appriciate an example on how to fork an existing repo from one project to another one, in addition to within the same project.

petersgiles commented 4 years ago

I am having the same problem. a better example would be appreciated.

petersgiles commented 4 years ago

Its as simple as this sourceRef=refs/heads/master. This article was useful and would be a good thing to reference in the documentation Git-Internals-Git-References

After a little spelunking I came up with this.

      var stringContent = new StringContent(JsonConvert.SerializeObject(new
            {
                name = $"{name}",
                parentRepository = new
                {
                    id = parentRepositoryGuid,
                    project = new
                    {
                        id = projectGuid
                    }
                },
                project = new
                {
                    id = projectGuid
                }
            }), Encoding.UTF8, "application/json");

            var url = $"{DEVOPSBASEURL}/{projectGuid}/_apis/git/repositories?sourceRef=refs/heads/master&api-version=4.1";