Example #1
0
        /// <summary>
        /// Get the information about a Git blob by its ID.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository</param>
        /// <param name="blobId">The object ID of the blob</param>
        /// <returns>The blob</returns>
        public async Task<Blob> GetBlob(Guid repositoryId, ObjectId blobId)
        {
            Assert.NotNull(repositoryId, "repositoryId");
            Assert.NotNull(blobId, "blobId");

            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/blobs/{BlobId}");
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("BlobId", blobId.ToString());

            return await Executor.Execute<Blob>(request);
        }
Example #2
0
        /// <summary>
        /// Download a blob's contents.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository</param>
        /// <param name="blobId">The object ID of the blob</param>
        /// <param name="format">The format to download as</param>
        /// <param name="outputStream">The stream to write the response content to asynchronously</param>
        public async Task DownloadBlob(Guid repositoryId, ObjectId blobId, BlobFormat format, Stream outputStream)
        {
            Assert.NotNull(repositoryId, "repositoryId");
            Assert.NotNull(blobId, "blobId");
            Assert.NotNull(outputStream, "outputStream");

            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/blobs/{BlobId}");
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("BlobId", blobId.ToString());

            if (format == BlobFormat.Zip)
            {
                request.AddUrlSegment("$format", "zip");
                request.AddHeader("Accept", "application/zip");
            }
            else
            {
                request.AddUrlSegment("$format", "octetstream");
                request.AddHeader("Accept", "application/octet-stream");
            }

            await Executor.Execute(request, outputStream);
        }
Example #3
0
        /// <summary>
        /// Download the contents of a tree as a zip file.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository</param>
        /// <param name="treeId">The object ID of the tree</param>
        /// <param name="outputStream">The stream to write to asynchronously</param>
        public async Task DownloadTree(Guid repositoryId, ObjectId treeId, Stream outputStream)
        {
            Assert.NotNull(repositoryId, "repositoryId");
            Assert.NotNull(treeId, "treeId");
            Assert.NotNull(outputStream, "outputStream");

            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/trees/{TreeId}");
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("TreeId", treeId.ToString());
            request.AddUrlSegment("$format", "zip");
            request.AddHeader("Accept", "application/zip");

            await Executor.Execute(request, outputStream);
        }
Example #4
0
        /// <summary>
        /// Get the information about a Git tree by its ID.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository</param>
        /// <param name="treeId">The object ID of the tree</param>
        /// <returns>The tree</returns>
        public async Task<Tree> GetTree(Guid repositoryId, ObjectId treeId)
        {
            Assert.NotNull(repositoryId, "repositoryId");
            Assert.NotNull(treeId, "treeId");

            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/trees/{TreeId}");
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("TreeId", treeId.ToString());

            return await Executor.Execute<Tree>(request);
        }
Example #5
0
        /// <summary>
        /// Get a commit in a repository.
        /// </summary>
        /// <param name="repositoryId">The ID of the repository</param>
        /// <param name="commitId">The ID of the commit</param>
        /// <param name="changeCount">The number of changes to return, or 0 for none.</param>
        /// <returns>The commit in the Git repository</returns>
        public async Task<Commit> GetCommit(Guid repositoryId, ObjectId commitId, int changeCount = 0)
        {
            Assert.NotNull("commitId", "commitId");

            var request = new TfsRestRequest("/_apis/git/repositories/{RepositoryId}/commits/{CommitId}");
            request.AddUrlSegment("RepositoryId", repositoryId.ToString());
            request.AddUrlSegment("CommitId", commitId.ToString());
            request.AddOptionalParameter("changeCount", changeCount, () => { return changeCount > 0; });

            return await Executor.Execute<Commit>(request);
        }
Example #6
0
 /// <summary>
 /// A revision in a Git repository, by the commit ID.
 /// </summary>
 /// <param name="commitId"></param>
 public Revision(ObjectId commitId)
 {
     type = RevisionType.Commit;
     version = commitId.ToString();
 }