Ejemplo n.º 1
0
 private void PendChangesToWorkspace(string head, TfsChangesetInfo parentChangeset, ITfsWorkspace workspace)
 {
     foreach (var change in Repository.GetChangedFiles(parentChangeset.GitCommit, head))
     {
         change.Apply(workspace);
     }
 }
Ejemplo n.º 2
0
        public int Checkin(string head, string parent, TfsChangesetInfo parentChangeset, CheckinOptions options, string sourceTfsPath = null)
        {
            var changeset = 0;

            WithWorkspace(parentChangeset, workspace => changeset = Checkin(head, parent, workspace, options, sourceTfsPath));
            return(changeset);
        }
Ejemplo n.º 3
0
        public IGitTfsRemote CreateRemote(TfsChangesetInfo changeset)
        {
            IGitTfsRemote remote;

            if (changeset.Remote.IsDerived)
            {
                var remoteId = GetRemoteId(changeset);
                remote = _globals.Repository.CreateTfsRemote(new RemoteInfo
                {
                    Id            = remoteId,
                    Url           = changeset.Remote.TfsUrl,
                    Repository    = changeset.Remote.TfsRepositoryPath,
                    RemoteOptions = _remoteOptions,
                }, string.Empty);
                remote.UpdateTfsHead(changeset.GitCommit, changeset.ChangesetId);
                Trace.TraceInformation("-> new remote '" + remote.Id + "'");
            }
            else
            {
                remote = changeset.Remote;
                if (changeset.Remote.MaxChangesetId < changeset.ChangesetId)
                {
                    int oldChangeset = changeset.Remote.MaxChangesetId;
                    _globals.Repository.MoveTfsRefForwardIfNeeded(changeset.Remote);
                    Trace.TraceInformation("-> existing remote {0} (updated from changeset {1})", changeset.Remote.Id, oldChangeset);
                }
                else
                {
                    Trace.TraceInformation("-> existing remote {0} (up to date)", changeset.Remote.Id);
                }
            }
            return(remote);
        }
Ejemplo n.º 4
0
        public long Checkin(string head, string parent, TfsChangesetInfo parentChangeset, CheckinOptions options)
        {
            var changeset = 0L;

            WithWorkspace(parentChangeset, workspace => changeset = Checkin(head, parent, workspace, options));
            return(changeset);
        }
Ejemplo n.º 5
0
        private string GetRemoteId(TfsChangesetInfo changeset)
        {
            if (IsAvailable(GitTfsConstants.DefaultRepositoryId))
            {
                Trace.TraceInformation("info: '" + changeset.Remote.TfsRepositoryPath + "' will be bootstraped as your main remote...");
                return(GitTfsConstants.DefaultRepositoryId);
            }

            //Remove '$/'!
            var expectedRemoteId = changeset.Remote.TfsRepositoryPath.Substring(2).Trim('/');
            var indexOfSlash     = expectedRemoteId.IndexOf('/');

            if (indexOfSlash != 0)
            {
                expectedRemoteId = expectedRemoteId.Substring(indexOfSlash + 1);
            }
            var remoteId = expectedRemoteId.ToGitRefName();
            var suffix   = 0;

            while (!IsAvailable(remoteId))
            {
                remoteId = expectedRemoteId + "-" + (suffix++);
            }
            return(remoteId);
        }
Ejemplo n.º 6
0
        public int CheckinTool(string head, TfsChangesetInfo parentChangeset)
        {
            var changeset = 0;

            WithWorkspace(parentChangeset, workspace => changeset = CheckinTool(head, parentChangeset, workspace));
            return(changeset);
        }
Ejemplo n.º 7
0
 public IGitTfsRemote CreateRemote(TfsChangesetInfo changeset)
 {
     IGitTfsRemote remote;
     if (changeset.Remote.IsDerived)
     {
         var remoteId = GetRemoteId(changeset);
         remote = _globals.Repository.CreateTfsRemote(new RemoteInfo
             {
                 Id = remoteId,
                 Url = changeset.Remote.TfsUrl,
                 Repository = changeset.Remote.TfsRepositoryPath,
                 RemoteOptions = _remoteOptions,
             }, string.Empty);
         remote.UpdateTfsHead(changeset.GitCommit, changeset.ChangesetId);
         _stdout.WriteLine("-> new remote '" + remote.Id + "'");
     }
     else
     {
         remote = changeset.Remote;
         if (changeset.Remote.MaxChangesetId < changeset.ChangesetId)
         {
             int oldChangeset = changeset.Remote.MaxChangesetId;
             _globals.Repository.MoveTfsRefForwardIfNeeded(changeset.Remote);
             _stdout.WriteLine("-> existing remote {0} (updated from changeset {1})", changeset.Remote.Id, oldChangeset);
         }
         else
         {
             _stdout.WriteLine("-> existing remote {0} (up to date)", changeset.Remote.Id);
         }
     }
     return remote;
 }
