コード例 #1
0
ファイル: GitTfsRemote.cs プロジェクト: sa2013/git-tfs
        private IGitTfsRemote FindOrInitTfsRemoteOfChangeset(int parentChangesetId, bool mergeChangeset, IRenameResult renameResult, out string omittedParentBranch)
        {
            omittedParentBranch = null;
            IGitTfsRemote tfsRemote;
            IChangeset    parentChangeset = Tfs.GetChangeset(parentChangesetId);
            //I think you want something that uses GetPathInGitRepo and ShouldSkip. See TfsChangeset.Apply.
            //Don't know if there is a way to extract remote tfs repository path from changeset datas! Should be better!!!
            var remote = Repository.ReadAllTfsRemotes().FirstOrDefault(r => parentChangeset.Changes.Any(c => r.GetPathInGitRepo(c.Item.ServerItem) != null));

            if (remote != null)
            {
                tfsRemote = remote;
            }
            else
            {
                // If the changeset has created multiple folders, the expected branch folder will not always be the first
                // so we scan all the changes of type folder to try to detect the first one which is a branch.
                // In most cases it will change nothing: the first folder is the good one
                IBranchObject tfsBranch   = null;
                string        tfsPath     = null;
                var           allBranches = Tfs.GetBranches(true);
                foreach (var change in parentChangeset.Changes)
                {
                    tfsPath = change.Item.ServerItem;
                    tfsPath = tfsPath.EndsWith("/") ? tfsPath : tfsPath + "/";

                    tfsBranch = allBranches.SingleOrDefault(b => tfsPath.StartsWith(b.Path.EndsWith("/") ? b.Path : b.Path + "/"));
                    if (tfsBranch != null)
                    {
                        // we found a branch, we stop here
                        break;
                    }
                }

                if (mergeChangeset && tfsBranch != null &&
                    string.Equals(Repository.GetConfig(GitTfsConstants.IgnoreNotInitBranches), true.ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    Trace.TraceInformation("warning: skip not initialized branch for path " + tfsBranch.Path);
                    tfsRemote           = null;
                    omittedParentBranch = tfsBranch.Path + ";C" + parentChangesetId;
                }
                else if (tfsBranch == null)
                {
                    Trace.TraceInformation("error: branch not found. Verify that all the folders have been converted to branches (or something else :().\n\tpath {0}", tfsPath);
                    tfsRemote           = null;
                    omittedParentBranch = ";C" + parentChangesetId;
                }
                else
                {
                    tfsRemote = InitTfsRemoteOfChangeset(tfsBranch, parentChangeset.ChangesetId, renameResult);
                    if (tfsRemote == null)
                    {
                        omittedParentBranch = tfsBranch.Path + ";C" + parentChangesetId;
                    }
                }
            }
            return(tfsRemote);
        }
コード例 #2
0
ファイル: GitTfsRemote.cs プロジェクト: solidco2/git-tfs
        private IGitTfsRemote FindOrInitTfsRemoteOfChangeset(int parentChangesetId, bool mergeChangeset, out string omittedParentBranch)
        {
            omittedParentBranch = null;
            IGitTfsRemote tfsRemote;
            IChangeset    parentChangeset = Tfs.GetChangeset(parentChangesetId);
            //I think you want something that uses GetPathInGitRepo and ShouldSkip. See TfsChangeset.Apply.
            //Don't know if there is a way to extract remote tfs repository path from changeset datas! Should be better!!!
            var remote = Repository.ReadAllTfsRemotes().FirstOrDefault(r => parentChangeset.Changes.Any(c => r.GetPathInGitRepo(c.Item.ServerItem) != null));

            if (remote != null)
            {
                tfsRemote = remote;
            }
            else
            {
                var tfsPath = parentChangeset.Changes.First().Item.ServerItem;
                tfsPath = tfsPath.EndsWith("/") ? tfsPath : tfsPath + "/";
                var tfsBranch = Tfs.GetBranches(true).SingleOrDefault(b => tfsPath.StartsWith(b.Path.EndsWith("/") ? b.Path : b.Path + "/"));

                if (mergeChangeset && tfsBranch != null && Repository.GetConfig(GitTfsConstants.IgnoreNotInitBranches) == true.ToString())
                {
                    stdout.WriteLine("warning: skip not initialized branch for path " + tfsBranch.Path);
                    tfsRemote           = null;
                    omittedParentBranch = tfsBranch.Path + ";C" + parentChangesetId;
                }
                else if (tfsBranch == null)
                {
                    stdout.WriteLine("error: branch  not found. Verify that all the folders have been converted to branches (or something else :().\n\tpath {0}", tfsPath);
                    tfsRemote           = null;
                    omittedParentBranch = ";C" + parentChangesetId;
                }
                else
                {
                    tfsRemote = InitTfsRemoteOfChangeset(tfsBranch, parentChangeset.ChangesetId);
                    if (tfsRemote == null)
                    {
                        omittedParentBranch = tfsBranch.Path + ";C" + parentChangesetId;
                    }
                }
            }
            return(tfsRemote);
        }