0

我想创建一个示例应用程序,它可以克隆用户的存储库,在其中添加一些文件,然后推送回远程存储库。我使用 Mercurial.NET C# API 来创建这个应用程序。

       string repoUrl = "https://bitbucket.org/USERNAME/REPONAME";

        var repoPath = @"THE LOCAL PATH";
        if (Directory.Exists(repoPath))
            Directory.Delete(repoPath, true);
        Directory.CreateDirectory(repoPath);
        var repo = new Mercurial.Repository(repoPath);

        repo.Clone(repoUrl, new CloneCommand().WithObserver(new DebugObserver()).WithUpdate(false));

        Random rand = new Random();

        string filename = "data" + rand.Next(0, 1000).ToString() + ".txt";

        using (StreamWriter _testData = new StreamWriter(@"E:\Lombiq\TestRepos\testrepo3\" + filename))
        {
            _testData.WriteLine("some text"); // Write the file.
        }
        repo.AddRemove(new AddRemoveCommand()
.WithIncludePattern("data*.txt"));

        repo.Commit("test commit");

        repo.Push(repoUrl); //How to add credentials?

我在 CSharp.Bitbucket ( https://github.com/scottksmith95/CSharp.Bitbucket ) 的帮助下成功地对用户进行了身份验证,因此我得到了一个令牌值和一个令牌秘密。

如何使用这些值将本地 repo 的内容推送回包含新文件的远程 repo?以及如何使用令牌值和令牌秘密来执行此操作?

非常感谢!

4

0 回答 0