Example #1
0
        internal void CopyAndCommit(List <CCElementVersion> ccHistory, DateTime since, DateTime until)
        {
            Git       git      = new Git(CreateGitInfo());
            ClearCase mainCC   = new ClearCase(CreateCCInfo("main"));
            ClearCase branchCC = new ClearCase(CreateCCInfo(this.BranchName));
            string    author   = "gicc <*****@*****.**>"; // todo : implement

            // main -> master
            mainCC.SetBranchCS(until);
            git.Checkout("master");

            List <string> mainFileList = mainCC.FindAllFilesInBranch(since, until);

            CopyFiles(mainFileList, VobPath, RepoPath);

            git.AddCommit("gicc", author);
            git.TagPull(); // todo : if changed

            // vob branch -> git branch
            branchCC.SetBranchCS(until);
            git.Checkout(BranchName);

            List <string> branchFileList = ccHistory
                                           .Where(elemVer => elemVer.CreatedDate > since && elemVer.CreatedDate <= until) // todo : pull 에서 날짜 제한 걸어주면 필요 없을 듯
                                           .Select(elemVer => elemVer.ElementName).ToList()
                                           .Distinct().ToList();

            CopyFiles(branchFileList, VobPath, RepoPath);

            git.AddCommit("gicc", author);
            git.TagPull(); // todo : if changed
        }
Example #2
0
        public List <string> ListCCFilesOnBranch(string branchName)
        {
            this.BranchName = branchName;
            ClearCase cc = new ClearCase(CreateCCInfo(branchName));

            return(cc.FindAllFilesInBranch());
        }
Example #3
0
        internal void CopyAndCheckin(Dictionary <string, FileChangeType> committedFileDic, string checkInComment)
        {
            ClearCase cc = new ClearCase(CreateCCInfo(this.BranchName));

            foreach (KeyValuePair <string, FileChangeType> kvp in committedFileDic)
            {
                switch (kvp.Value)
                {
                case FileChangeType.Creation:
                    File.Copy(Path.Combine(RepoPath, kvp.Key), Path.Combine(VobPath, kvp.Key), false);
                    cc.CheckIn(Path.Combine(VobPath, kvp.Key), checkInComment);
                    break;

                case FileChangeType.Modification:
                    cc.Checkout(kvp.Key);
                    File.Copy(Path.Combine(RepoPath, kvp.Key), Path.Combine(VobPath, kvp.Key), true);
                    cc.CheckIn(Path.Combine(VobPath, kvp.Key), checkInComment);
                    break;

                case FileChangeType.Delete:
                    // Will not implement.
                    break;

                default:
                    throw new InvalidOperationException("Git 파일 변경 사항은 추가, 수정, 삭제 중 하나여야 합니다.");
                }
            }
        }
Example #4
0
        /// <summary>
        /// git repository 의 working branch 작업사항을 cc branch 에 push 합니다.
        /// </summary>
        public void PushWorkingBranch()
        {
            Git       git = new Git(CreateGitInfo());
            ClearCase cc  = new ClearCase(CreateCCInfo(this.BranchName));

            Dictionary <string, FileChangeType> committedFileDic = git.GetCommittedFilesAfterLastPP();

            // 1. validateion
            CheckCurrentBranchEqualsToWorkingBranch(git);
            git.CheckModifiedFileIsNotExist();
            cc.CheckCheckoutNotExists(committedFileDic.Keys.ToList());

            // 2. pull & merge
            if (cc.FindAllFilesInBranch(git.GetLastPPDate(), DateTime.Now).Count > 0)
            {
                string message = string.Empty;

                message += "There are new checked-in files in the VOB." + Environment.NewLine;
                // todo : checkout _gicctemp branch, reset --hard before pull
                message += "The checked-in file are automatically pulled to the " + BranchName + " branch," + Environment.NewLine;
                // todo : move to _gicctemp branch
                message += "and your commits are moved to the " + BranchName + "_gicctemp branch." + Environment.NewLine;
                message += "Please merge your commits into the " + BranchName + " branch and execute push again." + Environment.NewLine;

                throw new GiccException(message);
            }

            // 3. copy commited files after last pull/push tag & checkin
            CopyAndCheckin(committedFileDic,
                           "checked in with gicc" + Environment.NewLine
                           + "-git commit id : " + git.GetHeadCommitId());

            // 4. tag "push"
            git.TagPush();
        }
Example #5
0
        /// <summary>
        /// Pull changes from cc main branch and cc working branch.
        /// All changes after the last gicc_push or gicc_pull tagged commit will be pulled.
        /// </summary>
        public void Pull()
        {
            Git       git = new Git(CreateGitInfo());
            ClearCase cc  = new ClearCase(CreateCCInfo(this.BranchName));
            List <CCElementVersion> ccHistory = new List <CCElementVersion>();

            ////cc.CheckAllSymbolicLinksAreMounted(); // symbolic link 는 nuget 으로 관리
            cc.CheckCheckedoutFileNotExistsInCurrentView();
            git.CheckModifiedFileIsNotExist();

            cc.FindAllFilesInBranch(git.GetLastPPDate(), DateTime.Now)
            .ForEach(file => ccHistory.AddRange(cc.Lshistory(file)));

            // todo: GetCommitPoints 와 CopyAndCommit 로직이 이상하다.
            // branch 내의 파일로 GetCommitPoints 를 잡는데, CopyAndCommit 에서 메인 브랜치를 pull 할 때 이를 이용한다.
            // 이러면 main branch 를 제대로 pull 할 수 없다.
            throw new NotImplementedException();

            List <DateTime> commitPoints = GetCommitPoints(ccHistory);

            for (int i = 0; i < commitPoints.Count - 2; i++)
            {
                CopyAndCommit(ccHistory, commitPoints[i], commitPoints[i + 1]);
            }
        }
Example #6
0
        /// <summary>
        /// 대상 브렌치에서 첫 번째 체크인이 일어나기 직전 상태의 메인 브렌치 파일들을 복사합니다.
        /// </summary>
        private void CopyMainBranchBeforeFirstBranchCheckin(string branchName)
        {
            ClearCase main   = new ClearCase(CreateCCInfo("main"));
            ClearCase branch = new ClearCase(CreateCCInfo(branchName));

            DateTime firstCheckinDate = branch.GetAllVersionsInBranch().Min(version => version.CreatedDate);

            main.SetMainCS(firstCheckinDate.AddSeconds(-1));

            CopyDirectory(VobPath, RepoPath);
        }
Example #7
0
        public void Clone()
        {
            Git       git = new Git(CreateGitInfo());
            ClearCase cc  = new ClearCase(CreateCCInfo(BranchName));

            git.Init();

            // move to git repository.
            CWD = git.RepoPath;

            WriteGiccConfig();

            CopyMainBranchBeforeFirstBranchCheckin(BranchName);
            git.AddCommit("gicc initialize", cc.GetAllVersionsInBranch().Min(version => version.CreatedDate).AddSeconds(-1));
            git.TagPull();

            Pull();
        }