0

From ASP.NET application I want to download specific files and subfolders that are present in Git remote repository using LibGit2Sharp.

For Example :

Main Remote Repository URL : https://github.com/macmillanhighered/TestApplication

Sub folder URL : https://github.com/macmillanhighered/TestApplication/tree/develop/Scripts/PRODUCTS

Instead of getting all files/folders i want to get specific folder only using libgit2sharp API.

I am using below sample code to do this, but it is not working. Please help me out as soon as possible

// Url of the remote repository to clone
        string url = "https://github.com/macmillanhighered/TestApplication/tree/develop/Scripts/PRODUCTS";

        // Location on the disk where the local repository should be cloned
        string workingDirectory = "C:\\TestGit";

        var credential = new UsernamePasswordCredentials() { Username = "nitin", Password = "test" };

        CloneOptions cloneOptions = new CloneOptions();
        cloneOptions.Credentials = credential;

        // Perform the initial clone
        string repoPath = Repository.Clone(url, workingDirectory, cloneOptions);


        using (var repo = new Repository(repoPath))
        {
             // "origin" is the default name given by a Clone operation
            // to the created remote
            var remote = repo.Network.Remotes["origin"];

            // Retrieve the changes from the remote repository
            // (eg. new commits that have been pushed by other contributors)
            Signature sign = new Signature("Test", "", DateTime.Now);

            FetchOptions fetchOptions = new FetchOptions();
            fetchOptions.Credentials = credential;

            MergeOptions mergeOptions = new MergeOptions();

            PullOptions pullOptions = new PullOptions();
            pullOptions.FetchOptions = fetchOptions;
            pullOptions.MergeOptions = mergeOptions;

            repo.Network.Pull(sign, pullOptions);
        }

I am getting below error

Request failed with status code: 404

Nitin
  • 1
  • 1

1 Answers1

1

I am getting below error Request failed with status code: 404

Clone() expects an url pointing to a git repository, not a file or folder with it.

Something like this should work better: string url = "https://github.com/macmillanhighered/TestApplication"

Instead of getting all files/folders i want to get specific folder only using libgit2sharp API.

The Git protocol doesn't work like this. You should fetch the whole repository and then locally work with the selected files you're interested in.

nulltoken
  • 64,429
  • 20
  • 138
  • 130