コード例 #1
0
        public async Task PushChangesAsync()
        {
            try
            {
                using (var repository = new Repository(ContentService.GetRepoFolder(Repo)))
                {
                    var status    = repository.RetrieveStatus();
                    var filePaths = status.Modified.Select(i => i.FilePath).Union(status.Untracked.Select(i => i.FilePath)).ToList();
                    if (!filePaths.Any())
                    {
                        return;
                    }
                    foreach (var p in filePaths)
                    {
                        repository.Index.Add(p);
                    }

                    repository.Commit("Changes", new Signature("scenarios-explorer", "*****@*****.**", DateTime.UtcNow), new Signature("scenarios-explorer", "*****@*****.**", DateTime.UtcNow));

                    var remote = repository.Network.Remotes["origin"];
                    repository.Network.Push(remote, pushRefSpec: "refs/heads/master", pushOptions: new PushOptions()
                    {
                        CredentialsProvider = new CredentialsHandler(CredentialsProvider)
                    });
                }
            }
            catch (LibGit2Sharp.NonFastForwardException)
            {
                // Means server has newer commits. Should be a niche case, just delete and drop their changes.
                await ContentService.DeleteCacheAsync(Repo);
            }
        }
コード例 #2
0
            private async Task ActuallyCloneAsyncHelper()
            {
                try
                {
                    await ContentService.DeleteCacheAsync(Repo);

                    string clonedRepoPath = Repository.Clone(Repo.Url, ContentService.GetRepoFolder(Repo), new CloneOptions()
                    {
                        BranchName = Repo.Branch, CredentialsProvider = ChangesService.CredentialsProvider
                    });
                }
                finally
                {
                    lock (m_queue)
                    {
                        m_queue.Remove(this);
                    }
                }
            }