Ejemplo n.º 8
0
        public long Checkin(string head, TfsChangesetInfo parentChangeset, CheckinOptions options)
        {
            var changeset = 0L;

            Tfs.WithWorkspace(WorkingDirectory, this, parentChangeset,
                              workspace => changeset = Checkin(head, parentChangeset.GitCommit, workspace, options));
            return(changeset);
        }
Ejemplo n.º 9
0
        public long Checkin(string head, TfsChangesetInfo parentChangeset)
        {
            var changeset = 0L;

            Tfs.WithWorkspace(WorkingDirectory, this, parentChangeset,
                              workspace => changeset = Checkin(head, parentChangeset, workspace));
            return(changeset);
        }
Ejemplo n.º 10
0
 public TfsWorkspace(Workspace workspace, string localDirectory, TextWriter stdout, TfsChangesetInfo contextVersion, IGitTfsRemote remote)
 {
     _workspace = workspace;
     _contextVersion = contextVersion;
     _remote = remote;
     _localDirectory = localDirectory;
     _stdout = stdout;
 }
Ejemplo n.º 11
0
        protected override long DoCheckin(TfsChangesetInfo changeset, string refToCheckin)
        {
            if (!changeset.Remote.Tfs.CanPerformGatedCheckin && _checkinOptions.QueueBuildForGatedCheckIn)
                throw new GitTfsException(
                    "gated checkin does not work with this TFS version (" + changeset.Remote.Tfs.TfsClientLibraryVersion + ").",
                    new[] { "Try installing the VS2010 edition of Team Explorer." });

            return changeset.Remote.Checkin(refToCheckin, changeset);
        }
Ejemplo n.º 12
0
        protected override int DoCheckin(TfsChangesetInfo changeset, string refToCheckin)
        {
            if (!changeset.Remote.Tfs.CanShowCheckinDialog)
                throw new GitTfsException(
                    "checkintool does not work with this TFS version (" + changeset.Remote.Tfs.TfsClientLibraryVersion + ").",
                    new[] { "Try installing the VS2010 edition of Team Explorer." });

            return changeset.Remote.CheckinTool(refToCheckin, changeset);
        }
Ejemplo n.º 13
0
        public void ShouldFailWithMoreThanOneParents()
        {
            mocks.Get<Globals>().Repository = mocks.Get<IGitRepository>();
            var parentChangesets = new TfsChangesetInfo() {Remote = mocks.Get<IGitTfsRemote>()};
            mocks.Get<IGitRepository>().Stub(x => x.GetParentTfsCommits("my-head"))
                .Return(new[] {parentChangesets, parentChangesets});

            Assert.AreNotEqual(GitTfsExitCodes.OK, mocks.ClassUnderTest.MakeArgsAndRun("don't care", "my-head"));
        }
Ejemplo n.º 14
0
        private int PerformRCheckin(TfsChangesetInfo parentChangeset)
        {
            var tfsRemote = parentChangeset.Remote;
            var repo = tfsRemote.Repository;
            if (repo.WorkingCopyHasUnstagedOrUncommitedChanges)
            {
                throw new GitTfsException("error: You have local changes; rebase-workflow checkin only possible with clean working directory.")
                    .WithRecommendation("Try 'git stash' to stash your local changes and checkin again.");
            }

            // get latest changes from TFS to minimize possibility of late conflict
            _stdout.WriteLine("Fetching changes from TFS to minimize possibility of late conflict...");
            parentChangeset.Remote.Fetch();
            if (parentChangeset.ChangesetId != parentChangeset.Remote.MaxChangesetId)
            {
                throw new GitTfsException("error: New TFS changesets were found.")
                    .WithRecommendation("Try to rebase HEAD onto latest TFS checkin and repeat rcheckin or alternatively checkin s");
            }

            string tfsLatest = parentChangeset.Remote.MaxCommitHash;

            // we could rcheckin only if tfsLatest changeset is a parent of HEAD
            // so that we could rebase after each single checkin without conflicts
            if (!String.IsNullOrWhiteSpace(repo.CommandOneline("rev-list", tfsLatest, "^HEAD")))
                throw new GitTfsException("error: latest TFS commit should be parent of commits being checked in");

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

                string[] strs = revList.Split(' ');
                string target = strs[0];
                string[] gitParents = strs.AsEnumerable().Skip(1).Where(hash => hash != tfsLatest).ToArray();

                string commitMessage = repo.GetCommitMessage(target, tfsLatest).Trim(' ', '\r', '\n');
                _stdout.WriteLine("Starting checkin of {0} '{1}'", target, commitMessage);
                _checkinOptions.CheckinComment = commitMessage;
                long newChangesetId = tfsRemote.Checkin(target, parentChangeset);
                tfsRemote.FetchWithMerge(newChangesetId, gitParents);
                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);

                repo.CommandNoisy("rebase", "--preserve-merges", "--onto", tfsLatest, target);
                _stdout.WriteLine("Rebase done successfully.");
            }
        }
