Example #1
0
        private int _PerformRCheckin(TfsChangesetInfo parentChangeset, string refToCheckin)
        {
            var    tfsRemote = parentChangeset.Remote;
            var    repo      = tfsRemote.Repository;
            string tfsLatest = parentChangeset.Remote.MaxCommitHash;

            RCheckinCommit rc = new RCheckinCommit(repo);

            while (true)
            {
                // determine first descendant of tfsLatest
                string revList = repo.CommandOneline("rev-list", "--parents", "--ancestry-path", "--first-parent", "--reverse", tfsLatest + ".." + refToCheckin);
                if (String.IsNullOrWhiteSpace(revList))
                {
                    _stdout.WriteLine("No more to rcheckin.");

                    Trace.WriteLine("Cleaning...");
                    tfsRemote.CleanupWorkspaceDirectory();

                    return(GitTfsExitCodes.OK);
                }

                rc.ExtractCommit(revList, tfsLatest);
                rc.BuildCommitMessage(!_checkinOptions.NoGenerateCheckinComment, tfsLatest);
                string target = rc.Sha;
                string tfsRepositoryPathOfMergedBranch = FindTfsRepositoryPathOfMergedBranch(tfsRemote, rc.Parents, target);

                var commitSpecificCheckinOptions = _checkinOptionsFactory.BuildCommitSpecificCheckinOptions(_checkinOptions, rc.Message, rc.Commit);

                _stdout.WriteLine("Starting checkin of {0} '{1}'", target.Substring(0, 8), commitSpecificCheckinOptions.CheckinComment);
                long newChangesetId = tfsRemote.Checkin(rc.Sha, parentChangeset, commitSpecificCheckinOptions, tfsRepositoryPathOfMergedBranch);
                tfsRemote.FetchWithMerge(newChangesetId, false, rc.Parents);
                if (tfsRemote.MaxChangesetId != newChangesetId)
                {
                    throw new GitTfsException("error: New TFS changesets were found. Rcheckin was not finished.");
                }

                tfsLatest       = tfsRemote.MaxCommitHash;
                parentChangeset = new TfsChangesetInfo {
                    ChangesetId = newChangesetId, GitCommit = tfsLatest, Remote = tfsRemote
                };
                _stdout.WriteLine("Done with {0}, rebasing tail onto new TFS-commit...", target);

                RebaseOnto(repo, tfsLatest, target);
                _stdout.WriteLine("Rebase done successfully.");
            }
        }
Example #2
0
        private int _PerformRCheckinQuick(TfsChangesetInfo parentChangeset, string refToCheckin)
        {
            var tfsRemote = parentChangeset.Remote;
            var repo = tfsRemote.Repository;
            string tfsLatest = parentChangeset.Remote.MaxCommitHash;

            string[] revList = null;
            repo.CommandOutputPipe(tr => revList = tr.ReadToEnd().Split('\n').Where(s => !String.IsNullOrWhiteSpace(s)).ToArray(),
                                   "rev-list", "--parents", "--ancestry-path", "--first-parent", "--reverse", tfsLatest + ".." + refToCheckin);

            string currentParent = tfsLatest;
            long newChangesetId = 0;

            RCheckinCommit rc = new RCheckinCommit(repo);

            foreach (string commitWithParents in revList)
            {
                rc.ExtractCommit(commitWithParents, currentParent);
                rc.BuildCommitMessage(!_checkinOptions.NoGenerateCheckinComment, currentParent);
                string target = rc.Sha;
                string tfsRepositoryPathOfMergedBranch = FindTfsRepositoryPathOfMergedBranch(tfsRemote, rc.Parents, target);

                var commitSpecificCheckinOptions = _checkinOptionsFactory.BuildCommitSpecificCheckinOptions(_checkinOptions, rc.Message, rc.Commit);

                _stdout.WriteLine("Starting checkin of {0} '{1}'", target.Substring(0, 8), commitSpecificCheckinOptions.CheckinComment);
                try
                {
                    newChangesetId = tfsRemote.Checkin(target, currentParent, parentChangeset, commitSpecificCheckinOptions, tfsRepositoryPathOfMergedBranch);
                    var fetchResult = tfsRemote.FetchWithMerge(newChangesetId, false, rc.Parents);
                    if (fetchResult.NewChangesetCount != 1)
                    {
                        var lastCommit = repo.FindCommitHashByChangesetId(newChangesetId);
                        RebaseOnto(repo, lastCommit, target);
                        if (AutoRebase)
                        {
                            tfsRemote.Repository.CommandNoisy("rebase", "--preserve-merges", tfsRemote.RemoteRef);
                        }
                        else
                        {
                            throw new GitTfsException("error: New TFS changesets were found. Rcheckin was not finished.");
                        }
                    }

                    currentParent = target;
                    parentChangeset = new TfsChangesetInfo {ChangesetId = newChangesetId, GitCommit = tfsRemote.MaxCommitHash, Remote = tfsRemote};
                    _stdout.WriteLine("Done with {0}.", target);
                }
                catch (Exception)
                {
                    if (newChangesetId != 0)
                    {
                        var lastCommit = repo.FindCommitHashByChangesetId(newChangesetId);
                        RebaseOnto(repo, lastCommit, currentParent);
                    }
                    throw;
                }
            }

            if (repo.IsBare)
                repo.UpdateRef(refToCheckin, tfsRemote.MaxCommitHash);
            else
                repo.Reset(tfsRemote.MaxCommitHash, ResetOptions.Hard);
            _stdout.WriteLine("No more to rcheckin.");

            Trace.WriteLine("Cleaning...");
            tfsRemote.CleanupWorkspaceDirectory();

            return GitTfsExitCodes.OK;
        }
