コード例 #1
0
ファイル: MergeHelper.cs プロジェクト: Xarlot/DXVcsTools
        public MergeState ManualMerge(DXVcsBranch currentBranch, ManualMergeViewModel mergeModel, Func <bool> showManualMergeUIHandler)
        {
            try {
                string           filePath   = mergeModel.OriginalFilePath;
                string           mergePath  = mergeModel.TargetFilePath;
                IDXVcsRepository repository = DXVcsRepositoryFactory.Create(Port.VcsServer);

                string vcsTargetFile = mergePath == null?GetMergeVcsPathByOriginalPath(filePath, currentBranch) : GetMergeVcsPathByTargetPath(mergePath, currentBranch);

                string tmpTargetFile = repository.GetFileWorkingPath(vcsTargetFile);
                mergeModel.TargetFilePath = tmpTargetFile;

                if (!showManualMergeUIHandler())
                {
                    Logger.AddInfo("ManualMergeCommand. Result = MergeState.None.");
                    return(MergeState.None);
                }

                vcsTargetFile = GetMergeVcsPathByTargetPath(mergeModel.TargetFilePath, currentBranch);
                string tmpOriginalFile = mergeModel.OriginalFilePath;
                tmpTargetFile = repository.GetFileWorkingPath(vcsTargetFile);
                if (string.IsNullOrEmpty(tmpTargetFile))
                {
                    Logger.AddInfo("ManualMergeCommand. Result = MergeState.TargetFileError.");
                    return(MergeState.TargetFileError);
                }

                repository.CheckOutFile(vcsTargetFile, tmpTargetFile, string.Empty);
                if (MergeFileHelper.IsBinaryFile(tmpTargetFile))
                {
                    if (OverwriteFile.Write(tmpOriginalFile, tmpTargetFile))
                    {
                        return(MergeState.Success);
                    }
                    else
                    {
                        return(MergeState.Conflict);
                    }
                }
                LaunchDiffTool(tmpOriginalFile, tmpTargetFile);
            }
            catch (Exception e) {
                Logger.AddError("ManualMergeCommand. Unknown error.", e);
                Logger.AddInfo("ManualMergeCommand. Result = MergeState.UnknownError.");
                return(MergeState.UnknownError);
            }
            Logger.AddInfo("ManualMergeCommand. Result = MergeState.Success");
            return(MergeState.Success);
        }
コード例 #2
0
ファイル: MergeHelper.cs プロジェクト: Xarlot/DXVcsTools
        public MergeState MergeChanges(DXVcsBranch currentBranch, string filePath, string mergePath, bool showPreview, bool isNew)
        {
            try {
                IDXVcsRepository repository      = DXVcsRepositoryFactory.Create(Port.VcsServer);
                string           tmpOriginalFile = Path.GetTempFileName();

                string vcsOriginalPath = Port.GetRelativePath(filePath);
                string vcsTargetFile   = mergePath == null?GetMergeVcsPathByOriginalPath(filePath, currentBranch) : Port.GetRelativePath(mergePath, currentBranch);

                try {
                    if (!isNew)
                    {
                        repository.GetLatestVersion(vcsOriginalPath, tmpOriginalFile);
                    }
                    else
                    {
                        CreateNewFileIfNeeded(repository, vcsTargetFile, currentBranch);
                    }
                    string tmpTargetFile;
                    try {
                        tmpTargetFile = isNew
                            ? GetFilePathForNewFile(repository, GetMergeVcsPathByOriginalPath(filePath, currentBranch), currentBranch)
                            : repository.GetFileWorkingPath(vcsTargetFile);
                    }
                    catch (Exception e) {
                        Logger.AddError("MergeCommand. Target file error.", e);
                        return(MergeState.TargetFileError);
                    }
                    if (string.IsNullOrEmpty(tmpTargetFile))
                    {
                        Logger.AddError("MergeCommand. Target file path is empty.");
                        return(MergeState.TargetFileError);
                    }

                    try {
                        if (!isNew)
                        {
                            repository.CheckOutFile(vcsTargetFile, tmpTargetFile, string.Empty);
                        }
                    }
                    catch (Exception e) {
                        Logger.AddError("MergeCommand. Check out file error.", e);
                        return(MergeState.CheckOutFileError);
                    }

                    FileDiffBase diff;
                    if (MergeFileHelper.IsBinaryFile(tmpTargetFile))
                    {
                        diff = new OverwriteFile();
                    }
                    else
                    {
                        diff = new FileDiff();
                    }
                    if (!diff.Merge(tmpOriginalFile, filePath, tmpTargetFile))
                    {
                        return(MergeState.Conflict);
                    }
                    if (showPreview)
                    {
                        PreviewTarget(repository, filePath, vcsTargetFile, tmpTargetFile, isNew);
                    }
                }
                catch (Exception e) {
                    Logger.AddError("MergeCommand. Unknown error.", e);
                }
                finally {
                    File.Delete(tmpOriginalFile);
                }
            }
            catch {
                return(MergeState.UnknownError);
            }
            return(MergeState.Success);
        }