public Task ExecuteAsync(object?parameter = null, CancellationToken cancellation = default) { if (changes.GetMarkedEntries().Any() || Amend) { foreach (var submoduleEntry in changes.GetMarkedEntries(true)) { var submodule = repository.Submodules.FirstOrDefault(x => x.Path == submoduleEntry.FilePath); if (submodule != null) { using (var subRepo = new Repository(Path.Combine(repository.Info.WorkingDirectory, submodule.Path))) { var status = subRepo.RetrieveStatus(); var entries = status.Added .Concat(status.Removed) .Concat(status.Modified) .Concat(status.Untracked) .Concat(status.Missing); Commit(subRepo, entries, string.Format("Commit Submodule {0}", submodule.Name)); } } } Commit(repository, changes.GetMarkedEntries(), reportProgress: true); mainThread.Invoke(() => changes.Refresh()); } return(Task.CompletedTask); }
public Task ExecuteAsync(object?parameter = null, CancellationToken cancellation = default) { var dialog = new MessageBox( string.Format("Reset"), DialogBoxButton.Ok | DialogBoxButton.Cancel, "We will (hard) reset the current checked out branch to its corresponding remote tip"); if (mainThread.Invoke(() => dialog.ShowDialog()) == true) { foreach (var(config, repository, index) in repositories.Select((config, index) => (config, config.Repository, index))) { repository.Fetch(credentials, prune: true); if (repository.GetBranch(config.TargetBranchRemote) is Branch targetBranchRemote) { repository.Reset(ResetMode.Hard, targetBranchRemote.Tip); eventStream.Push(Status.Create( (index + 1) / (float)repositories.Count(), "Resetting {0} to {1}...", repository.GetName(), targetBranchRemote.FriendlyName)); } } eventStream.Push(Status.Succeeded()); mainThread.Invoke(() => view.Refresh()); } return(Task.CompletedTask); }
public Task ExecuteAsync(CancellationToken cancellation = default) { var entries = view.MarkedEntries.ToList(); if (entries.Any()) { var dialog = new MessageBox( string.Format("Ignore Commits"), DialogBoxButton.Ok | DialogBoxButton.Cancel, string.Format("We will ignore and add the selected {0} commit(s) into the {1} file", entries.Count(), Constants.NoCherryPick)); if (mainThread.Invoke(() => dialog.ShowDialog()) == true) { // Create the file if it does not exist var ignoreCommitsLines = File.Exists(Constants.NoCherryPick) ? File.ReadAllLines(Constants.NoCherryPick).ToList() : new List <string>(); // Iterate marked entries by repository foreach (var selectedEntry in entries.GroupBy(x => x.Config)) { // This is how it looks the ignore in the config file // // [repository "$(RepoName)"] // ignore = $(CommitUrl) // var repoSection = $"[repository \"{selectedEntry.Key.Repository.GetName()}\"]"; var ignores = selectedEntry.Select(commitEntry => $"\tignore = {selectedEntry.Key.Repository.GetRepoUrl() + $"/commit/{commitEntry.Commit.Sha}"}"); // Search if the section already exists in the file var existingRepoSection = ignoreCommitsLines.FirstOrDefault(x => string.Compare(x, repoSection, CultureInfo.CurrentCulture, System.Globalization.CompareOptions.IgnoreSymbols) == 0); if (string.IsNullOrEmpty(existingRepoSection)) { ignoreCommitsLines.Add(repoSection); } else { repoSection = existingRepoSection; } // Insert the new ignores ignoreCommitsLines.InsertRange(ignoreCommitsLines.IndexOf(repoSection) + 1, ignores); // Update the CherryPickConfig selectedEntry.Key.IgnoreCommits = selectedEntry.Key.IgnoreCommits.Concat(ignores); } // And write the ignored commits File.WriteAllLines(Constants.NoCherryPick, ignoreCommitsLines); mainThread.Invoke(() => view.Refresh()); } } return(Task.CompletedTask); }
public Task ExecuteAsync(object?parameter = null, CancellationToken cancellation = default) { var dirtyRepositories = repositories .Select(config => ( config, targetBranch: config.Repository.GetBranch(config.TargetBranch), targetBranchRemote: config.Repository.GetBranch(config.TargetBranchRemote))) .Where(x => x.targetBranch != null && x.targetBranch.Tip != x.targetBranchRemote?.Tip) .Select(x => (x.config.Repository.GetName(), x.config.TargetBranchRemote + $"-merge-{x.targetBranch.Tip.GetShortSha()}")); if (dirtyRepositories.Any()) { var dialog = new PushDialog(dirtyRepositories.ToArray()); if (mainThread.Invoke(() => dialog.ShowDialog()) == true) { foreach (var branch in dialog.Branches) { if (branch.BranchName?.Contains('/') == true && repositories.FirstOrDefault(x => x.Repository.GetName() == branch.Repo) is CherryPickConfig config) { var repository = config.Repository; var remoteName = branch.BranchName.Substring(0, branch.BranchName.IndexOf('/')); if (repository.Network.Remotes.FirstOrDefault(x => x.Name == remoteName) is Remote remote) { var targetBranchName = branch.BranchName.Substring(remoteName.Length + 1); // Push config.Repository.Network.Push( repository.Network.Remotes.Single(x => x.Name == "origin"), $"refs/heads/{repository.Head.FriendlyName}:refs/heads/{targetBranchName}", new PushOptions { CredentialsProvider = credentials }); eventStream.Push(Status.Create("Pushed changes to {0}", $"{repository.GetRepoUrl()}/tree/{targetBranchName}")); Process.Start("cmd", $"/c start {repository.GetRepoUrl()}/compare/{config.TargetBranch}...{targetBranchName}"); mainThread.Invoke(() => view.Refresh()); } else { mainThread.Invoke(() => new MessageBox("Error", "Remote '{0}' not found for '{1}'", remoteName, branch.BranchName).ShowDialog()); } } } } } return(Task.CompletedTask); }
private static Task StartCoroutineAsTask(IEnumerator iEnum) { var tcs = new TaskCompletionSource <bool>(); MainThread.Invoke(() => { MainThread.instance.StartCoroutineAsTask(tcs, iEnum, () => true); }); return(tcs.Task); }
public async Task ExecuteAsync(object?parameter = null, CancellationToken cancellation = default) { foreach (var repositoryEntries in view.MarkedEntries.GroupBy(x => x.Config).Where(x => x.Any())) { var config = repositoryEntries.Key; var repository = config.Repository; var dialog = new MessageBox( string.Format("{0} ({1} -> {2})", config.Repository.GetName(), config.BaseBranch, config.TargetBranch), DialogBoxButton.Ok | DialogBoxButton.Cancel, string.Format("We will cherry pick the selected {0} commit(s) into the following branch: {1}", repositoryEntries.Count(), config.TargetBranch)); if (mainThread.Invoke(() => dialog.ShowDialog()) == true) { var targetBranch = repository.SwitchToTargetBranch(config); var count = 0; foreach (var entry in repositoryEntries.Reverse()) { var result = repository.CherryPick(entry.Commit, repository.Config.BuildSignature(DateTimeOffset.Now)); if (result.Status == CherryPickStatus.Conflicts) { await commandService.RunAsync(WellKnownCommands.ResolveConflicts, cancellation : cancellation); if (repository.Index.Conflicts.Any()) { repository.Reset(ResetMode.Hard); throw new InvalidOperationException(string.Format("Unable to cherry pick {0}", entry.Commit.MessageShort)); } else { // TODO: auto-commit, keep moving } eventStream.Push(Status.Create(++count / (float)repositoryEntries.Count(), "Cherry picking {0} {1}", entry.Commit.GetShortSha(), entry.Commit.MessageShort)); } else { eventStream.Push(Status.Create(++count / (float)repositoryEntries.Count(), "Cherry picking {0} {1}", entry.Commit.GetShortSha(), entry.Commit.MessageShort)); } } mainThread.Invoke(() => view.Refresh()); } } }
private static Task StartCoroutineAsTask(IEnumerator iEnum) { AssertV2.IsTrue(ApplicationV2.isPlaying, "In EDIT mode!"); var tcs = new TaskCompletionSource <bool>(); MainThread.Invoke(() => { MainThread.instance.StartCoroutineAsTask(tcs, iEnum, () => true); }); return(tcs.Task); }
public void Main() { MySocket = new Socket(); SocketConnectedObserver = new TargettedObserver <bool>(() => MySocket.Connected); SocketConnectedObserver.ValueChanged += ReportSocketConnectedStateChanged; PerformSocketConnection(); MainThread.Invoke(PollSocketValue); }
private void StartCounting() { mTask = Task.Delay(mGameView.TimeToStepDown * 1000).ContinueWith(t => { if (!mGameOver) { MainThread.Invoke(StepDown); } }); }
/// <summary> /// Add a log entry in a thread-safe manner by calling self from main thread if necessary. /// </summary> /// <param name="entry">The text of the log entry.</param> /// <param name="error">True if the text should appear highlighted red.</param> private static void ThreadSafeAddEntry(string entry, bool error) { if (MainThread != null && MainThread.InvokeRequired) // we are in a different thread to the main window { MainThread.Invoke(new AddEntryDelegate(ThreadSafeAddEntry), new object[] { entry, error }); // call self from main thread } else if (OnNewLogEntry != null) { OnNewLogEntry(entry, error); } }
public Task ExecuteAsync(CancellationToken cancellation = default) { if (CanExecute()) { CommitSubmodules(); CommitChanges(repository, view.GetMarkedEntries(), CreateDialog()); mainThread.Invoke(() => view.Refresh()); } return(Task.CompletedTask); }
public Task ExecuteAsync(object?parameter = null, CancellationToken cancellation = default) { if (view.SelectedEntry is CommitEntry selectedEntry) { var dialog = new ResetDialog(string.Format("Reset current branch {0} to {1}?", selectedEntry.Repository.Head.GetName(), selectedEntry.Commit.GetShortSha())); if (mainThread.Invoke(() => dialog.ShowDialog()) == true) { repository.Reset(dialog.ResetMode, view.SelectedEntry.Commit); view.Refresh(); } } return(Task.CompletedTask); }
public Task ExecuteAsync(CancellationToken cancellation = default) { foreach (var(config, index) in repositories.Select((config, index) => (config, index))) { eventStream.Push(Status.Create((index + 1) / (float)repositories.Count(), "Fetching {0}...", config.Repository.GetName())); config.Repository.Fetch(credentials, prune: true); } ; eventStream.Push(Status.Succeeded()); mainThread.Invoke(() => view.Refresh()); return(Task.CompletedTask); }
public Task ExecuteAsync(object?parameter = null, CancellationToken cancellation = default) { var entries = changes.GetMarkedEntries().ToList(); if (entries.Any()) { var dialog = new MessageBox("Revert Changes", string.Format("Are you sure you want to revert {0} item(s)?", entries.Count)); var dialogResult = mainThread.Invoke(() => dialog.ShowDialog()); if (dialogResult == true) { foreach (var entry in entries) { switch (entry.State) { case FileStatus.ModifiedInWorkdir: { var submodule = repository.Submodules.FirstOrDefault(x => x.Path == entry.FilePath); if (submodule != null) { using (var subRepo = new Repository(Path.Combine(repository.Info.WorkingDirectory, submodule.Path))) subRepo.Reset(ResetMode.Hard, subRepo.Head.Tip); repository.Submodules.Update(submodule.Name, new SubmoduleUpdateOptions()); } else { repository.RevertFileChanges(entry.FilePath); } break; } case FileStatus.NewInWorkdir: repository.Remove(entry.FilePath); break; } } changes.Refresh(); } } return(Task.CompletedTask); }
public Task ExecuteAsync(CancellationToken cancellation = default) { if (config != null) { var dialog = new InputBox( "Select Branch", "Cherry pick from:", config.Repository.Branches.Select(x => x.FriendlyName).ToArray()) { Text = config.BaseBranch ?? string.Empty }; if (mainThread.Invoke(() => dialog.ShowDialog()) == true) { config.BaseBranch = dialog.Text; view.Refresh(false); } } return(Task.CompletedTask); }
public IEnumerator TestMainThread() { GameObject go = null; var task = TaskRunner.instance.RunInBackground(delegate { // Test that its not be possible to create a GO in a background thread: AssertV2.Throws <Exception>(() => { go = new GameObject(name: "A"); }); // Test that on MainThread the gameobject can be created: MainThread.Invoke(() => { go = new GameObject(name: "B"); }); Thread.Sleep(1000); // wait for main thread action to execute Assert.IsTrue(go != null); // Assert.AreEqual("B", go.name); // go.name not allowed in background thread Log.d("Background thread now done"); }).task; Assert.IsNull(go); yield return(task.AsCoroutine()); task.ThrowIfException(); Assert.IsNotNull(go); Assert.AreEqual("B", go.name); }
public IEnumerator TestMainThread() { var queue = BackgroundTaskQueue.NewBackgroundTaskQueue(1); GameObject go = null; var task = queue.Run(async(cancel) => { cancel.ThrowIfCancellationRequested(); // Test that its not be possible to create a GO in a background thread: AssertV2.Throws <Exception>(() => { go = new GameObject(name: "A"); }); // Test that on MainThread the gameobject can be created: MainThread.Invoke(() => { go = new GameObject(name: "B"); }); await TaskV2.Delay(1000); // wait for main thread action to execute Assert.IsTrue(go != null); // Assert.AreEqual("B", go.name); // go.name not allowed in background thread Log.d("Background thread now done"); }); Assert.IsNull(go); yield return(task.AsCoroutine()); task.ThrowIfException(); Assert.IsNotNull(go); Assert.AreEqual("B", go.name); }
public Task ExecuteAsync(CancellationToken cancellation = default) { mainThread.Invoke(() => new ResolveConflictsDialog(repository, commands).ShowDialog()); return(Task.CompletedTask); }
private void PollSocketValue() { SocketConnectedObserver.CheckValue(); MainThread.Invoke(PollSocketValue); }
public Task ExecuteAsync(object?parameter = null, CancellationToken cancellation = default) { var dialog = new SwitchDialog(branches: repository.Branches.Select(x => x.FriendlyName).OrderBy(x => x).ToArray()); if (mainThread.Invoke(() => dialog.ShowDialog()) == true && !string.IsNullOrEmpty(dialog.Branch)) { var branch = repository.Branches.FirstOrDefault(x => x.FriendlyName == dialog.Branch); var targetBranch = branch; var targetBranchName = dialog.Branch; var overwriteTargetBranch = false; // Check if the selected branch is remote if (branch?.IsRemote == true) { // Get the branch name from the remote targetBranchName = branch.GetName(); // Allow the user to create a branch for the remote var createBranchDialog = new InputBox("Create Branch", "Branch") { Text = targetBranchName }; if (mainThread.Invoke(() => createBranchDialog.ShowDialog()) == true) { // Check if the new branch already exists targetBranchName = createBranchDialog.Text; targetBranch = repository.Branches.FirstOrDefault(x => !x.IsRemote && x.FriendlyName == createBranchDialog.Text); if (targetBranch != null) { // The branch already exist => ask the user to overwrite it var forceDialog = new MessageBox( "Warning", DialogBoxButton.Ok | DialogBoxButton.Cancel, "A branch with this name already exists. Do you want to overwrite it?"); overwriteTargetBranch = mainThread.Invoke(() => forceDialog.ShowDialog() == true); if (!overwriteTargetBranch) { return(CancelCheckout()); } } } else { return(CancelCheckout()); } } // 1. Check the remote branch if remote was selected if (branch?.IsRemote == true) { repository.Checkout(branch); } // 2. Remove the existing branch if the user decided to overwrite it if (overwriteTargetBranch && targetBranch != null) { eventStream.Push(Status.Create(0.2f, "Removing branch {0}", targetBranch.FriendlyName)); repository.Branches.Remove(targetBranch); } // 3. Create the branch if it does not exist if (targetBranch == null) { eventStream.Push(Status.Create(0.4f, "Creating branch {0}", targetBranchName)); targetBranch = repository.CreateBranch(targetBranchName); } // 4. Checkout the branch eventStream.Push(Status.Create(0.6f, "Swithing to branch {0}", targetBranchName)); repository.Checkout(targetBranch); // 5. Update submodules if (dialog.UpdateSubmodules) { eventStream.Push(Status.Create(0.8f, "Updating submodules...")); repository.UpdateSubmodules(eventStream: eventStream); } eventStream.Push(new BranchChanged(targetBranchName)); eventStream.Push(Status.Succeeded()); } return(Task.CompletedTask); }
public async Task ExecuteAsync(object?parameter = null, CancellationToken cancellation = default) { var repositoryStatus = repository.RetrieveStatus(); var localBranch = repository.Head; var targetBranch = repository.Head.TrackedBranch ?? repository.Head; var dialog = new PullDialog( targetBranch.RemoteName ?? repository.GetDefaultRemoteName(), targetBranch.GetName(), showStashWarning: repositoryStatus.IsDirty, trackRemoteBranch: false, remotes: repository.GetRemoteNames(), branches: repository.GetBranchNames()); if (mainThread.Invoke(() => dialog.ShowDialog()) == true && !string.IsNullOrEmpty(dialog.Branch)) { var targetBranchFriendlyName = string.IsNullOrEmpty(dialog.Remote) ? dialog.Branch : $"{dialog.Remote}/{dialog.Branch}"; targetBranch = repository.Branches.FirstOrDefault(x => x.FriendlyName == targetBranchFriendlyName); if (targetBranch == null) { throw new InvalidOperationException(string.Format("Branch {0} not found", targetBranchFriendlyName)); } eventStream.Push(Status.Start("Pull {0} {1}", targetBranchFriendlyName, dialog.IsFastForward ? "With Fast Fordward" : string.Empty)); var stash = default(Stash); var mergeResult = default(MergeResult); var stashResult = default(StashApplyStatus); // 1. Fetch if (targetBranch.IsRemote) { TryFetch(targetBranch); } // 2. Stash (optional, if the repo is dirty) and Merge try { if (repositoryStatus.IsDirty) { stash = repository.Stashes.Add(Signatures.GetStashSignature(), StashModifiers.IncludeUntracked); } mergeResult = Merge(targetBranch, dialog.IsFastForward); } finally { if (stash != null && repository.Stashes.Contains(stash) && !repository.RetrieveStatus().IsDirty) { stashResult = repository.Stashes.Pop(repository.Stashes.ToList().IndexOf(stash)); } } // 3. Resolve conflicts if (mergeResult?.Status == MergeStatus.Conflicts) { await commandService.RunAsync("ResolveConflicts"); } // 4. Track if (dialog.TrackRemoteBranch) { localBranch.Track(repository, targetBranch); } // 5. Update submodules if (dialog.UpdateSubmodules) { eventStream.Push(Status.Create(0.8f, "Updating submodules...")); repository.UpdateSubmodules(eventStream: eventStream); } eventStream.Push(Status.Finish(mergeResult.Status.ToString())); mainThread.Invoke(() => view.Refresh()); } }
public HelpCommand(MainThread mainThread, [ImportMany] IEnumerable <Lazy <ContentView, MenuCommandMetadata> > views, [ImportMany] IEnumerable <Lazy <IMenuCommand, MenuCommandMetadata> > commands) : base(() => mainThread.Invoke(() => new HelpDialog(views, commands).ShowDialog())) { }
public IEnumerator TestMainThread2() { Assert.IsTrue(MainThread.instance.enabled); MainThread.Invoke(() => { Assert.IsTrue(Application.isPlaying); }); yield return(null); }
public Task ExecuteAsync(CancellationToken cancellation = default) { var localBranch = repository.Head; var targetBranch = repository.Head.TrackedBranch ?? repository.Head; var dialog = new PushDialog( targetBranch.RemoteName ?? repository.GetDefaultRemoteName(), targetBranch.GetName(), trackRemoteBranch: repository.Head.TrackedBranch != null, remotes: repository.GetRemoteNames(), branches: repository.GetBranchNames()); var result = mainThread.Invoke(() => dialog.ShowDialog()); if (result == true && !string.IsNullOrEmpty(dialog.Remote)) { var remote = repository .Network .Remotes .FirstOrDefault(x => x.Name == dialog.Remote); if (remote != null) { var pushRefSpec = $"refs/heads/{localBranch.GetName()}:refs/heads/{dialog.Branch}"; if (dialog.Force) { pushRefSpec = "+" + pushRefSpec; } var pushOptions = new PushOptions() { CredentialsProvider = credentialsProvider, OnPushTransferProgress = (current, total, bytes) => { eventStream.Push <Status>((float)current / (float)total); return(true); } }; eventStream.Push(Status.Start("git push {0} {1}", dialog.Remote, pushRefSpec)); repository.Network.Push(remote, pushRefSpec, pushOptions); if (dialog.TrackRemoteBranch) { var trackedBranch = repository.Branches.FirstOrDefault(x => x.RemoteName == dialog.Remote && x.GetName() == dialog.Branch); if (trackedBranch != null) { localBranch.Track(repository, trackedBranch); } } eventStream.Push(Status.Succeeded()); mainThread.Invoke(() => view.Refresh()); } } return(Task.CompletedTask); }