我想要将Azure应用服务上文件夹中的文件推到Git版本库。
我已经将本地git仓库复制到服务器上,并使用LibGit2Sharp来提交和推送这些文件:
using (var repo = new Repository(@"D:\home\site\wwwroot\repo"))
{
// Stage the file
Commands.Stage(repo, "*");
// Create the committer's signature and commit
Signature author = new Signature("translator", "example.com", DateTime.Now);
Signature committer = author;
// Commit to the repository
Commit commit = repo.Commit($"Files updated {DateTime.Now}", author, committer);
Remote remote = repo.Network.Remotes["origin"];
var options = new PushOptions
{
CredentialsProvider = (_url, _user, _cred) =>
new UsernamePasswordCredentials
{
Username = _settings.UserName,
Password = _settings.Password
}
};
repo.Network.Push(remote, @"+refs/heads/master", options);
}
它起作用,但似乎需要一些时间,而且这看起来有点笨重。通过代码或者可能是直接通过Azure(配置或Azure函数),是否有更有效的方法来实现这个目标?