Ejemplo n.º 1
0
        private void RewriteMerges(IRepository repo, Dictionary <ShallowCommit, ShallowCommit> originalMerges)
        {
            int count = 0;

            this.logger.Log("0% Rewriting " + originalMerges.Keys.Count + " commits", replace: true);
            repo.Refs.RewriteHistory(new RewriteHistoryOptions {
                CommitParentsRewriter = commit =>
                {
                    this.logger.Log((100 * ++count / originalMerges.Keys.Count) + "% Rewriting commit " + commit.Sha, replace: true);
                    return(TranslateMergeParents(ShallowCommit.FromCommit(commit), originalMerges).Select(p => repo.Lookup(p.Sha) as Commit));
                }
            }, originalMerges.Keys.Select(p => repo.Lookup(p.Sha) as Commit));

            // cleanup original refs
            foreach (var @ref in repo.Refs.FromGlob("refs/original/*"))
            {
                repo.Refs.Remove(@ref);
            }
        }
Ejemplo n.º 2
0
        private ShallowCommit CherryPickCommit(IRepository repo, ShallowCommit original)
        {
            if (this.config.DryRun)
            {
                return(original);
            }

            var commit  = repo.Lookup(original.Sha) as Commit;
            var options = new CherryPickOptions();

            if (commit.Parents.Count() > 1)
            {
                options.Mainline = 1;
            }

            try
            {
                return(ShallowCommit.FromCommit(repo.CherryPick(commit, new Signature(commit.Author.Name, commit.Author.Email, commit.Author.When), options).Commit));
            }
            catch (EmptyCommitException)
            {
                return(ShallowCommit.FromCommit(this.CommitWorktree(repo, commit)));
            }
            catch (Exception e)
            {
                if (!config.Retry)
                {
                    throw;
                }

                this.logger.Log("An error occurred: \n" + e);
                this.logger.Log("Press any key after fixing conflicts manually.", true);
                Console.ReadKey();

                return(ShallowCommit.FromCommit(this.CommitWorktree(repo, commit)));
            }
        }