private void Initialize() { Cursor.Current = Cursors.WaitCursor; ConflictedFiles.MultiSelect = false; int oldSelectedRow = 0; if (ConflictedFiles.SelectedRows.Count > 0) { oldSelectedRow = ConflictedFiles.SelectedRows[0].Index; } ConflictedFiles.DataSource = GitCommandHelpers.GetConflictedFiles(); if (ConflictedFiles.Rows.Count > oldSelectedRow) { ConflictedFiles.Rows[oldSelectedRow].Selected = true; if (oldSelectedRow < ConflictedFiles.FirstDisplayedScrollingRowIndex || oldSelectedRow > (ConflictedFiles.FirstDisplayedScrollingRowIndex + ConflictedFiles.DisplayedRowCount(false))) { ConflictedFiles.FirstDisplayedScrollingRowIndex = oldSelectedRow; } } InitMergetool(); ConflictedFilesContextMenu.Text = "Solve"; OpenMergetool.Text = "Open in " + mergetool; button1.Text = "Open in " + mergetool; if (GitCommandHelpers.InTheMiddleOfRebase()) { Reset.Text = "Abort rebase"; ContextChooseLocal.Text = "Choose local (theirs)"; ContextChooseRemote.Text = "Choose remote (ours)"; } else { Reset.Text = "Abort merge"; ContextChooseLocal.Text = "Choose local (ours)"; ContextChooseRemote.Text = "Choose remote (theirs)"; } if (!GitCommandHelpers.InTheMiddleOfPatch() && !GitCommandHelpers.InTheMiddleOfRebase() && !GitCommandHelpers.InTheMiddleOfConflictedMerge() && ThereWhereMergeConflicts) { if (MessageBox.Show(allConflictsResolved.Text, allConflictsResolvedCaption.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { GitUICommands.Instance.StartCommitDialog(); } } if (!GitCommandHelpers.InTheMiddleOfConflictedMerge() && ThereWhereMergeConflicts) { Close(); } Cursor.Current = Cursors.Default; }
private void ConflictedFiles_DoubleClick(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; if (ConflictedFiles.SelectedRows.Count != 1) { return; } string filename = GetFileName(); string[] filenames = GitCommandHelpers.GetConflictedFiles(filename); try { if (Directory.Exists(Settings.WorkingDir + filename) && !File.Exists(Settings.WorkingDir + filename)) { /* BEGIN REPLACED WITH FASTER, BUT DIRTIER SUBMODULE CHECK * IList<IGitSubmodule> submodules = (new GitCommands.GitCommands()).GetSubmodules(); * foreach (IGitSubmodule submodule in submodules) * { * if (submodule.LocalPath.Equals(filename)) * { * if (MessageBox.Show(mergeConflictIsSubmodule.Text, mergeConflictIsSubmoduleCaption.Text, MessageBoxButtons.YesNo) == DialogResult.Yes) * { * stageFile(filename); * Initialize(); * } * return; * } * }*/ var submoduleConfig = new ConfigFile(Settings.WorkingDir + ".gitmodules"); if (submoduleConfig.GetConfigSections().Any(configSection => configSection.GetValue("path").Trim().Equals(filename.Trim()))) { if (MessageBox.Show(mergeConflictIsSubmodule.Text, mergeConflictIsSubmoduleCaption.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { stageFile(filename); } return; } //END: REPLACED WITH FASTER, BUT DIRTIER SUBMODULE CHECK } string arguments = mergetoolCmd; if (CheckForLocalRevision(filename) && CheckForRemoteRevision(filename)) { if (TryMergeWithScript(filename, filenames[0], filenames[2], filenames[1])) { Cursor.Current = Cursors.Default; return; } if (FileHelper.IsBinaryFile(filename)) { if (MessageBox.Show(string.Format(fileIsBinary.Text, mergetool), "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.No) { BinairyFilesChooseLocalBaseRemote(filename); return; } } //Check if there is a base file. If not, ask user to fall back to 2-way merge. //git doesn't support 2-way merge, but we can try to adjust attributes to fix this. //For kdiff3 this is easy; just remove the 3rd file from the arguments. Since the //filenames are quoted, this takes a little extra effort. We need to remove these //quotes also. For tortoise and araxis a little bit more magic is needed. if (filenames[0] == null) { DialogResult result = MessageBox.Show(string.Format(noBaseRevision.Text, filename), "Merge", MessageBoxButtons.YesNoCancel); if (result == DialogResult.Yes) { arguments = arguments.Replace("-merge -3", "-merge"); arguments = arguments.Replace("/base:\"$BASE\"", ""); arguments = arguments.Replace("\"$BASE\"", ""); } if (result == DialogResult.Cancel) { return; } } arguments = arguments.Replace("$BASE", filenames[0]); arguments = arguments.Replace("$LOCAL", filenames[1]); arguments = arguments.Replace("$REMOTE", filenames[2]); arguments = arguments.Replace("$MERGED", filename + ""); //get timestamp of file before merge. This is an extra check to verify if merge was successfull DateTime lastWriteTimeBeforeMerge = DateTime.Now; if (File.Exists(Settings.WorkingDir + filename)) { lastWriteTimeBeforeMerge = File.GetLastWriteTime(Settings.WorkingDir + filename); } int exitCode; GitCommandHelpers.RunCmd(mergetoolPath, "" + arguments + "", out exitCode); DateTime lastWriteTimeAfterMerge = lastWriteTimeBeforeMerge; if (File.Exists(Settings.WorkingDir + filename)) { lastWriteTimeAfterMerge = File.GetLastWriteTime(Settings.WorkingDir + filename); } //Check exitcode AND timestamp of the file. If exitcode is success and //time timestamp is changed, we are pretty sure the merge was done. if (exitCode == 0 && lastWriteTimeBeforeMerge != lastWriteTimeAfterMerge) { stageFile(filename); } //If the exitcode is 1, but the file is changed, ask if the merge conflict is solved. //If the exitcode is 0, but the file is not changed, ask if the merge conflict is solved. if ((exitCode == 1 && lastWriteTimeBeforeMerge != lastWriteTimeAfterMerge) || (exitCode == 0 && lastWriteTimeBeforeMerge == lastWriteTimeAfterMerge)) { if (MessageBox.Show(askMergeConflictSolved.Text, askMergeConflictSolvedCaption.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { stageFile(filename); } } } } finally { if (filenames[0] != null && File.Exists(filenames[0])) { File.Delete(filenames[0]); } if (filenames[1] != null && File.Exists(filenames[1])) { File.Delete(filenames[1]); } if (filenames[2] != null && File.Exists(filenames[2])) { File.Delete(filenames[2]); } Cursor.Current = Cursors.Default; Initialize(); } }