private bool InitModules() { if (!File.Exists(_fullPathResolver.Resolve(".gitmodules"))) { return(false); } if (!IsSubmodulesInitialized()) { if (AskIfSubmodulesShouldBeInitialized()) { UICommands.StartUpdateSubmodulesDialog(this); } return(true); } return(false); }
/// <summary> /// Loads commit template from the file specified in .git/config /// under <c>commit.template</c> setting. /// </summary> /// <exception cref="FileNotFoundException">The specified template file cannot be found.</exception> /// <returns>The commit template, if it is specified; otherwise <see langword="null"/>.</returns> /// <remarks> /// Template file can be set by the following command: /// <c>$ git config --global commit.template ~/.git_commit_msg.txt</c> /// </remarks> public string?LoadGitCommitTemplate() { string?fileName = GetModule().GetEffectiveSetting("commit.template"); if (string.IsNullOrEmpty(fileName)) { return(null); } fileName = _fullPathResolver.Resolve(fileName); if (!_fileSystem.File.Exists(fileName)) { throw new FileNotFoundException("File not found", fileName); } string commitTemplate = _fileSystem.File.ReadAllText(fileName); return(commitTemplate); }
static (bool allFilesExist, bool allFilesOrUntrackedDirectoriesExist) FileOrUntrackedDirExists(List <FileStatusItem> items, IFullPathResolver fullPathResolver) { bool allFilesExist = items.Any(); bool allFilesOrUntrackedDirectoriesExist = items.Any(); foreach (var item in items) { var path = fullPathResolver.Resolve(item.Item.Name); var fileExists = File.Exists(path); allFilesExist = allFilesExist && fileExists; var fileOrUntrackedDirectoryExists = fileExists || (!item.Item.IsTracked && Directory.Exists(path)); allFilesOrUntrackedDirectoriesExist = allFilesOrUntrackedDirectoriesExist && fileOrUntrackedDirectoryExists; if (allFilesExist == false && allFilesOrUntrackedDirectoriesExist == false) { break; } } return(allFilesExist, allFilesOrUntrackedDirectoriesExist); }
public DialogResult PullChanges(IWin32Window owner) { if (!ShouldPullChanges()) { return(DialogResult.No); } DialogResult dr = ShouldRebaseMergeCommit(); if (dr != DialogResult.Yes) { return(dr); } if (!Fetch.Checked && Branches.Text.IsNullOrWhiteSpace() && Module.IsDetachedHead()) { int idx = PSTaskDialog.cTaskDialog.ShowCommandBox( owner, _notOnBranchCaption.Text, _notOnBranchMainInstruction.Text, _notOnBranch.Text, _notOnBranchButtons.Text, ShowCancelButton: true); switch (idx) { case 0: if (!UICommands.StartCheckoutBranch(owner)) { return(DialogResult.Cancel); } break; case -1: return(DialogResult.Cancel); } } if (PullFromUrl.Checked && Directory.Exists(comboBoxPullSource.Text)) { var path = comboBoxPullSource.Text; ThreadHelper.JoinableTaskFactory.Run(() => RepositoryHistoryManager.Remotes.AddAsMostRecentAsync(path)); } var source = CalculateSource(); if (!CalculateLocalBranch(source, out var curLocalBranch, out var curRemoteBranch)) { return(DialogResult.No); } ScriptManager.RunEventScripts(this, ScriptEvent.BeforePull); var stashed = CalculateStashedValue(owner); using (var form = CreateFormProcess(source, curLocalBranch, curRemoteBranch)) { if (!IsPullAll()) { form.Remote = source; } form.ShowDialog(owner); ErrorOccurred = form.ErrorOccurred(); try { bool aborted = form.DialogResult == DialogResult.Abort; if (!aborted && !Fetch.Checked) { if (!ErrorOccurred) { if (!InitModules()) { UICommands.UpdateSubmodules(owner); } } else { CheckMergeConflictsOnError(); } } } finally { if (stashed) { PopStash(); } ScriptManager.RunEventScripts(this, ScriptEvent.AfterPull); } } return(DialogResult.OK); bool ShouldPullChanges() { if (PullFromUrl.Checked && string.IsNullOrEmpty(comboBoxPullSource.Text)) { MessageBox.Show(this, _selectSourceDirectory.Text); return(false); } if (PullFromRemote.Checked && string.IsNullOrEmpty(_NO_TRANSLATE_Remotes.Text) && !IsPullAll()) { MessageBox.Show(this, _selectRemoteRepository.Text); return(false); } if (!Fetch.Checked && Branches.Text == "*") { MessageBox.Show(this, _fetchAllBranchesCanOnlyWithFetch.Text); return(false); } return(true); } string CalculateSource() { if (PullFromUrl.Checked) { return(comboBoxPullSource.Text); } LoadPuttyKey(); return(IsPullAll() ? "--all" : _NO_TRANSLATE_Remotes.Text); } bool InitModules() { if (!File.Exists(_fullPathResolver.Resolve(".gitmodules"))) { return(false); } if (!IsSubmodulesInitialized()) { if (AskIfSubmodulesShouldBeInitialized()) { UICommands.StartUpdateSubmodulesDialog(this); } return(true); } return(false); bool IsSubmodulesInitialized() { // Fast submodules check return(Module.GetSubmodulesLocalPaths() .Select(submoduleName => Module.GetSubmodule(submoduleName)) .All(submodule => submodule.IsValidGitWorkingDir())); } bool AskIfSubmodulesShouldBeInitialized() { return(MessageBox.Show(this, _questionInitSubmodules.Text, _questionInitSubmodulesCaption.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes); } } void CheckMergeConflictsOnError() { // Rebase failed -> special 'rebase' merge conflict if (Rebase.Checked && Module.InTheMiddleOfRebase()) { UICommands.StartTheContinueRebaseDialog(owner); } else if (Module.InTheMiddleOfAction()) { MergeConflictHandler.HandleMergeConflicts(UICommands, owner); } } void PopStash() { if (ErrorOccurred || Module.InTheMiddleOfAction()) { return; } bool?messageBoxResult = AppSettings.AutoPopStashAfterPull; if (messageBoxResult == null) { DialogResult res = PSTaskDialog.cTaskDialog.MessageBox( owner, _applyStashedItemsAgainCaption.Text, "", _applyStashedItemsAgain.Text, "", "", _dontShowAgain.Text, PSTaskDialog.eTaskDialogButtons.YesNo, PSTaskDialog.eSysIcons.Question, PSTaskDialog.eSysIcons.Question); messageBoxResult = res == DialogResult.Yes; if (PSTaskDialog.cTaskDialog.VerificationChecked) { AppSettings.AutoPopStashAfterPull = messageBoxResult; } } if ((bool)messageBoxResult) { UICommands.StashPop(owner); } } }
private void SpawnCommitBrowser(GitItem item) { GitUICommands.LaunchBrowse(workingDir: _fullPathResolver.Resolve(item.FileName.EnsureTrailingPathSeparator()), selectedId: item.ObjectId); }
void FileStatusListView_MouseMove(object sender, MouseEventArgs e) { ListView listView = sender as ListView; // DRAG // If the mouse moves outside the rectangle, start the drag. if (_dragBoxFromMouseDown != Rectangle.Empty && !_dragBoxFromMouseDown.Contains(e.X, e.Y)) { if (SelectedItems.Any()) { StringCollection fileList = new StringCollection(); foreach (GitItemStatus item in SelectedItems) { string fileName = _fullPathResolver.Resolve(item.Name); fileList.Add(fileName.ToNativePath()); } DataObject obj = new DataObject(); obj.SetFileDropList(fileList); // Proceed with the drag and drop, passing in the list item. DoDragDrop(obj, DragDropEffects.Copy); _dragBoxFromMouseDown = Rectangle.Empty; } } // TOOLTIP if (listView != null) { ListViewItem hoveredItem; try { var point = new Point(e.X, e.Y); hoveredItem = listView.HitTest(point).Item; } catch (ArgumentOutOfRangeException) { hoveredItem = null; } var gitItemStatus = hoveredItem?.Tag as GitItemStatus; if (gitItemStatus != null) { string text; if (gitItemStatus.IsRenamed || gitItemStatus.IsCopied) { text = string.Concat(gitItemStatus.Name, " (", gitItemStatus.OldName, ")"); } else { text = gitItemStatus.Name; } float fTextWidth = listView.CreateGraphics().MeasureString(text, listView.Font).Width + 17; // Use width-itemheight because the icon drawn in front of the text is the itemheight if (fTextWidth > (FileStatusListView.Width - FileStatusListView.GetItemRect(hoveredItem.Index).Height)) { if (!hoveredItem.ToolTipText.Equals(gitItemStatus.ToString())) { hoveredItem.ToolTipText = gitItemStatus.ToString(); } } else { hoveredItem.ToolTipText = ""; } } } }
private void UseMergeWithScript(string fileName, string mergeScript, string baseFileName, string localFileName, string remoteFileName) { // get timestamp of file before merge. This is an extra check to verify if merge was successfully DateTime lastWriteTimeBeforeMerge = DateTime.Now; if (File.Exists(Path.Combine(Module.WorkingDir, fileName))) { lastWriteTimeBeforeMerge = File.GetLastWriteTime(_fullPathResolver.Resolve(fileName)); } Module.RunExternalCmdDetached("wscript", "\"" + mergeScript + "\" \"" + FixPath(_fullPathResolver.Resolve(fileName)) + "\" \"" + FixPath(remoteFileName) + "\" \"" + FixPath(localFileName) + "\" \"" + FixPath(baseFileName) + "\""); if (MessageBox.Show(this, string.Format(_askMergeConflictSolvedAfterCustomMergeScript.Text, FixPath(_fullPathResolver.Resolve(fileName))), _askMergeConflictSolvedCaption.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { DateTime lastWriteTimeAfterMerge = lastWriteTimeBeforeMerge; if (File.Exists(_fullPathResolver.Resolve(fileName))) { lastWriteTimeAfterMerge = File.GetLastWriteTime(_fullPathResolver.Resolve(fileName)); } // The file is not modified, do not stage file and present warning if (lastWriteTimeBeforeMerge == lastWriteTimeAfterMerge) { MessageBox.Show(this, _fileUnchangedAfterMerge.Text); } else { StageFile(fileName); } } Initialize(); if (File.Exists(baseFileName)) { File.Delete(baseFileName); } if (File.Exists(remoteFileName)) { File.Delete(remoteFileName); } if (File.Exists(localFileName)) { File.Delete(localFileName); } }