Ejemplo n.º 15
0
 public TfsWorkspace(IWorkspace workspace, string localDirectory, TextWriter stdout, TfsChangesetInfo contextVersion, IGitTfsRemote remote, CheckinOptions checkinOptions, ITfsHelper tfsHelper)
 {
     _workspace = workspace;
     _contextVersion = contextVersion;
     _remote = remote;
     _checkinOptions = checkinOptions;
     _tfsHelper = tfsHelper;
     _localDirectory = localDirectory;
     _stdout = stdout;
 }
Ejemplo n.º 16
0
        private void WithWorkspace(TfsChangesetInfo parentChangeset, Action <ITfsWorkspace> action)
        {
            // If there isn't a custom workspace, and a workspace is lingering from a previous
            // git-tfs run, clean it up. If the user is using a custom workspace dir, leave
            // it for them to explicitly clean up, in case they're doing something unsupported
            // with it.
            Tfs.CleanupWorkspaces(DefaultWorkingDirectory);

            Tfs.WithWorkspace(WorkingDirectory, this, parentChangeset, action);
        }
Ejemplo n.º 17
0
        public TfsWorkspace(IWorkspace workspace, string localDirectory, TfsChangesetInfo contextVersion, IGitTfsRemote remote, CheckinOptions checkinOptions, ITfsHelper tfsHelper, CheckinPolicyEvaluator policyEvaluator)
        {
            _workspace       = workspace;
            _policyEvaluator = policyEvaluator;
            _contextVersion  = contextVersion;
            _checkinOptions  = checkinOptions;
            _tfsHelper       = tfsHelper;
            _localDirectory  = remote.Repository.IsBare ? Path.GetFullPath(localDirectory) : localDirectory;

            this.Remote = remote;
        }
Ejemplo n.º 18
0
 public TfsWorkspace(IWorkspace workspace, string localDirectory, TextWriter stdout, TfsChangesetInfo contextVersion, IGitTfsRemote remote, CheckinOptions checkinOptions, ITfsHelper tfsHelper, CheckinPolicyEvaluator policyEvaluator)
 {
     _workspace       = workspace;
     _policyEvaluator = policyEvaluator;
     _contextVersion  = contextVersion;
     _remote          = remote;
     _checkinOptions  = checkinOptions;
     _tfsHelper       = tfsHelper;
     _localDirectory  = localDirectory;
     _stdout          = stdout;
 }
Ejemplo n.º 19
0
        private string GetRemoteId(TfsChangesetInfo parent)
        {
            if (IsAvailable(GitTfsConstants.DefaultRepositoryId))
                return GitTfsConstants.DefaultRepositoryId;

            var hostname = new Uri(parent.Remote.TfsUrl).Host.Replace(".", "-");
            var remoteId = hostname;
            var suffix = 0;
            while (!IsAvailable(remoteId))
                remoteId = hostname + "-" + (suffix++);
            return remoteId;
        }
Ejemplo n.º 20
0
        private void WithWorkspace(TfsChangesetInfo parentChangeset, Action <ITfsWorkspace> action)
        {
            //are there any subtrees?
            var subtrees = globals.Repository.GetSubtrees(this);

            if (subtrees.Any())
            {
                Tfs.WithWorkspace(WorkingDirectory, this, subtrees.Select(x => new Tuple <string, string>(x.TfsRepositoryPath, x.Prefix)), parentChangeset, action);
            }
            else
            {
                Tfs.WithWorkspace(WorkingDirectory, this, parentChangeset, action);
            }
        }
Ejemplo n.º 21
0
        private int PerformCheckin(TfsChangesetInfo parentChangeset, string refToCheckin)
        {
            var newChangesetId = DoCheckin(parentChangeset, refToCheckin);

            if (_checkinOptions.NoMerge)
            {
                _stdout.WriteLine("TFS Changeset #" + newChangesetId + " was created.");
                parentChangeset.Remote.Fetch();
            }
            else
            {
                _stdout.WriteLine("TFS Changeset #" + newChangesetId + " was created. Marking it as a merge commit...");
                parentChangeset.Remote.FetchWithMerge(newChangesetId, refToCheckin);

                if (refToCheckin == "HEAD")
                    parentChangeset.Remote.Repository.CommandNoisy("merge", parentChangeset.Remote.MaxCommitHash);
            }
            return GitTfsExitCodes.OK;
        }
