Beispiel #1
0
        private string FindRemoteAndFetch(int parentChangesetId, bool stopOnFailMergeCommit, bool mergeChangeset, IRenameResult renameResult, out string omittedParentBranch)
        {
            var tfsRemote = FindOrInitTfsRemoteOfChangeset(parentChangesetId, mergeChangeset, renameResult, out omittedParentBranch);

            if (tfsRemote != null && string.Compare(tfsRemote.TfsRepositoryPath, TfsRepositoryPath, StringComparison.InvariantCultureIgnoreCase) != 0)
            {
                stdout.WriteLine("\tFetching from dependent TFS remote '{0}'...", tfsRemote.Id);
                try
                {
                    var fetchResult = ((GitTfsRemote)tfsRemote).FetchWithMerge(-1, stopOnFailMergeCommit, parentChangesetId, renameResult);
                }
                finally
                {
                    Trace.WriteLine("Cleaning...");
                    tfsRemote.CleanupWorkspaceDirectory();

                    if (tfsRemote.Repository.IsBare)
                    {
                        tfsRemote.Repository.UpdateRef(GitRepository.ShortToLocalName(tfsRemote.Id), tfsRemote.MaxCommitHash);
                    }
                }
                return(Repository.FindCommitHashByChangesetId(parentChangesetId));
            }
            return(null);
        }
        public void Unshelve(string shelvesetOwner, string shelvesetName, string destinationBranch, Action <Exception> ignorableErrorHandler)
        {
            var destinationRef = GitRepository.ShortToLocalName(destinationBranch);

            if (Repository.HasRef(destinationRef))
            {
                throw new GitTfsException("ERROR: Destination branch (" + destinationBranch + ") already exists!");
            }

            var shelvesetChangeset = Tfs.GetShelvesetData(this, shelvesetOwner, shelvesetName);

            var parentId = shelvesetChangeset.BaseChangesetId;
            var ch       = GetTfsChangesetById(parentId);

            if (ch == null)
            {
                throw new GitTfsException("ERROR: Parent changeset C" + parentId + " not found."
                                          + " Try fetching the latest changes from TFS");
            }

            var log    = Apply(ch.GitCommit, shelvesetChangeset, ignorableErrorHandler);
            var commit = Commit(log);

            Repository.UpdateRef(destinationRef, commit, "Shelveset " + shelvesetName + " from " + shelvesetOwner);
        }
Beispiel #3
0
        private IGitTfsRemote InitTfsRemoteOfChangeset(IBranchObject tfsBranch, int parentChangesetId, IRenameResult renameResult = null)
        {
            if (tfsBranch.IsRoot)
            {
                return(InitTfsBranch(this.remoteOptions, tfsBranch.Path));
            }

            var branchesDatas = Tfs.GetRootChangesetForBranch(tfsBranch.Path, parentChangesetId);

            IGitTfsRemote remote = null;

            foreach (var branch in branchesDatas)
            {
                var rootChangesetId = branch.RootChangeset;
                remote = InitBranch(this.remoteOptions, tfsBranch.Path, rootChangesetId, true);
                if (remote == null)
                {
                    stdout.WriteLine("warning: root commit not found corresponding to changeset " + rootChangesetId);
                    stdout.WriteLine("=> continuing anyway by creating a branch without parent...");
                    return(InitTfsBranch(this.remoteOptions, tfsBranch.Path));
                }

                if (branch.IsRenamedBranch)
                {
                    try
                    {
                        remote.Fetch(renameResult: renameResult);
                    }
                    finally
                    {
                        Trace.WriteLine("Cleaning...");
                        remote.CleanupWorkspaceDirectory();

                        if (remote.Repository.IsBare)
                        {
                            remote.Repository.UpdateRef(GitRepository.ShortToLocalName(remote.Id), remote.MaxCommitHash);
                        }
                    }
                }
            }

            return(remote);
        }
Beispiel #4
0
        public void Unshelve(string shelvesetOwner, string shelvesetName, string destinationBranch, Action <Exception> ignorableErrorHandler, bool force)
        {
            var destinationRef = GitRepository.ShortToLocalName(destinationBranch);

            if (Repository.HasRef(destinationRef))
            {
                throw new GitTfsException("ERROR: Destination branch (" + destinationBranch + ") already exists!");
            }

            var shelvesetChangeset = Tfs.GetShelvesetData(this, shelvesetOwner, shelvesetName);

            var    parentId = shelvesetChangeset.BaseChangesetId;
            var    ch       = GetTfsChangesetById(parentId);
            string rootCommit;

            if (ch == null)
            {
                if (!force)
                {
                    throw new GitTfsException("ERROR: Parent changeset C" + parentId + " not found.", new[]
                    {
                        "Try fetching the latest changes from TFS",
                        "Try applying the shelveset on the currently checkouted commit using the '--force' option"
                    }
                                              );
                }
                stdout.WriteLine("warning: Parent changeset C" + parentId + " not found."
                                 + " Trying to apply the shelveset on the current commit...");
                rootCommit = Repository.GetCurrentCommit();
            }
            else
            {
                rootCommit = ch.GitCommit;
            }

            var log    = Apply(rootCommit, shelvesetChangeset, ignorableErrorHandler);
            var commit = Commit(log);

            Repository.UpdateRef(destinationRef, commit, "Shelveset " + shelvesetName + " from " + shelvesetOwner);
        }