string GetFilePathForNewFile(IDXVcsRepository repository, string vcsPath, DXVcsBranch currentBranch) { string testVcsPath = currentBranch.Path; string result = repository.GetFileWorkingPath(testVcsPath) + @"\"; return(vcsPath.Replace(currentBranch.Path, result)); }
public bool CheckIn(CheckInViewModel checkInViewModel, DXVcsBranch targetBranch, bool isNew) { Logger.AddInfo("CheckInCommand. Perform checkin file: " + checkInViewModel.FilePath); try { IDXVcsRepository repository = DXVcsRepositoryFactory.Create(Port.VcsServer); string filePath = GetFilePathForBranch(checkInViewModel.FilePath, targetBranch); string vcsOriginalPath = GetMergeVcsPathByTargetPath(filePath, targetBranch); if (isNew) { repository.AddFile(vcsOriginalPath, File.ReadAllBytes(filePath), checkInViewModel.Comment); } else { repository.CheckInFile(vcsOriginalPath, filePath, checkInViewModel.Comment); } if (checkInViewModel.StaysChecked) { repository.CheckOutFile(vcsOriginalPath, filePath, checkInViewModel.Comment); } } catch (Exception e) { Logger.AddError("CheckInCommand. CheckIn failed.", e); return(false); } return(true); }
public void CompareWithPortVersion(string filePath, DXVcsBranch current) { try { IDXVcsRepository repository = DXVcsRepositoryFactory.Create(Port.VcsServer); string vcsTargetPath = GetMergeVcsPathByOriginalPath(filePath, current); PreviewTarget(repository, vcsTargetPath, repository.GetFileWorkingPath(vcsTargetPath)); } catch (Exception e) { DXMessageBox.Show(e.Message); } }
public MergeState MergeChanges(DXVcsBranch currentBranch, string filePath, string mergePath, bool showPreview) { 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 { repository.GetLatestVersion(vcsOriginalPath, tmpOriginalFile); string tmpTargetFile = string.Empty; try { tmpTargetFile = 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 { repository.CheckOutFile(vcsTargetFile, tmpTargetFile, string.Empty); } catch (Exception e) { Logger.AddError("MergeCommand. Check out file error.", e); return(MergeState.CheckOutFileError); } var diff = new FileDiff(); if (!diff.Merge(tmpOriginalFile, filePath, tmpTargetFile)) { return(MergeState.Conflict); } if (showPreview) { PreviewTarget(repository, vcsTargetFile, tmpTargetFile); } } finally { File.Delete(tmpOriginalFile); } } catch { return(MergeState.UnknownError); } return(MergeState.Success); }
public string GetFilePathForBranch(string path, DXVcsBranch currentBranch) { try { string relativePath = GetMergeVcsPathByOriginalPath(path, currentBranch); IDXVcsRepository repository = DXVcsRepositoryFactory.Create(Port.VcsServer); return(repository.GetFileWorkingPath(relativePath)); } catch (Exception e) { Logger.AddError("GetFilePathForBranch failed.", e); } return(string.Empty); }
public string GetMergeVcsPathByOriginalPath(string filePath, DXVcsBranch currentBranch) { string relativePath = Port.GetRelativePath(filePath); string result = relativePath.Replace(Port.MasterBranch.Path, currentBranch.Path); string ext = Path.GetExtension(filePath); if (ext == ".sln" || ext == ".csproj") { return(result + Path.GetFileName(filePath)); } return(result); }
public bool IsItemUnderVss(string filePath, DXVcsBranch current) { try { string vcsTargetPath = GetMergeVcsPathByOriginalPath(filePath, current); IDXVcsRepository repository = DXVcsRepositoryFactory.Create(Port.VcsServer); return(repository.IsUnderVss(vcsTargetPath)); } catch (Exception e) { Logger.AddError("IsItemUnderVss failed.", e); } return(true); }
public void NavigateToSolution(DXVcsBranch currentBranch, IDteWrapper dte) { try { string filePath = Port.ProjectFilePath; string vcsFilePath = GetMergeVcsPathByOriginalPath(filePath, currentBranch); IDXVcsRepository repository = DXVcsRepositoryFactory.Create(Port.VcsServer); string targetPath = repository.GetFileWorkingPath(vcsFilePath); dte.OpenSolution(targetPath); } catch { MessageBox.Show("Can`t navigate to solution"); } }
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); }
public void CompareCurrentWithPortVersion(string filePath, DXVcsBranch current) { try { IDXVcsRepository repository = DXVcsRepositoryFactory.Create(Port.VcsServer); string vcsTargetPath = GetMergeVcsPathByOriginalPath(filePath, current); if (!repository.IsUnderVss(vcsTargetPath)) { DXMessageBox.Show("Target is not under vss"); return; } string fileTargetPath = repository.GetFileWorkingPath(vcsTargetPath); PreviewTarget(repository, fileTargetPath, vcsTargetPath, filePath, false); } catch (Exception e) { DXMessageBox.Show(e.Message); } }
string GetMergeVcsPathByTargetPath(string filePath, DXVcsBranch currentBranch) { return(Port.GetRelativePath(filePath, currentBranch)); }
void CreateNewFileIfNeeded(IDXVcsRepository repository, string vcsTargetFile, DXVcsBranch branch) { if (repository.IsUnderVss(vcsTargetFile)) { throw new ArgumentException("File is under vss alrealy!"); } string filePath = GetFilePathForNewFile(repository, vcsTargetFile, branch); if (File.Exists(filePath)) { var attr = File.GetAttributes(filePath); if (attr == FileAttributes.ReadOnly) { throw new ArgumentException("File is readonly!"); } File.Delete(filePath); } string dir = Path.GetDirectoryName(filePath); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } using (var f = File.Create(filePath)) { f.Close(); } }