Ejemplo n.º 22
0
        private string GetRemoteId(TfsChangesetInfo changeset)
        {
            if (IsAvailable(GitTfsConstants.DefaultRepositoryId))
            {
                _stdout.WriteLine("info: '" + changeset.Remote.TfsRepositoryPath + "' will be bootstraped as your main remote...");
                return GitTfsConstants.DefaultRepositoryId;
            }

            //Remove '$/'!
            var expectedRemoteId = changeset.Remote.TfsRepositoryPath.Substring(2).Trim('/');
            var indexOfSlash = expectedRemoteId.IndexOf('/');
            if (indexOfSlash != 0)
                expectedRemoteId = expectedRemoteId.Substring(indexOfSlash + 1);
            var remoteId = expectedRemoteId.ToGitRefName();
            var suffix = 0;
            while (!IsAvailable(remoteId))
                remoteId = expectedRemoteId + "-" + (suffix++);
            return remoteId;
        }
Ejemplo n.º 23
0
        private int PerformRCheckin(TfsChangesetInfo parentChangeset, string refToCheckin)
        {
            if (_globals.Repository.IsBare)
                AutoRebase = false;

            if (_globals.Repository.WorkingCopyHasUnstagedOrUncommitedChanges)
            {
                throw new GitTfsException("error: You have local changes; rebase-workflow checkin only possible with clean working directory.")
                    .WithRecommendation("Try 'git stash' to stash your local changes and checkin again.");
            }

            // get latest changes from TFS to minimize possibility of late conflict
            _stdout.WriteLine("Fetching changes from TFS to minimize possibility of late conflict...");
            parentChangeset.Remote.Fetch();
            if (parentChangeset.ChangesetId != parentChangeset.Remote.MaxChangesetId)
            {
                if (AutoRebase)
                {
                    _globals.Repository.CommandNoisy("rebase", "--preserve-merges", parentChangeset.Remote.RemoteRef);
                    parentChangeset = _globals.Repository.GetTfsCommit(parentChangeset.Remote.MaxCommitHash);
                }
                else
                {
                    if (_globals.Repository.IsBare)
                        _globals.Repository.UpdateRef(refToCheckin, parentChangeset.Remote.MaxCommitHash);

                    throw new GitTfsException("error: New TFS changesets were found.")
                        .WithRecommendation("Try to rebase HEAD onto latest TFS checkin and repeat rcheckin or alternatively checkins");
                }
            }

            IEnumerable<GitCommit> commitsToCheckin = _globals.Repository.FindParentCommits(refToCheckin, parentChangeset.Remote.MaxCommitHash);
            Trace.WriteLine("Commit to checkin count:" + commitsToCheckin.Count());
            if (!commitsToCheckin.Any())
                throw new GitTfsException("error: latest TFS commit should be parent of commits being checked in");

            SetupMetadataExport(parentChangeset.Remote);

            return _PerformRCheckinQuick(parentChangeset, refToCheckin, commitsToCheckin);
        }
Ejemplo n.º 24
0
        private int PerformRCheckin(TfsChangesetInfo parentChangeset, string refToCheckin)
        {
            if (_globals.Repository.IsBare)
                AutoRebase = false;

            if (_globals.Repository.WorkingCopyHasUnstagedOrUncommitedChanges)
            {
                throw new GitTfsException("error: You have local changes; rebase-workflow checkin only possible with clean working directory.")
                    .WithRecommendation("Try 'git stash' to stash your local changes and checkin again.");
            }

            // get latest changes from TFS to minimize possibility of late conflict
            _stdout.WriteLine("Fetching changes from TFS to minimize possibility of late conflict...");
            parentChangeset.Remote.Fetch();
            if (parentChangeset.ChangesetId != parentChangeset.Remote.MaxChangesetId)
            {
                if (!Old && AutoRebase)
                {
                    _globals.Repository.CommandNoisy("rebase", "--preserve-merges", parentChangeset.Remote.RemoteRef);
                    parentChangeset = _globals.Repository.GetTfsCommit(parentChangeset.Remote.MaxCommitHash);
                }
                else
                {
                    if (_globals.Repository.IsBare)
                        _globals.Repository.UpdateRef(refToCheckin, parentChangeset.Remote.MaxCommitHash);

                    throw new GitTfsException("error: New TFS changesets were found.")
                        .WithRecommendation("Try to rebase HEAD onto latest TFS checkin and repeat rcheckin or alternatively checkin s");
                }
            }

            string tfsLatest = parentChangeset.Remote.MaxCommitHash;

            // we could rcheckin only if tfsLatest changeset is a parent of HEAD
            // so that we could rebase after each single checkin without conflicts
            if (!String.IsNullOrWhiteSpace(_globals.Repository.CommandOneline("rev-list", tfsLatest, "^" + refToCheckin)))
                throw new GitTfsException("error: latest TFS commit should be parent of commits being checked in");

            return (!Old || _globals.Repository.IsBare) ? _PerformRCheckinQuick(parentChangeset, refToCheckin) : _PerformRCheckin(parentChangeset, refToCheckin);
        }
