コード例 #1
0
        public Branch Checkout(IIntegrationResult result, string branchName)
        {
            result.AddMessage($"#Checkout {branchName}");
            var task = Task.Run(() =>
            {
                using (var repo = GetRepository())
                {
                    if (repo.Head.FriendlyName == branchName)
                    {
                        return(repo.Branches[branchName]);
                    }

                    Branch branch = repo.Branches[branchName];
                    if (branch == null)
                    {
                        branch           = repo.CreateBranch(branchName, $"origin/{branchName}");
                        var remoteBranch = repo.Branches[$"origin/{branchName}"];
                        repo.Branches.Update(branch
                                             , b => b.UpstreamBranch = remoteBranch.UpstreamBranchCanonicalName
                                             , b => b.TrackedBranch  = remoteBranch.CanonicalName
                                             );
                        branch = repo.Branches[branchName];
                    }
                    return(Commands.Checkout(repo, branch));
                }
            });

            task.Wait();
            return(task.Result);
        }
コード例 #2
0
        public void FetchOrigin(IIntegrationResult result)
        {
            result.AddMessage("#FetchOrigin");
            var task = Task.Run(() =>
            {
                using (var repo = GetRepository())
                {
                    string logMessage = "";
                    foreach (Remote remote in repo.Network.Remotes)
                    {
                        IEnumerable <string> refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
                        Commands.Fetch(repo, remote.Name, refSpecs, GetFetchOptions(), logMessage);
                        result.AddMessage(logMessage);
                    }
                }
            });

            task.Wait();
        }
コード例 #3
0
        public IList <Conflict> GetConflictsList(IIntegrationResult result)
        {
            result.AddMessage("#GetConflictsList");
            var task = Task.Run(() =>
            {
                IList <Conflict> conflictList;
                using (var repo = GetRepository())
                {
                    conflictList = repo.Index.Conflicts.ToList();
                }
                if (conflictList.Count > 0)
                {
                    result.AddMessage(string.Join(Environment.NewLine, conflictList.Select(t => t.Ours.Path)));
                }
                return(conflictList);
            });

            task.Wait();
            return(task.Result);
        }
コード例 #4
0
        public IList <TreeEntryChanges> GetDiffList(IIntegrationResult result, string target)
        {
            result.AddMessage($"#GetDiffList {target}");
            var task = Task.Run(() =>
            {
                IList <TreeEntryChanges> diffList;
                using (var repo = GetRepository())
                {
                    diffList = repo.Diff.Compare <TreeChanges>(repo.Head.Tip.Tree, repo.Branches[target].Tip.Tree).ToList();
                }
                if (diffList.Count > 0)
                {
                    result.AddMessage(string.Join(Environment.NewLine, diffList.Select(t => t.Path)));
                }
                return(diffList);
            });

            task.Wait();
            return(task.Result);
        }
コード例 #5
0
        public void Push(IIntegrationResult result, string branch)
        {
            result.AddMessage("#Push");
            var task = Task.Run(() =>
            {
                using (var repo = GetRepository())
                {
                    repo.Network.Push(repo.Branches[branch], GetPushOptions());
                }
            });

            task.Wait();
        }
コード例 #6
0
        public Tuple <MergeResult, IList <Modification> > Pull(IIntegrationResult result)
        {
            result.AddMessage("#Pull");
            var task = Task.Run(() =>
            {
                MergeResult mergeResult;
                IList <Modification> changeList = new List <Modification>();
                using (var repo = GetRepository())
                {
                    mergeResult = Commands.Pull(repo, GetSignature(), GetPullOptions());
                    result.AddMessage($"pullresult : {mergeResult.Status}");

                    if (mergeResult.Commit != null)
                    {
                        foreach (var parent in mergeResult.Commit.Parents)
                        {
                            foreach (var change in repo.Diff.Compare <TreeChanges>(parent.Tree, mergeResult.Commit.Tree))
                            {
                                changeList.Add(new Modification
                                {
                                    ChangeNumber = parent.Sha,
                                    Comment      = parent.MessageShort,
                                    FileName     = Path.GetFileName(change.Path),
                                    FolderName   = Path.GetDirectoryName(change.Path),
                                    ModifiedTime = parent.Committer.When.DateTime,
                                    EmailAddress = parent.Committer.Email,
                                    UserName     = parent.Author.Name,
                                    Type         = change.Status.ToString()
                                });
                            }
                        }
                    }
                }
                return(new Tuple <MergeResult, IList <Modification> >(mergeResult, changeList));
            });

            task.Wait();
            return(task.Result);
        }
コード例 #7
0
        public MergeResult Merge(IIntegrationResult result, string branch)
        {
            result.AddMessage($"#Merge {branch}");
            var task = Task.Run(() =>
            {
                using (var repo = GetRepository())
                {
                    return(repo.Merge(repo.Branches[branch], GetSignature(), GetMergeOptions()));
                }
            });

            task.Wait();
            return(task.Result);
        }
コード例 #8
0
        public string GitClone(IIntegrationResult result, string branch)
        {
            result.AddMessage($"#GitClone {branch}");

            var task = Task.Run(() =>
            {
                CloneOptions co        = new CloneOptions();
                co.CredentialsProvider = GetCredentialsHandler();
                co.BranchName          = branch;
                return(Repository.Clone(GitRepository, GitDirectory, co));
            });

            task.Wait();
            return(task.Result);
        }
コード例 #9
0
        private void InitProcessData(IIntegrationResult result)
        {
            result.AddMessage("#InitProcessData");
            projectName = GetGitRepositoryName();

            gitDirectory = result.BaseFromWorkingDirectory(projectName);

            var builder = new UriBuilder(GitRepository);

            builder.UserName = string.Empty;
            builder.Password = string.Empty;
            gitUrl           = builder.Uri.ToString();

            git = new GitUtil(projectName, gitDirectory, gitUrl, GitUserId, GitUserPassword);

            isFirstRun = false;
        }
コード例 #10
0
        public void Reset(IIntegrationResult result, string branch)
        {
            result.AddMessage($"#Reset {branch}");

            Checkout(result, branch);

            var task = Task.Run(() =>
            {
                using (var repo = GetRepository())
                {
                    Branch origin = repo.Branches[$"origin/{branch}"];
                    repo.Reset(ResetMode.Hard, origin.Tip);
                }
            });

            task.Wait();
        }
コード例 #11
0
 private void InitGitRepository(IIntegrationResult result)
 {
     result.AddMessage("#InitGitRepository");
     if (Directory.Exists(gitDirectory))
     {
         if (!Repository.IsValid(gitDirectory))
         {
             Directory.Delete(gitDirectory, true);
             git.GitClone(result, Branch);
             isFirstRun = true;
         }
     }
     else
     {
         git.GitClone(result, Branch);
         isFirstRun = true;
     }
 }