Example #3
0
        private int _PerformRCheckin(TfsChangesetInfo parentChangeset, string refToCheckin)
        {
            var tfsRemote = parentChangeset.Remote;
            var repo = tfsRemote.Repository;
            string tfsLatest = parentChangeset.Remote.MaxCommitHash;

            RCheckinCommit rc = new RCheckinCommit(repo);

            while (true)
            {
                // determine first descendant of tfsLatest
                string revList = repo.CommandOneline("rev-list", "--parents", "--ancestry-path", "--first-parent", "--reverse", tfsLatest + ".." + refToCheckin);
                if (String.IsNullOrWhiteSpace(revList))
                {
                    _stdout.WriteLine("No more to rcheckin.");

                    Trace.WriteLine("Cleaning...");
                    tfsRemote.CleanupWorkspaceDirectory();

                    return GitTfsExitCodes.OK;
                }

                rc.ExtractCommit(revList, tfsLatest);
                rc.BuildCommitMessage(!_checkinOptions.NoGenerateCheckinComment, tfsLatest);
                string target = rc.Sha;
                string tfsRepositoryPathOfMergedBranch = FindTfsRepositoryPathOfMergedBranch(tfsRemote, rc.Parents, target);

                var commitSpecificCheckinOptions = _checkinOptionsFactory.BuildCommitSpecificCheckinOptions(_checkinOptions, rc.Message, rc.Commit);

                _stdout.WriteLine("Starting checkin of {0} '{1}'", target.Substring(0, 8), commitSpecificCheckinOptions.CheckinComment);
                long newChangesetId = tfsRemote.Checkin(rc.Sha, parentChangeset, commitSpecificCheckinOptions, tfsRepositoryPathOfMergedBranch);
                tfsRemote.FetchWithMerge(newChangesetId, false, rc.Parents);
                if (tfsRemote.MaxChangesetId != newChangesetId)
                    throw new GitTfsException("error: New TFS changesets were found. Rcheckin was not finished.");

                tfsLatest = tfsRemote.MaxCommitHash;
                parentChangeset = new TfsChangesetInfo {ChangesetId = newChangesetId, GitCommit = tfsLatest, Remote = tfsRemote};
                _stdout.WriteLine("Done with {0}, rebasing tail onto new TFS-commit...", target);

                RebaseOnto(repo, tfsLatest, target);
                _stdout.WriteLine("Rebase done successfully.");
            }
        }
Example #4
0
        private int _PerformRCheckinQuick(TfsChangesetInfo parentChangeset, string refToCheckin)
        {
            var    tfsRemote = parentChangeset.Remote;
            var    repo      = tfsRemote.Repository;
            string tfsLatest = parentChangeset.Remote.MaxCommitHash;

            string[] revList = null;
            repo.CommandOutputPipe(tr => revList = tr.ReadToEnd().Split('\n').Where(s => !String.IsNullOrWhiteSpace(s)).ToArray(),
                                   "rev-list", "--parents", "--ancestry-path", "--first-parent", "--reverse", tfsLatest + ".." + refToCheckin);

            string currentParent  = tfsLatest;
            long   newChangesetId = 0;

            RCheckinCommit rc = new RCheckinCommit(repo);

            foreach (string commitWithParents in revList)
            {
                rc.ExtractCommit(commitWithParents, currentParent);
                rc.BuildCommitMessage(!_checkinOptions.NoGenerateCheckinComment, currentParent);
                string target = rc.Sha;
                string tfsRepositoryPathOfMergedBranch = FindTfsRepositoryPathOfMergedBranch(tfsRemote, rc.Parents, target);

                var commitSpecificCheckinOptions = _checkinOptionsFactory.BuildCommitSpecificCheckinOptions(_checkinOptions, rc.Message, rc.Commit);

                _stdout.WriteLine("Starting checkin of {0} '{1}'", target.Substring(0, 8), commitSpecificCheckinOptions.CheckinComment);
                try
                {
                    newChangesetId = tfsRemote.Checkin(target, currentParent, parentChangeset, commitSpecificCheckinOptions, tfsRepositoryPathOfMergedBranch);
                    var fetchResult = tfsRemote.FetchWithMerge(newChangesetId, false, rc.Parents);
                    if (fetchResult.NewChangesetCount != 1)
                    {
                        var lastCommit = repo.FindCommitHashByChangesetId(newChangesetId);
                        RebaseOnto(repo, lastCommit, target);
                        if (AutoRebase)
                        {
                            tfsRemote.Repository.CommandNoisy("rebase", "--preserve-merges", tfsRemote.RemoteRef);
                        }
                        else
                        {
                            throw new GitTfsException("error: New TFS changesets were found. Rcheckin was not finished.");
                        }
                    }

                    currentParent   = target;
                    parentChangeset = new TfsChangesetInfo {
                        ChangesetId = newChangesetId, GitCommit = tfsRemote.MaxCommitHash, Remote = tfsRemote
                    };
                    _stdout.WriteLine("Done with {0}.", target);
                }
                catch (Exception)
                {
                    if (newChangesetId != 0)
                    {
                        var lastCommit = repo.FindCommitHashByChangesetId(newChangesetId);
                        RebaseOnto(repo, lastCommit, currentParent);
                    }
                    throw;
                }
            }

            if (repo.IsBare)
            {
                repo.UpdateRef(refToCheckin, tfsRemote.MaxCommitHash);
            }
            else
            {
                repo.ResetHard(tfsRemote.MaxCommitHash);
            }
            _stdout.WriteLine("No more to rcheckin.");

            Trace.WriteLine("Cleaning...");
            tfsRemote.CleanupWorkspaceDirectory();

            return(GitTfsExitCodes.OK);
        }