Ejemplo n.º 25
0
        private int PerformCheckin(TfsChangesetInfo parentChangeset, string refToCheckin)
        {
            var newChangesetId = DoCheckin(parentChangeset, refToCheckin);

            if (_checkinOptions.NoMerge)
            {
                _stdout.WriteLine("TFS Changeset #" + newChangesetId + " was created.");
                parentChangeset.Remote.Fetch();
            }
            else
            {
                _stdout.WriteLine("TFS Changeset #" + newChangesetId + " was created. Marking it as a merge commit...");
                parentChangeset.Remote.FetchWithMerge(newChangesetId, false, refToCheckin);

                if (refToCheckin == "HEAD")
                    parentChangeset.Remote.Repository.Merge(parentChangeset.Remote.MaxCommitHash);
            }

            Trace.WriteLine("Cleaning...");
            parentChangeset.Remote.CleanupWorkspaceDirectory();

            return GitTfsExitCodes.OK;
        }
Ejemplo n.º 26
0
        public int Verify(TfsChangesetInfo changeset, bool ignorePathCaseMismatch)
        {
            Trace.TraceInformation("Comparing TFS changeset " + changeset.ChangesetId + " to git commit " + changeset.GitCommit);
            var tfsTree = changeset.Remote.GetChangeset(changeset.ChangesetId).GetTree().ToDictionary(entry => entry.FullName.ToLowerInvariant().Replace("/", @"\"));
            var gitTree = changeset.Remote.Repository.GetCommit(changeset.GitCommit).GetTree().ToDictionary(entry => entry.Entry.Path.ToLowerInvariant());

            var all = tfsTree.Keys.Union(gitTree.Keys);
            var inBoth = tfsTree.Keys.Intersect(gitTree.Keys);
            var tfsOnly = tfsTree.Keys.Except(gitTree.Keys);
            var gitOnly = gitTree.Keys.Except(tfsTree.Keys);

            var foundDiff = GitTfsExitCodes.OK;
            foreach (var file in all.OrderBy(x => x))
            {
                if (tfsTree.ContainsKey(file))
                {
                    if (gitTree.ContainsKey(file))
                    {
                        if (Compare(tfsTree[file], gitTree[file], ignorePathCaseMismatch))
                            foundDiff = Math.Max(foundDiff, GitTfsExitCodes.VerifyContentMismatch);
                    }
                    else
                    {
                        Trace.TraceInformation("Only in TFS: " + tfsTree[file].FullName);
                        foundDiff = Math.Max(foundDiff, GitTfsExitCodes.VerifyFileMissing);
                    }
                }
                else
                {
                    Trace.TraceInformation("Only in git: " + gitTree[file].FullName);
                    foundDiff = Math.Max(foundDiff, GitTfsExitCodes.VerifyFileMissing);
                }
            }
            if (foundDiff == GitTfsExitCodes.OK)
                Trace.TraceInformation("No differences!");
            return foundDiff;
        }
Ejemplo n.º 27
0
        private void FindTfsCommits(TextReader stdout, ICollection <TfsChangesetInfo> tfsCommits, bool includeStubRemotes)
        {
            string           currentCommit     = null;
            TfsChangesetInfo lastChangesetInfo = null;
            string           line;

            while (null != (line = stdout.ReadLine()))
            {
                var match = GitTfsConstants.CommitRegex.Match(line);
                if (match.Success)
                {
                    if (lastChangesetInfo != null)
                    {
                        tfsCommits.Add(lastChangesetInfo);
                        lastChangesetInfo = null;
                    }

                    currentCommit = match.Groups[1].Value;
                    continue;
                }

                var changesetInfo = TryParseChangesetInfo(line, currentCommit, includeStubRemotes);
                if (changesetInfo != null)
                {
                    lastChangesetInfo = changesetInfo;
                }
            }

            // Add the final changesetinfo object; it won't be handled in the loop
            // if it was part of the last commit message.
            if (lastChangesetInfo != null)
            {
                tfsCommits.Add(lastChangesetInfo);
            }

            //stdout.Close();
        }
Ejemplo n.º 28
0
        public void Verify(TfsChangesetInfo changeset)
        {
            _stdout.WriteLine("Comparing TFS changeset " + changeset.ChangesetId + " to git commit " + changeset.GitCommit);
            var tfsTree = changeset.Remote.GetChangeset(changeset.ChangesetId).GetTree().ToDictionary(entry => entry.FullName.ToLowerInvariant().Replace("/",@"\"));
            var gitTree = changeset.Remote.Repository.GetCommit(changeset.GitCommit).GetTree().ToDictionary(entry => entry.Entry.Path.ToLowerInvariant());

            var all = tfsTree.Keys.Union(gitTree.Keys);
            var inBoth = tfsTree.Keys.Intersect(gitTree.Keys);
            var tfsOnly = tfsTree.Keys.Except(gitTree.Keys);
            var gitOnly = gitTree.Keys.Except(tfsTree.Keys);

            var foundDiff = false;
            foreach(var file in all.OrderBy(x => x))
            {
                if(tfsTree.ContainsKey(file))
                {
                    if(gitTree.ContainsKey(file))
                    {
                        if (Compare(tfsTree[file], gitTree[file]))
                            foundDiff = true;
                    }
                    else
                    {
                        _stdout.WriteLine("Only in TFS: " + tfsTree[file].FullName);
                        foundDiff = true;
                    }
                }
                else
                {
                    _stdout.WriteLine("Only in git: " + gitTree[file].FullName);
                    foundDiff = true;
                }
            }
            if(!foundDiff)
                _stdout.WriteLine("No differences!");
        }
Ejemplo n.º 29
0
 public long CheckinTool(string head, TfsChangesetInfo parentChangeset)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 30
0
 public int CheckinTool(string head, TfsChangesetInfo parentChangeset)
 {
     throw DerivedRemoteException;
 }
Ejemplo n.º 31
0
 public void Shelve(string shelvesetName, string head, TfsChangesetInfo parentChangeset, bool evaluateCheckinPolicies)
 {
     Tfs.WithWorkspace(WorkingDirectory, this, parentChangeset,
                       workspace => Shelve(shelvesetName, head, parentChangeset, evaluateCheckinPolicies, workspace));
 }
Ejemplo n.º 32
0
 private void Shelve(string shelvesetName, string head, TfsChangesetInfo parentChangeset, bool evaluateCheckinPolicies, ITfsWorkspace workspace)
 {
     PendChangesToWorkspace(head, parentChangeset.GitCommit, workspace);
     workspace.Shelve(shelvesetName, evaluateCheckinPolicies, () => Repository.GetCommitMessage(head, parentChangeset.GitCommit));
 }
Ejemplo n.º 33
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.");
            }
        }
Ejemplo n.º 34
0
 public long Checkin(string head, string parent, TfsChangesetInfo parentChangeset, CheckinOptions options)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 35
0
 private void WithWorkspace(TfsChangesetInfo parentChangeset, Action<ITfsWorkspace> action)
 {
     //are there any subtrees?
     var subtrees = globals.Repository.GetSubtrees(this);
     if (subtrees.Any())
     {
         Tfs.WithWorkspace(WorkingDirectory, this, subtrees.Select(x => new Tuple<string, string>(x.TfsRepositoryPath, x.Prefix)), parentChangeset, action);
     }
     else
     {
         Tfs.WithWorkspace(WorkingDirectory, this, parentChangeset, action);
     }
 }
Ejemplo n.º 36
0
 public int CheckinTool(string head, TfsChangesetInfo parentChangeset)
 {
     var changeset = 0;
     WithWorkspace(parentChangeset, workspace => changeset = CheckinTool(head, parentChangeset, workspace));
     return changeset;
 }
Ejemplo n.º 37
0
 public void CreateTfsRemote(string remoteId, TfsChangesetInfo tfsHead, RemoteOptions remoteOptions)
 {
     CreateTfsRemote(remoteId, tfsHead.Remote.TfsUrl, tfsHead.Remote.TfsRepositoryPath, remoteOptions);
     ReadTfsRemote(remoteId).UpdateRef(tfsHead.GitCommit, tfsHead.ChangesetId);
 }
Ejemplo n.º 38
0
 public void Shelve(string shelvesetName, string treeish, TfsChangesetInfo parentChangeset, CheckinOptions options, bool evaluateCheckinPolicies)
 {
     throw DerivedRemoteException;
 }
Ejemplo n.º 39
0
 public long Checkin(string head, string parent, TfsChangesetInfo parentChangeset, CheckinOptions options, string sourceTfsPath = null)
 {
     throw DerivedRemoteException;
 }
Ejemplo n.º 40
0
 public long CheckinTool(string head, TfsChangesetInfo parentChangeset)
 {
     throw DerivedRemoteException;
 }
Ejemplo n.º 41
0
 public void Shelve(string shelvesetName, string treeish, TfsChangesetInfo parentChangeset, bool evaluateCheckinPolicies)
 {
     throw DerivedRemoteException;
 }
Ejemplo n.º 42
0
 private long Checkin(string head, TfsChangesetInfo parentChangeset, ITfsWorkspace workspace)
 {
     PendChangesToWorkspace(head, parentChangeset, workspace);
     return(workspace.Checkin());
 }
Ejemplo n.º 43
0
 protected abstract int DoCheckin(TfsChangesetInfo changeset, string refToCheckin);
Ejemplo n.º 44
0
 public void WithWorkspace(string directory, IGitTfsRemote remote, TfsChangesetInfo versionToFetch, Action<ITfsWorkspace> action)
 {
     Trace.WriteLine("Setting up a TFS workspace at " + directory);
     var fakeWorkspace = new FakeWorkspace(directory, remote.TfsRepositoryPath);
     var workspace = _container.With("localDirectory").EqualTo(directory)
         .With("remote").EqualTo(remote)
         .With("contextVersion").EqualTo(versionToFetch)
         .With("workspace").EqualTo(fakeWorkspace)
         .With("tfsHelper").EqualTo(this)
         .GetInstance<TfsWorkspace>();
     action(workspace);
 }
Ejemplo n.º 45
0
 public long Checkin(string treeish, TfsChangesetInfo parentChangeset, CheckinOptions options, string sourceTfsPath = null)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 46
0
 public int Checkin(string head, string parent, TfsChangesetInfo parentChangeset, CheckinOptions options, string sourceTfsPath = null)
 {
     var changeset = 0;
     WithWorkspace(parentChangeset, workspace => changeset = Checkin(head, parent, workspace, options, sourceTfsPath));
     return changeset;
 }
Ejemplo n.º 47
0
 public long Checkin(string treeish, TfsChangesetInfo parentChangeset)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 48
0
        private int PerformRCheckin(TfsChangesetInfo parentChangeset)
        {
            var tfsRemote = parentChangeset.Remote;
            var repo = tfsRemote.Repository;

            if (repo.WorkingCopyHasUnstagedOrUncommitedChanges)
            {
                throw new GitTfsException("error: You have local changes; rebase-workflow checkin only possible with clean working directory.")
                    .WithRecommendation("Try 'git stash' to stash your local changes and checkin again.");
            }

            // get latest changes from TFS to minimize possibility of late conflict
            _stdout.WriteLine("Fetching changes from TFS to minimize possibility of late conflict...");
            parentChangeset.Remote.Fetch();
            if (parentChangeset.ChangesetId != parentChangeset.Remote.MaxChangesetId)
            {
                if (Quick && AutoRebase)
                {
                    tfsRemote.Repository.CommandNoisy("rebase", "--preserve-merges", tfsRemote.RemoteRef);
                }
                else
                {
                    throw new GitTfsException("error: New TFS changesets were found.")
                        .WithRecommendation("Try to rebase HEAD onto latest TFS checkin and repeat rcheckin or alternatively checkin s");
                }
            }

            string tfsLatest = parentChangeset.Remote.MaxCommitHash;

            // we could rcheckin only if tfsLatest changeset is a parent of HEAD
            // so that we could rebase after each single checkin without conflicts
            if (!String.IsNullOrWhiteSpace(repo.CommandOneline("rev-list", tfsLatest, "^HEAD")))
                throw new GitTfsException("error: latest TFS commit should be parent of commits being checked in");

            if (Quick)
            {
                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 + "..HEAD");

                string currentParent = tfsLatest;
                long newChangesetId = 0;
                foreach (string commitWithParents in revList)
                {
                    string[] strs = commitWithParents.Split(' ');
                    string target = strs[0];
                    string[] gitParents = strs.AsEnumerable().Skip(1).Where(hash => hash != currentParent).ToArray();

                    string commitMessage = _checkinOptions.NoGenerateCheckinComment
                                               ? repo.GetCommitMessage(target)
                                               : repo.GetCommitMessage(target, currentParent);
                    var commitSpecificCheckinOptions = _checkinOptionsFactory.BuildCommitSpecificCheckinOptions(_checkinOptions, commitMessage);

                    _stdout.WriteLine("Starting checkin of {0} '{1}'", target.Substring(0, 8), commitSpecificCheckinOptions.CheckinComment);
                    try
                    {
                        newChangesetId = tfsRemote.Checkin(target, currentParent, parentChangeset, commitSpecificCheckinOptions);
                        tfsRemote.FetchWithMerge(newChangesetId, gitParents);
                        if (tfsRemote.MaxChangesetId != newChangesetId)
                        {
                            var lastCommit = repo.FindCommitHashByCommitMessage("git-tfs-id: .*;C" + newChangesetId + "[^0-9]");
                            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.FindCommitHashByCommitMessage("git-tfs-id: .*;C" + newChangesetId + "[^0-9]");
                            RebaseOnto(repo, lastCommit, currentParent);
                        }
                        throw;
                    }
                }

                repo.Reset(tfsRemote.MaxCommitHash, ResetOptions.Hard);
                _stdout.WriteLine("No more to rcheckin.");
                return GitTfsExitCodes.OK;
            }
            else
            {
                while (true)
                {
                    // determine first descendant of tfsLatest
                    string revList = repo.CommandOneline("rev-list", "--parents", "--ancestry-path", "--first-parent", "--reverse", tfsLatest + "..HEAD");
                    if (String.IsNullOrWhiteSpace(revList))
                    {
                        _stdout.WriteLine("No more to rcheckin.");
                        return GitTfsExitCodes.OK;
                    }

                    string[] strs = revList.Split(' ');
                    string target = strs[0];
                    string[] gitParents = strs.AsEnumerable().Skip(1).Where(hash => hash != tfsLatest).ToArray();

                    string commitMessage = _checkinOptions.NoGenerateCheckinComment
                        ? repo.GetCommitMessage(target)
                        : repo.GetCommitMessage(target, tfsLatest);
                    var commitSpecificCheckinOptions = _checkinOptionsFactory.BuildCommitSpecificCheckinOptions(_checkinOptions, commitMessage);
                    _stdout.WriteLine("Starting checkin of {0} '{1}'", target.Substring(0, 8), commitSpecificCheckinOptions.CheckinComment);
                    long newChangesetId = tfsRemote.Checkin(target, parentChangeset, commitSpecificCheckinOptions);
                    tfsRemote.FetchWithMerge(newChangesetId, gitParents);
                    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.");
                }
            }
        }
Ejemplo n.º 49
0
 public void Shelve(string shelvesetName, string head, TfsChangesetInfo parentChangeset, bool evaluateCheckinPolicies)
 {
     WithWorkspace(parentChangeset, workspace => Shelve(shelvesetName, head, parentChangeset, evaluateCheckinPolicies, workspace));
 }
Ejemplo n.º 50
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;
        }
