コード例 #1
0
ファイル: InitBranch.cs プロジェクト: qnrckd/git-tfs
        private int CloneBranch(string tfsBranchPath, string gitBranchNameExpected)
        {
            var defaultRemote = InitFromDefaultRemote();

            // TFS representations of repository paths do not have trailing slashes
            tfsBranchPath = (tfsBranchPath ?? string.Empty).TrimEnd('/');

            if (!tfsBranchPath.IsValidTfsPath())
            {
                var remotes = _globals.Repository.GetLastParentTfsCommits(tfsBranchPath);
                if (!remotes.Any())
                {
                    throw new Exception("error: No TFS branch found!");
                }
                tfsBranchPath = remotes.First().Remote.TfsRepositoryPath;
            }
            tfsBranchPath.AssertValidTfsPath();

            var allRemotes = _globals.Repository.ReadAllTfsRemotes();
            var remote     = allRemotes.FirstOrDefault(r => r.TfsRepositoryPath.ToLower() == tfsBranchPath.ToLower());

            if (remote != null && remote.MaxChangesetId != 0)
            {
                _stdout.WriteLine("warning : There is already a remote for this tfs branch. Branch ignored!");
                return(GitTfsExitCodes.InvalidArguments);
            }

            IList <RootBranch> creationBranchData;

            if (ParentBranch == null)
            {
                creationBranchData = defaultRemote.Tfs.GetRootChangesetForBranch(tfsBranchPath);
            }
            else
            {
                var tfsRepositoryPathParentBranchFound = allRemotes.FirstOrDefault(r => r.TfsRepositoryPath.ToLower() == ParentBranch.ToLower());
                if (tfsRepositoryPathParentBranchFound == null)
                {
                    throw new GitTfsException("error: The Tfs parent branch '" + ParentBranch + "' can not be found in the Git repository\nPlease init it first and try again...\n");
                }

                creationBranchData = defaultRemote.Tfs.GetRootChangesetForBranch(tfsBranchPath, -1, tfsRepositoryPathParentBranchFound.TfsRepositoryPath);
            }

            IFetchResult fetchResult;

            InitBranchSupportingRename(tfsBranchPath, gitBranchNameExpected, creationBranchData, defaultRemote, out fetchResult);
            return(GitTfsExitCodes.OK);
        }
コード例 #2
0
ファイル: InitBranch.cs プロジェクト: irontoby/git-tfs
        public int Run(string tfsBranchPath, string gitBranchNameExpected)
        {
            //[Temporary] Remove in the next version!
            if (!DontDisplayObsoleteMessage)
            {
                _stdout.WriteLine("WARNING: This command is obsolete and will be removed in the next version. Use 'branch --init' instead!");
            }

            var defaultRemote = InitFromDefaultRemote();

            // TFS representations of repository paths do not have trailing slashes
            tfsBranchPath = (tfsBranchPath ?? string.Empty).TrimEnd('/');

            var allRemotes = _globals.Repository.ReadAllTfsRemotes();

            tfsBranchPath.AssertValidTfsPath();
            if (allRemotes.Any(r => r.TfsRepositoryPath.ToLower() == tfsBranchPath.ToLower()))
            {
                _stdout.WriteLine("warning : There is already a remote for this tfs branch. Branch ignored!");
                return(GitTfsExitCodes.InvalidArguments);
            }

            int rootChangeSetId;

            if (ParentBranch == null)
            {
                rootChangeSetId = defaultRemote.Tfs.GetRootChangesetForBranch(tfsBranchPath);
            }
            else
            {
                var tfsRepositoryPathParentBranchFound = allRemotes.FirstOrDefault(r => r.TfsRepositoryPath.ToLower() == ParentBranch.ToLower());
                if (tfsRepositoryPathParentBranchFound == null)
                {
                    throw new GitTfsException("error: The Tfs parent branch '" + ParentBranch + "' can not be found in the Git repository\nPlease init it first and try again...\n");
                }

                rootChangeSetId = defaultRemote.Tfs.GetRootChangesetForBranch(tfsBranchPath, tfsRepositoryPathParentBranchFound.TfsRepositoryPath);
            }

            var sha1RootCommit = _globals.Repository.FindCommitHashByChangesetId(rootChangeSetId);

            if (string.IsNullOrWhiteSpace(sha1RootCommit))
            {
                throw new GitTfsException("error: The root changeset " + rootChangeSetId +
                                          " have not be found in the Git repository. The branch containing the changeset should not have been created. Please do it before retrying!!\n");
            }
            var tfsRemote = CreateBranch(defaultRemote, tfsBranchPath, sha1RootCommit, gitBranchNameExpected);

            if (!NoFetch)
            {
                FetchRemote(tfsRemote, false);
            }
            else
            {
                Trace.WriteLine("Not fetching changesets, --nofetch option specified");
            }
            return(GitTfsExitCodes.OK);
        }
コード例 #3
0
ファイル: InitBranch.cs プロジェクト: LevShisterov/git-tfs
        private int CloneBranch(string tfsBranchPath, string gitBranchNameExpected)
        {
            var defaultRemote = InitFromDefaultRemote();

            // TFS representations of repository paths do not have trailing slashes
            tfsBranchPath = (tfsBranchPath ?? string.Empty).TrimEnd('/');

            if (!tfsBranchPath.IsValidTfsPath())
            {
                var remotes = _globals.Repository.GetLastParentTfsCommits(tfsBranchPath);
                if (!remotes.Any())
                {
                    throw new Exception("error: No TFS branch found!");
                }
                tfsBranchPath = remotes.First().Remote.TfsRepositoryPath;
            }
            tfsBranchPath.AssertValidTfsPath();

            IFetchResult fetchResult;
            var          allRemotes = _globals.Repository.ReadAllTfsRemotes().ToList();
            var          remote     = allRemotes.FirstOrDefault(r => String.Equals(r.TfsRepositoryPath, tfsBranchPath, StringComparison.OrdinalIgnoreCase));

            if (remote != null && remote.MaxChangesetId != 0)
            {
                Trace.WriteLine("Fetching remote: " + remote.Id);
                fetchResult = FetchRemote(remote, true, forceRefUpdate: true);
                if (fetchResult.NewChangesetCount != 0)
                {
                    Trace.TraceInformation("Existing branch: fetched new changes.");
                    _globals.Repository.GarbageCollect();
                }
                else
                {
                    Trace.TraceInformation("Existing branch: no new changes found.");
                }
                return(GitTfsExitCodes.OK);
            }

            IList <RootBranch> creationBranchData;

            if (ParentBranch == null)
            {
                creationBranchData = defaultRemote.Tfs.GetRootChangesetForBranch(tfsBranchPath);
            }
            else
            {
                var tfsRepositoryPathParentBranchFound = allRemotes.FirstOrDefault(r => r.TfsRepositoryPath.ToLower() == ParentBranch.ToLower());
                if (tfsRepositoryPathParentBranchFound == null)
                {
                    throw new GitTfsException("error: The Tfs parent branch '" + ParentBranch + "' can not be found in the Git repository\nPlease init it first and try again...\n");
                }

                creationBranchData = defaultRemote.Tfs.GetRootChangesetForBranch(tfsBranchPath, -1, tfsRepositoryPathParentBranchFound.TfsRepositoryPath);
            }

            InitBranchSupportingRename(tfsBranchPath, gitBranchNameExpected, creationBranchData, defaultRemote, out fetchResult);
            return(GitTfsExitCodes.OK);
        }