public MergeViewer(Project p, string filename, string original, string myVersion, string newVersion) { InitializeComponent(); gitFilename = filename; project = p; if (myVersion == null) { titleMe.Text += " (file was deleted)"; deletedSide = 0; } else if (original == null) { titleMe.Text += " (file was added)"; } else { titleMe.Text += " (file was modified)"; } if (newVersion == null) { titleNew.Text += " (file was deleted)"; deletedSide = 1; // Only one side can be deleted in a conflict, so deletedSide is either 0 or 1 } else if (original == null) { titleNew.Text += " (file was added)"; } else { titleNew.Text += " (file was modified)"; } }
public TextMergeViewer(Project p, string filename, string original, string myVersion, string newVersion) : base(p, filename, original, myVersion, newVersion) { this.filename = filename; this.myVersion = myVersion; this.newVersion = newVersion; if (original == null) { original = ""; // We don't really have to display anything differently. // Also, add-add conflicts don't need any special treatment. } ProcessDiff(original, myVersion, newVersion); InitializeEditor(); // Select the first conflict, update the conflict indicators. conflictHover = new int[conflictBlocks.Count]; conflictChoice = new int[conflictBlocks.Count]; for (int i = 0; i < conflictChoice.Length; i++) { conflictHover[i] = conflictChoice[i] = -1; } SelectConflict(0); if (conflictBlocks.Count > 1) { nextConflict.IsEnabled = prevConflict.IsEnabled = true; } UpdateStatus(); }
public CommitForm(Project p) { InitializeComponent(); Style = (Style)FindResource(typeof(Window)); Title += " for " + p.name; project = p; GetChanges(); }
public BinaryMergeViewer(Project p, string filename, string original, string myVersion, string newVersion) : base(p, filename, original, myVersion, newVersion) { editMe.Visibility = editThem.Visibility = Visibility.Collapsed; revertMe.Visibility = revertThem.Visibility = Visibility.Collapsed; manualMerge.Visibility = Visibility.Collapsed; grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); Grid.SetRow(actionsMe, 1); Grid.SetRow(actionsThem, 1); CreateFiles(filename, myVersion, newVersion); status.Text = "1 unresolved conflicts remaining."; }
public ProjectHistory(Project p, string hash = null) { InitializeComponent(); Style = (Style)FindResource(typeof(Window)); Title += " for " + p.name; project = p; string dir = ProjectMonitor.GetProjectDirectory(project); ProcessReturn ret = GitWrapper.Log(dir); string[] commits = SentenceFilter.SplitLines(ret.Output.Trim()); if (ret.ReturnValue != 0 || commits.Length == 0) { throw new InvalidRepositoryException(project); } var actualCommits = new string[commits.Length - 1]; Array.Copy(commits, actualCommits, commits.Length - 1); var timestamp = (int)(Directory.GetLastWriteTimeUtc(dir) - epoch).TotalSeconds; projectHistory.Items.Add(CreateListViewItem("", "Current Version", "", timestamp)); commitHashes = new List<string>(); int cIndex = 1; int? hashIndex = null; if (actualCommits.Count() > 0 && hash == "HEAD") { hashIndex = 1; } foreach (var commit in actualCommits) { var match = Regex.Match(commit, "^([a-z0-9]+) '(.*?)' ([0-9]+) (.*)$"); if (match.Success) { commitHashes.Add(match.Groups[1].Value); if (match.Groups[1].Value == hash) { hashIndex = cIndex; } cIndex++; projectHistory.Items.Add(CreateListViewItem(match.Groups[1].Value, match.Groups[4].Value, match.Groups[2].Value, int.Parse(match.Groups[3].Value))); } } if (hash != null && hashIndex == null) { MessageBox.Show("Could not find that revision. You may have to update the project.", "Version not found"); } projectHistory.SelectedIndex = hashIndex ?? 0; projectHistory.ScrollIntoView(projectHistory.Items[projectHistory.SelectedIndex]); projectHistory.Focus(); }
public FileHistory(Project p, string filename, string hash = null) { InitializeComponent(); Style = (Style)FindResource(typeof(Window)); Title += " for " + filename + " (" + p.name + ")"; project = p; this.filename = filename; gitFilename = filename.Replace(Path.DirectorySeparatorChar, '/'); string dir = ProjectMonitor.GetProjectDirectory(p); ProcessReturn ret = GitWrapper.Log(dir, String.Format("-- \"{0}\"", filename)); string[] commits = SentenceFilter.SplitLines(ret.Output.Trim()); if (ret.ReturnValue != 0 || commits.Length == 0) { throw new InvalidRepositoryException(p); } fileData = new Dictionary<string, string>(); hashes = new List<string>(); fullpath = Util.PathCombine(dir, filename); fileData[""] = Util.ReadFile(fullpath); hashes.Add(""); var timestamp = (int)(File.GetLastWriteTimeUtc(fullpath) - epoch).TotalSeconds; fileHistory.Items.Add(CreateListViewItem("", "Current Version", "", timestamp)); int cIndex = 1; int? hashIndex = null; foreach (var commit in commits) { var match = Regex.Match(commit, "^([a-z0-9]+) '(.*?)' ([0-9]+) (.*)$"); if (match.Success) { hashes.Add(match.Groups[1].Value); if (match.Groups[1].Value == hash) { hashIndex = cIndex; } cIndex++; fileHistory.Items.Add(CreateListViewItem(match.Groups[1].Value, match.Groups[4].Value, match.Groups[2].Value, int.Parse(match.Groups[3].Value))); } } if (hash != null && hashIndex == null) { MessageBox.Show("Could not find that version of the file. You may have to update the project.", "Version not found"); } fileHistory.SelectedIndex = hashIndex ?? 0; fileHistory.ScrollIntoView(fileHistory.Items[fileHistory.SelectedIndex]); fileHistory.Focus(); }
public bool UploadProject(Project p, Window window, BackgroundWorker worker, bool progress = true) { LockProject(p.id); string dir = GetProjectDirectory(p); bool committed = false, success = false; string commitMsg = null; try { if (worker.CancellationPending) return false; Project updatedProject; lock (projects) { updatedProject = projects.Find(pr => pr.id == p.id); } if (!updatedProject.can_write) { window.Dispatcher.Invoke(new Action(() => MessageBox.Show(window, "You don't have write access to this project.", "Not Authorized") )); return false; } while (true) { worker.ReportProgress(progress ? 25 : -1, "First, checking for updates..."); if (!UpdateProject(p, window, worker, false)) { return false; } if (worker.CancellationPending) return false; GitWrapper.AddAll(dir); worker.ReportProgress(progress ? 50 : -1, "Saving your changes..."); ProcessReturn ret = CheckReturn("status", GitWrapper.Status(dir), worker); if (worker.CancellationPending) return false; if (ret.Stdout.Trim() != "") { if (commitMsg == null) { CommitForm commitForm = null; window.Dispatcher.Invoke(new Action(() => { commitForm = new CommitForm(p); commitForm.ShowDialog(); })); commitMsg = commitForm.savedMessage; if (commitMsg == null) { return false; } } CheckReturn("commit", GitWrapper.Commit(dir, commitMsg), worker); committed = true; if (worker.CancellationPending) return false; worker.ReportProgress(progress ? 75 : -1, "Uploading..."); ret = GitWrapper.Push(dir); worker.ReportProgress(-1, ret.Output); if (ret.ReturnValue == 0) { worker.ReportProgress(progress ? 100 : -1, "Upload successful."); break; } else if (ret.Output.Contains("non-fast-forward")) { if (worker.CancellationPending) return false; committed = false; CheckReturn("reset", GitWrapper.Reset(dir, "HEAD^"), worker); MessageBoxResult resp = MessageBoxResult.Cancel; window.Dispatcher.Invoke(new Action(() => resp = MessageBox.Show(window, "Additional updates must be merged in. Continue?", "Project Updated", MessageBoxButton.OKCancel))); if (resp == MessageBoxResult.Cancel) { return false; } } else if (ret.Output.Contains("not authorized")) { ShowError(window, "You don't have write access to this project anymore."); return false; } else { ShowError(window, "Could not connect to the SciGit servers. Please try again later."); return false; } } else { worker.ReportProgress(progress ? 100 : -1, "No changes to upload."); break; } } success = true; return true; } catch (Exception e) { throw e; } finally { if (!success && committed) { CheckReturn("reset", GitWrapper.Reset(dir, "HEAD^"), worker); } else if (success) { lock (editedProjects) { editedProjects.RemoveAll(pr => pr.id == p.id); } } UnlockProject(p.id); } }
public bool CheckProject(Project p) { string dir = GetProjectDirectory(p); if (!Directory.Exists(dir) || !Directory.Exists(Path.Combine(dir, ".git"))) { var result = Util.ShowMessageBox("Project " + p.name + " seems to be corrupted. Do you want SciGit to repair it?\r\n" + "You may want to back up your files first.", "Project corrupted", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { return InitializeProject(p); } return false; } return true; }
public static string GetProjectDirectory(Project p) { if (p.id == 0) { return Path.GetTempPath(); // for testing } return Util.PathCombine(GetProjectDirectory(), p.name); }
private void ProjectEdited(Project p) { if (!Settings.Default.AutoSave && (Settings.Default.NotifyMask & (int)NotifyFlags.NotifyUpload) != 0) { QueueBalloonTip("Project Edited", "You made changes to project " + p.name + ". Click to upload your changes...", CreateUploadProjectHandler(p)); } }
private void ProjectUpdated(Project p) { if (!Settings.Default.AutoUpdate && (Settings.Default.NotifyMask & (int)NotifyFlags.NotifyUpdate) != 0) { QueueBalloonTip("Project Updated", "Project " + p.name + " has been updated. Click to update the local version...", CreateUpdateProjectHandler(p)); } }
private void OpenFileHistory(Project p, string filename, string hash = null) { if (!projectMonitor.CheckProject(p)) return; string dir = ProjectMonitor.GetProjectDirectory(p); if (!File.Exists(Util.PathCombine(dir, filename))) { Util.ShowMessageBox("File " + filename + " does not exist. You may have to update the project.", "SciGit error"); } else { FileHistory fh = null; try { fh = new FileHistory(p, filename, hash); ShowTop(fh); } catch (InvalidRepositoryException) { if (fh != null) fh.Hide(); Util.ShowMessageBox("This file does not belong to a valid SciGit project.", "SciGit error"); } catch (Exception e) { if (fh != null) fh.Hide(); ErrorForm.Show(e); } } }
private void ProjectAdded(Project p) { if ((Settings.Default.NotifyMask & (int)NotifyFlags.NotifyAddDelete) != 0) { QueueBalloonTip("Project Added", "Project " + p.name + (p.can_write ? "" : " (read-only)") + " has been added. Click to open the project folder...", CreateOpenDirectoryHandler(p)); } }
private EventHandler CreateUploadProjectHandler(Project p) { return (s, e) => { var progressForm = new ProgressForm("Uploading " + p.name, (form, bw) => projectMonitor.UploadProject(p, form, bw)); ShowTop(progressForm); }; }
public static ProcessReturn Clone(string dir, Project p, string options = "") { return ExecuteCommand(String.Format("clone git@{0}:r{1} {2} " + options, ServerHost, p.id, EscapeShellArg(p.name)), dir); }
public bool UpdateProject(Project p, Window window, BackgroundWorker worker, bool progress = true) { LockProject(p.id); string dir = GetProjectDirectory(p); bool possibleCommit = false, rebaseStarted = false, success = false; ProcessReturn ret; try { if (worker.CancellationPending) return false; if (!Directory.Exists(dir)) { worker.ReportProgress(progress ? 25 : -1, "Repairing project..."); MessageBoxResult result = MessageBox.Show("Project " + p.name + " does not exist. Would you like to re-create it?", "Project does not exist", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { if (!InitializeProject(p)) { ShowError(window, "Could not obtain project from the SciGit servers. Please try again later."); } else { worker.ReportProgress(progress ? 100 : -1, "Repair and update successful."); return true; } } return false; } if (GitWrapper.RebaseInProgress(dir)) { GitWrapper.Rebase(dir, "--abort"); } if (worker.CancellationPending) return false; worker.ReportProgress(progress ? 25 : -1, "Checking for updates..."); ret = GitWrapper.Fetch(dir); worker.ReportProgress(-1, ret.Output); if (ret.ReturnValue != 0) { if (ret.Output.Contains("Not a git")) { MessageBoxResult res = MessageBox.Show("Project " + p.name + " seems to be corrupted. Do you want SciGit to repair it?\r\n" + "You may want to back up your files first.", "Project corrupted", MessageBoxButton.YesNo); if (res == MessageBoxResult.Yes) { string gitDir = Path.Combine(dir, ".git"); if (Directory.Exists(gitDir)) { Directory.Delete(gitDir, true); } worker.ReportProgress(progress ? 30 : -1, "Repairing project..."); if (!InitializeProject(p)) { ShowError(window, "Could not obtain project from the SciGit servers. Please try again later."); return false; } worker.ReportProgress(progress ? 35 : -1, "Checking for updates..."); ret = GitWrapper.Fetch(dir); worker.ReportProgress(-1, ret.Output); } else { return false; } } if (ret.ReturnValue != 0) { ShowError(window, "Could not connect to the SciGit servers. Please try again later."); return false; } } while (true) { if (worker.CancellationPending) return false; // Reset commits until we get to something in common with FETCH_HEAD. ret = CheckReturn("merge-base", GitWrapper.MergeBase(dir, "HEAD", "FETCH_HEAD"), worker); string baseCommit = ret.Stdout.Trim(); GitWrapper.Reset(dir, baseCommit); if (worker.CancellationPending) return false; // Make a temporary commit to facilitate merging. GitWrapper.AddAll(dir); worker.ReportProgress(-1, "Creating temporary commit..."); ret = GitWrapper.Commit(dir, "tempCommit " + DateTime.Now); possibleCommit = true; worker.ReportProgress(-1, ret.Output); if (worker.CancellationPending) return false; worker.ReportProgress(progress ? 50 : -1, "Merging..."); ret = GitWrapper.Rebase(dir, "FETCH_HEAD"); worker.ReportProgress(-1, ret.Output); if (ret.Output.Contains("Permission denied")) { // One of the files is open. // If the return value isn't 0, there was a merge conflict on top of this (so abort the rebase) if (ret.ReturnValue == 0) { GitWrapper.Reset(dir, baseCommit); } else { rebaseStarted = true; } var match = Regex.Match(ret.Output, "error: unable to unlink old '(.*)' \\(Permission denied\\)"); string file = ""; if (match.Success) { file = "(" + match.Groups[1].Value + ") "; } var resp = MessageBox.Show("One of the project files is currently open " + file + "and cannot be edited. " + "Please save and close your changes before continuing.", "File Locked", MessageBoxButton.OKCancel); if (resp == MessageBoxResult.Cancel) { return false; } if (rebaseStarted) GitWrapper.Rebase(dir, "--abort"); } else { break; } } if (ret.ReturnValue != 0) { rebaseStarted = true; if (worker.CancellationPending) return false; if (ret.Output.Contains("CONFLICT")) { MessageBoxResult resp = MessageBoxResult.Cancel; window.Dispatcher.Invoke( new Action(() => resp = MessageBox.Show(window, "Merge conflict(s) were detected. Would you like to resolve them now using the SciGit editor?\r\n" + "Please save any changes to open files before continuing.", "Merge Conflict", MessageBoxButton.OKCancel))); MergeResolver mr = null; Exception exception = null; if (resp == MessageBoxResult.OK) { window.Dispatcher.Invoke(new Action(() => { try { mr = new MergeResolver(p); mr.ShowDialog(); } catch (Exception e) { if (mr != null) mr.Hide(); exception = e; } })); } if (exception != null) throw new Exception("", exception); if (resp != MessageBoxResult.No && (mr == null || !mr.Saved)) { // Cancel the process here. return false; } else { GitWrapper.AddAll(dir); worker.ReportProgress(progress ? 75 : -1, "Continuing merge..."); ret = GitWrapper.Rebase(dir, "--continue"); worker.ReportProgress(-1, ret.Output); if (ret.ReturnValue != 0) { if (ret.Output.Contains("No changes")) { // The temp commit was effectively ignored. Just skip it. CheckReturn("rebase", GitWrapper.Rebase(dir, "--skip"), worker); } else { throw new Exception("rebase: " + ret.Output); } } worker.ReportProgress(progress ? 100 : -1, "Merge successful."); success = true; rebaseStarted = false; } } else { throw new Exception("rebase: " + ret.Output); } } else { worker.ReportProgress(progress ? 100 : -1, ret.Output.Contains("up to date") ? "No changes." : "Changes merged without conflict."); success = true; if (progress && !ret.Output.Contains("up to date")) { var result = MessageBox.Show("Project " + p.name + " was successfully updated. Would you like to view the changes?", "Project updated", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { window.Dispatcher.Invoke(new Action(() => { var ph = new ProjectHistory(p, "HEAD"); ph.Show(); })); } } } } catch (Exception e) { throw new Exception("", e); } finally { if (rebaseStarted) GitWrapper.Rebase(dir, "--abort"); if (possibleCommit) { // Reset commits until we get to something in common with FETCH_HEAD. ret = CheckReturn("merge-base", GitWrapper.MergeBase(dir, "HEAD", "FETCH_HEAD"), worker); CheckReturn("reset", GitWrapper.Reset(dir, ret.Stdout.Trim()), worker); } if (success) { lock (noAutoUpdateProjects) { noAutoUpdateProjects.Remove(p.id); } lock (updatedProjects) { updatedProjects.RemoveAll(pr => pr.id == p.id); } } UnlockProject(p.id); } return success; }
public bool HasUpload(Project p) { string dir = GetProjectDirectory(p); if (!Directory.Exists(dir)) return false; ProcessReturn ret = GitWrapper.Status(dir); return ret.Stdout.Trim() != ""; }
public bool HasUpdate(Project p) { string dir = GetProjectDirectory(p); if (!Directory.Exists(dir)) return false; ProcessReturn ret = GitWrapper.GetLastCommit(dir); string lastHash = ""; if (ret.ReturnValue == 0) { lastHash = ret.Stdout.Trim(); } return lastHash != p.last_commit_hash; }
private EventHandler CreateOpenDirectoryHandler(Project p) { return (s, e) => Process.Start(ProjectMonitor.GetProjectDirectory(p)); }
private bool AutoUpdateProject(Project p, bool notify = true) { LockProject(p.id); string dir = GetProjectDirectory(p); bool possibleCommit = false, rebaseStarted = false, success = false; ProcessReturn ret; try { if (!Directory.Exists(dir)) { if (!InitializeProject(p)) { return false; } return true; } if (GitWrapper.RebaseInProgress(dir)) { GitWrapper.Rebase(dir, "--abort"); } ret = GitWrapper.Fetch(dir); if (ret.ReturnValue != 0) { if (ret.Output.Contains("Not a git")) { MessageBoxResult res = MessageBox.Show("Project " + p.name + " seems to be corrupted. Do you want SciGit to repair it?\r\n" + "You may want to back up your files first.", "Project corrupted", MessageBoxButton.YesNo); if (res == MessageBoxResult.Yes) { string gitDir = Path.Combine(dir, ".git"); if (Directory.Exists(gitDir)) { Directory.Delete(gitDir, true); } if (!InitializeProject(p)) { return false; } ret = GitWrapper.Fetch(dir); } else { DisableAutoUpdates(p); } } if (ret.ReturnValue != 0) { return false; } } while (true) { // Reset commits until we get to something in common with FETCH_HEAD. ret = CheckReturn("merge-base", GitWrapper.MergeBase(dir, "HEAD", "FETCH_HEAD")); string baseCommit = ret.Stdout.Trim(); GitWrapper.Reset(dir, baseCommit); // Make a temporary commit to facilitate merging. GitWrapper.AddAll(dir); ret = GitWrapper.Commit(dir, "tempCommit " + DateTime.Now); possibleCommit = true; ret = GitWrapper.Rebase(dir, "FETCH_HEAD"); if (ret.Output.Contains("Permission denied")) { // One of the files is open. // If the return value isn't 0, there was a merge conflict on top of this (so abort the rebase) if (ret.ReturnValue == 0) { GitWrapper.Reset(dir, baseCommit); } else { rebaseStarted = true; } var match = Regex.Match(ret.Output, "error: unable to unlink old '(.*)' \\(Permission denied\\)"); string file = ""; if (match.Success) { file = " (" + match.Groups[1].Value + ")"; } var resp = Util.ShowMessageBox("Project " + p.name + " cannot be updated, as one of the project files is currently open" + file + ".\n" + "Please save and close your changes before continuing.", "File Locked", MessageBoxButtons.RetryCancel); if (resp == DialogResult.Cancel) { DisableAutoUpdates(p); return false; } if (rebaseStarted) GitWrapper.Rebase(dir, "--abort"); } else { break; } } if (ret.ReturnValue != 0) { rebaseStarted = true; if (ret.Output.Contains("CONFLICT")) { var resp = Util.ShowMessageBox("Merge conflict(s) were detected in project " + p.name + ". Would you like to resolve them now using the SciGit editor?\r\n" + "Please save any changes to open files before continuing.", "Auto-update: merge conflict", MessageBoxButtons.OKCancel); MergeResolver mr = null; Exception exception = null; if (resp == DialogResult.OK) { parent.Invoke(new Action(() => { try { mr = new MergeResolver(p); mr.ShowDialog(); } catch (Exception e) { if (mr != null) mr.Hide(); exception = e; } })); } if (exception != null) throw new Exception("", exception); if (mr == null || !mr.Saved) { DisableAutoUpdates(p); return false; } else { GitWrapper.AddAll(dir); ret = GitWrapper.Rebase(dir, "--continue"); if (ret.ReturnValue != 0) { if (ret.Output.Contains("No changes")) { // The temp commit was effectively ignored. Just skip it. CheckReturn("rebase", GitWrapper.Rebase(dir, "--skip")); } else { throw new Exception("rebase: " + ret.Output); } } success = true; rebaseStarted = false; } } else { throw new Exception("rebase: " + ret.Output); } } else { success = true; if (!ret.Output.Contains("up to date") && notify) { DispatchCallbacks(projectAutoUpdatedCallbacks, p); } } } catch (Exception e) { return false; } finally { if (rebaseStarted) GitWrapper.Rebase(dir, "--abort"); if (possibleCommit) { // Reset commits until we get to something in common with FETCH_HEAD. ret = CheckReturn("merge-base", GitWrapper.MergeBase(dir, "HEAD", "FETCH_HEAD")); CheckReturn("reset", GitWrapper.Reset(dir, ret.Stdout.Trim())); } if (success) { lock (updatedProjects) { updatedProjects.RemoveAll(pr => pr.id == p.id); } } UnlockProject(p.id); } return success; }
private EventHandler CreateViewProjectHistoryHandler(Project p, string hash = null) { return (s, e) => { if (!projectMonitor.CheckProject(p)) return; var ph = new ProjectHistory(p, hash); ShowTop(ph); }; }
private void AutoUploadProject(Project p) { LockProject(p.id); string dir = GetProjectDirectory(p); bool committed = false, success = false; try { Project updatedProject; lock (projects) { updatedProject = projects.Find(pr => pr.id == p.id); } if (!updatedProject.can_write) { return; } while (true) { if (!AutoUpdateProject(p, false)) { return; } GitWrapper.AddAll(dir); ProcessReturn ret = CheckReturn("status", GitWrapper.Status(dir)); if (ret.Stdout.Trim() != "") { CheckReturn("commit", GitWrapper.Commit(dir, "autocommit")); committed = true; ret = GitWrapper.Push(dir); if (ret.ReturnValue == 0) { break; } else if (ret.Output.Contains("non-fast-forward")) { committed = false; CheckReturn("reset", GitWrapper.Reset(dir, "HEAD^")); // have to update; repeat the loop return; } else { return; } } else { break; } } success = true; messageCallback("Auto-save successful", "Changes to project " + p.name + " were uploaded successfully."); } catch (Exception e) { return; } finally { if (!success && committed) { GitWrapper.Reset(dir, "HEAD^"); } else if (success) { lock (editedProjects) { editedProjects.RemoveAll(pr => pr.id == p.id); } } UnlockProject(p.id); } }
private void OpenProjectHistory(Project p, string hash = null) { if (!projectMonitor.CheckProject(p)) return; string dir = ProjectMonitor.GetProjectDirectory(p); if (!Directory.Exists(dir)) { Util.ShowMessageBox("Project does not exist.", "Error"); } else { ProjectHistory ph = null; try { ph = new ProjectHistory(p, hash); ShowTop(ph); } catch (InvalidRepositoryException) { if (ph != null) ph.Hide(); Util.ShowMessageBox("This file does not belong to a valid SciGit project.", "Error"); } catch (Exception e) { if (ph != null) ph.Hide(); ErrorForm.Show(e); } } }
private void DisableAutoUpdates(Project p) { Util.ShowMessageBox("This project will not be automatically synced until the issue has been resolved.\n" + "Please manually update the project by right-clicking on the tray icon or the project folder to try again.", "Error updating project"); lock (noAutoUpdateProjects) { noAutoUpdateProjects.Add(p.id); } }
private void ProjectAutoUpdated(Project p) { if ((Settings.Default.NotifyMask & (int)NotifyFlags.NotifyUpdate) != 0) { QueueBalloonTip("Project Updated", "Project " + p.name + " has been successfully auto-updated. Click to view changes...", CreateViewProjectHistoryHandler(p, "HEAD")); } }
private void DispatchCallbacks(List<ProjectCallback> callbacks, Project p) { foreach (var callback in callbacks) { callback(p); } }
private void ProjectRemoved(Project p) { if ((Settings.Default.NotifyMask & (int)NotifyFlags.NotifyAddDelete) != 0) { QueueBalloonTip("Project Removed", "You are no longer receiving updates for project " + p.name + ". Click to open the project folder...", CreateOpenDirectoryHandler(p)); } }
private bool InitializeProject(Project p) { string dir = GetProjectDirectory(); string pdir = Util.PathCombine(dir, p.name); ProcessReturn ret; lock (projectLocks) { if (!projectLocks.ContainsKey(p.id)) { projectLocks.Add(p.id, new Mutex()); } } LockProject(p.id); try { if (Directory.Exists(pdir)) { if (!Directory.Exists(Util.PathCombine(pdir, ".git"))) { // Re-generate the .git directory only. Make a clone in a temp directory: string tempPath = Path.Combine(Util.GetTempPath(), p.name); if (Directory.Exists(tempPath)) { Directory.Delete(tempPath, true); } ret = GitWrapper.Clone(Util.GetTempPath(), p, "-n"); if (ret.ReturnValue != 0) return false; Directory.Move(Path.Combine(tempPath, ".git"), Path.Combine(pdir, ".git")); return true; } else { return false; } } ret = GitWrapper.Clone(dir, p); if (ret.ReturnValue != 0) return false; dir = GetProjectDirectory(p); File.WriteAllText(Util.PathCombine(dir, ".git", "info", "attributes"), "* -merge -diff"); // Ignore some common temporary files. string[] exclude = new string[] {"*~", "~*", "*.tmp", "*.scigitUpdated*", "*.swp"}; File.WriteAllText(Util.PathCombine(dir, ".git", "info", "exclude"), String.Join("\n", exclude)); return true; } catch (Exception ex) { Logger.LogException(ex); return false; } finally { UnlockProject(p.id); } }
public InvalidRepositoryException(Project p) { Project = p; }
public MergeResolver(Project p) { InitializeComponent(); Style = (Style)FindResource(typeof(Window)); Title += " for " + p.name; project = p; if (p.id == 0) { string orig_big = "", my_big = "", new_big = ""; for (int i = 0; i < 25; i++) { orig_big += "a\na\n"; my_big += "b\na\n"; new_big += "c\na\n"; } unmergedFiles = new List<FileData> { new FileData { filename = "file.txt", original = "Sentence one.\nSentence two. Sentence three. Sentence four.\nSome crap after\na change\netc\nanother conflict\n", myVersion = "Sentence one.\nSentence two. Sentence threea.\nPlus a newline. Sentence four.\nSome crap after\na change\netc\nanother disagreement\n", newVersion = "Sentence one.\nSentence two. Sentence threeb. Sentence four.\nSome crap after\na small change\netc\nanother difference\n" }, new FileData { filename = "bin_file.txt", original = "\007Sentence one.\nSentence two. Sentence three. Sentence four.\nSome crap after\na change\netc\nanother conflict\n", myVersion = null, newVersion = "\007Sentence one.\nSentence two. Sentence threeb. Sentence four.\nSome crap after\na small change\netc\nanother difference\n" }, new FileData { filename = "file.docx", original = "\007Sentence one.\nSentence two. Sentence three. Sentence four.\nSome crap after\na change\netc\nanother conflict\n", myVersion = "\007x", //File.ReadAllText("C:\\temp\\a.docx", Encoding.Default), newVersion = "\007y" //File.ReadAllText("C:\\temp\\b.docx", Encoding.Default) }, new FileData { filename = "big_file.txt", original = orig_big, myVersion = my_big, newVersion = new_big }, new FileData { filename = "added_file.txt", original = null, myVersion = "Sentence one.\nSentence two. Sentence threea.\nPlus a newline. Sentence four.\nSome crap after\na change\netc\nanother disagreement\n", newVersion = "Sentence one.\nSentence two. Sentence threeb. Sentence four.\nSome crap after\na small change\netc\nanother difference\n" }, new FileData { filename = "my_deletion.txt", original = "Sentence one.\nSentence two. Sentence three. Sentence four.\nSome crap after\na change\netc\nanother conflict\n", myVersion = null, newVersion = "Sentence one.\nSentence two. Sentence threeb. Sentence four.\nSome crap after\na small change\netc\nanother difference\n" }, new FileData { filename = "their_deletion.txt", original = "Sentence one.\nSentence two. Sentence three. Sentence four.\nSome crap after\na change\netc\nanother conflict\n", myVersion = "Sentence one.\nSentence two. Sentence threea.\nPlus a newline. Sentence four.\nSome crap after\na change\netc\nanother disagreement\n", newVersion = null } }; } else { unmergedFiles = GetUnmergedFiles(); } diffViewerMap = new Dictionary<string, MergeViewer>(); updated = new List<string>(); created = new List<string>(); deleted = new List<string>(); for (int i = 0; i < unmergedFiles.Count; i++) { CreateDiffViewer(unmergedFiles[i]); } updated.Sort(); created.Sort(); deleted.Sort(); combined = new List<string>(updated); combined.AddRange(created); combined.AddRange(deleted); diffViewers = new List<MergeViewer>(combined.Select(name => diffViewerMap[name])); var unmergedMap = unmergedFiles.ToDictionary(x => x.filename); unmergedFiles = new List<FileData>(combined.Select(name => unmergedMap[name])); foreach (var name in updated) { fileListing.AddFile(0, name); } foreach (var name in created) { fileListing.AddFile(1, name); } foreach (var name in deleted) { fileListing.AddFile(2, name); } fileListing.SelectionHandlers.Add(SelectFilename); active = 0; diffViewers[active].Visibility = Visibility.Visible; SetActiveFile(active); if (unmergedFiles.Count <= 1) { nextFile.IsEnabled = false; } }