Ejemplo n.º 51
0
 private void Shelve(string shelvesetName, string head, TfsChangesetInfo parentChangeset, bool evaluateCheckinPolicies, ITfsWorkspace workspace)
 {
     PendChangesToWorkspace(head, parentChangeset.GitCommit, workspace);
     workspace.Shelve(shelvesetName, evaluateCheckinPolicies, () => Repository.GetCommitMessage(head, parentChangeset.GitCommit));
 }
Ejemplo n.º 52
0
 public long CheckinTool(string head, TfsChangesetInfo parentChangeset)
 {
     var changeset = 0L;
     Tfs.WithWorkspace(WorkingDirectory, this, parentChangeset,
                       workspace => changeset = CheckinTool(head, parentChangeset, workspace));
     return changeset;
 }
Ejemplo n.º 53
0
 private long CheckinTool(string head, TfsChangesetInfo parentChangeset, ITfsWorkspace workspace)
 {
     PendChangesToWorkspace(head, parentChangeset.GitCommit, workspace);
     return(workspace.CheckinTool(() => Repository.GetCommitMessage(head, parentChangeset.GitCommit)));
 }
Ejemplo n.º 54
0
 private long CheckinTool(string head, TfsChangesetInfo parentChangeset, ITfsWorkspace workspace)
 {
     PendChangesToWorkspace(head, parentChangeset.GitCommit, workspace);
     return workspace.CheckinTool(() => Repository.GetCommitMessage(head, parentChangeset.GitCommit));
 }
Ejemplo n.º 55
0
 private void WithWorkspace(TfsChangesetInfo parentChangeset, Action <ITfsWorkspace> action)
 {
     Tfs.WithWorkspace(WorkingDirectory, this, parentChangeset, action);
 }
Ejemplo n.º 56
0
 public int Checkin(string treeish, TfsChangesetInfo parentChangeset, CheckinOptions options, string sourceTfsPath = null)
 {
     throw DerivedRemoteException;
 }
Ejemplo n.º 57
0
 public void Shelve(string shelvesetName, string treeish, TfsChangesetInfo parentChangeset, bool evaluateCheckinPolicies)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 58
0
 protected override int DoCheckin(TfsChangesetInfo changeset, string refToCheckin)
 {
     return changeset.Remote.Checkin(refToCheckin, changeset, _checkinOptions);
 }
Ejemplo n.º 59
0
 private void Shelve(string shelvesetName, string head, TfsChangesetInfo parentChangeset, CheckinOptions options, bool evaluateCheckinPolicies, ITfsWorkspace workspace)
 {
     PendChangesToWorkspace(head, parentChangeset.GitCommit, workspace);
     workspace.Shelve(shelvesetName, evaluateCheckinPolicies, options);
 }