private void SwitchBranch(string branch) { if (EditorUtility.DisplayDialog(ConfirmSwitchTitle, String.Format(ConfirmSwitchMessage, branch), ConfirmSwitchOK, ConfirmSwitchCancel)) { Repository.SwitchBranch(branch) .FinallyInUI((success, e) => { if (success) { UsageTracker.IncrementBranchesViewButtonCheckoutLocalBranch(); Redraw(); AssetDatabase.Refresh(); } else { EditorUtility.DisplayDialog(Localization.SwitchBranchTitle, String.Format(Localization.SwitchBranchFailedDescription, branch), Localization.Ok); } }).Start(); } }
private void Commit() { isBusy = true; var files = treeChanges.GetCheckedFiles().ToList(); ITask addTask = null; if (files.Count == gitStatusEntries.Count) { addTask = Repository.CommitAllFiles(commitMessage, commitBody); } else { ITask commit = Repository.CommitFiles(files, commitMessage, commitBody); // if there are files that have been staged outside of Unity, but they aren't selected for commit, remove them // from the index before commiting, otherwise the commit will take them along. var filesStagedButNotChecked = gitStatusEntries.Where(x => x.Staged).Select(x => x.Path).Except(files).ToList(); if (filesStagedButNotChecked.Count > 0) { addTask = GitClient.Remove(filesStagedButNotChecked); } addTask = addTask == null ? commit : addTask.Then(commit); } addTask .FinallyInUI((success, exception) => { if (success) { UsageTracker.IncrementChangesViewButtonCommit(); commitMessage = ""; commitBody = ""; } isBusy = false; }).Start(); }
private void CheckoutRemoteBranch(string branch) { var indexOfFirstSlash = branch.IndexOf('/'); var originName = branch.Substring(0, indexOfFirstSlash); var branchName = branch.Substring(indexOfFirstSlash + 1); if (Repository.LocalBranches.Any(localBranch => localBranch.Name == branchName)) { EditorUtility.DisplayDialog(WarningCheckoutBranchExistsTitle, String.Format(WarningCheckoutBranchExistsMessage, branchName), WarningCheckoutBranchExistsOK); } else { var confirmCheckout = EditorUtility.DisplayDialog(ConfirmCheckoutBranchTitle, String.Format(ConfirmCheckoutBranchMessage, branch, originName), ConfirmCheckoutBranchOK, ConfirmCheckoutBranchCancel); if (confirmCheckout) { Repository.CreateBranch(branchName, branch) .FinallyInUI((success, e) => { if (success) { UsageTracker.IncrementBranchesViewButtonCheckoutRemoteBranch(); Redraw(); } else { EditorUtility.DisplayDialog(Localization.SwitchBranchTitle, String.Format(Localization.SwitchBranchFailedDescription, branch), Localization.Ok); } }).Start(); } } }
private void OnButtonBarGUI() { if (mode == BranchesMode.Default) { // Delete button // If the current branch is selected, then do not enable the Delete button EditorGUI.BeginDisabledGroup(disableDelete); { if (GUILayout.Button(DeleteBranchButton, EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { DeleteLocalBranch(treeLocals.SelectedNode.Path); } } EditorGUI.EndDisabledGroup(); // Create button GUILayout.FlexibleSpace(); EditorGUI.BeginDisabledGroup(disableCreate); { if (GUILayout.Button(CreateBranchButton, EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { targetMode = BranchesMode.Create; } } EditorGUI.EndDisabledGroup(); } // Branch name + cancel + create else if (mode == BranchesMode.Create) { GUILayout.BeginHorizontal(); { var createBranch = false; var cancelCreate = false; var cannotCreate = treeLocals.SelectedNode == null || treeLocals.SelectedNode.IsFolder || !Validation.IsBranchNameValid(newBranchName); // Create on return/enter or cancel on escape var offsetID = GUIUtility.GetControlID(FocusType.Passive); if (Event.current.isKey && GUIUtility.keyboardControl == offsetID + 1) { if (Event.current.keyCode == KeyCode.Escape) { cancelCreate = true; Event.current.Use(); } else if (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter) { if (cannotCreate) { EditorApplication.Beep(); } else { createBranch = true; } Event.current.Use(); } } newBranchName = EditorGUILayout.TextField(newBranchName); // Create EditorGUI.BeginDisabledGroup(cannotCreate); { if (GUILayout.Button(NewBranchConfirmButton, EditorStyles.miniButtonLeft, GUILayout.ExpandWidth(false))) { createBranch = true; } } EditorGUI.EndDisabledGroup(); // Cancel create if (GUILayout.Button(NewBranchCancelButton, EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false))) { cancelCreate = true; } // Effectuate create if (createBranch) { Repository.CreateBranch(newBranchName, treeLocals.SelectedNode.Path) .FinallyInUI((success, e) => { if (success) { UsageTracker.IncrementBranchesViewButtonCreateBranch(); Redraw(); } else { var errorHeader = "fatal: "; var errorMessage = e.Message.StartsWith(errorHeader) ? e.Message.Remove(0, errorHeader.Length) : e.Message; EditorUtility.DisplayDialog(CreateBranchTitle, errorMessage, Localization.Ok); } }) .Start(); } // Cleanup if (createBranch || cancelCreate) { newBranchName = ""; GUIUtility.keyboardControl = -1; targetMode = BranchesMode.Default; } } GUILayout.EndHorizontal(); } }
public void Run() { isBusy = true; progress.UpdateProgress(0, 100, "Initializing..."); if (firstRun) { UsageTracker.IncrementNumberOfStartups(); } var thread = new Thread(() => { GitInstallationState state = new GitInstallationState(); try { if (Environment.IsMac) { var getEnvPath = new SimpleProcessTask(TaskManager.Token, "bash".ToNPath(), "-c \"/usr/libexec/path_helper\"") .Configure(ProcessManager, dontSetupGit: true) .Catch(e => true); // make sure this doesn't throw if the task fails var path = getEnvPath.RunSynchronously(); if (getEnvPath.Successful) { Logger.Trace("Existing Environment Path Original:{0} Updated:{1}", Environment.Path, path); Environment.Path = path?.Split(new[] { "\"" }, StringSplitOptions.None)[1]; } } progress.UpdateProgress(20, 100, "Setting up octorun..."); Environment.OctorunScriptPath = new OctorunInstaller(Environment, TaskManager) .SetupOctorunIfNeeded(); progress.UpdateProgress(50, 100, "Setting up git..."); state = Environment.GitInstallationState; if (!state.GitIsValid && !state.GitLfsIsValid && FirstRun) { // importing old settings NPath gitExecutablePath = Environment.SystemSettings.Get(Constants.GitInstallPathKey, NPath.Default); if (gitExecutablePath.IsInitialized) { Environment.SystemSettings.Unset(Constants.GitInstallPathKey); state.GitExecutablePath = gitExecutablePath; state.GitInstallationPath = gitExecutablePath.Parent.Parent; Environment.GitInstallationState = state; } } var installer = new GitInstaller(Environment, ProcessManager, TaskManager.Token); installer.Progress(progressReporter.UpdateProgress); if (state.GitIsValid && state.GitLfsIsValid) { if (firstRun) { installer.ValidateGitVersion(state); if (state.GitIsValid) { installer.ValidateGitLfsVersion(state); } } } if (!state.GitIsValid || !state.GitLfsIsValid) { state = installer.RunSynchronously(); } SetupGit(state); progress.UpdateProgress(80, 100, "Initializing repository..."); if (state.GitIsValid && state.GitLfsIsValid) { RestartRepository(); } progress.UpdateProgress(100, 100, "Initialized"); } catch (Exception ex) { Logger.Error(ex, "A problem ocurred setting up Git"); progress.UpdateProgress(90, 100, "Initialization failed"); } new ActionTask <bool>(TaskManager.Token, (s, gitIsValid) => { InitializationComplete(); if (gitIsValid) { InitializeUI(); } }, () => state.GitIsValid && state.GitLfsIsValid) { Affinity = TaskAffinity.UI } .Start(); }); thread.Start(); }
public override void OnGUI() { GUILayout.BeginHorizontal(Styles.AuthHeaderBoxStyle); { GUILayout.Label(PublishToGithubLabel, EditorStyles.boldLabel); } GUILayout.EndHorizontal(); EditorGUI.BeginDisabledGroup(isBusy); { if (connections.Length > 1) { EditorGUI.BeginChangeCheck(); { selectedConnection = EditorGUILayout.Popup("Connections:", selectedConnection, connectionLabels); } if (EditorGUI.EndChangeCheck()) { selectedClient = GetApiClient(connections[selectedConnection]); ownersNeedLoading = true; Redraw(); } } selectedOwner = EditorGUILayout.Popup(SelectedOwnerLabel, selectedOwner, owners); repoName = EditorGUILayout.TextField(RepositoryNameLabel, repoName); repoDescription = EditorGUILayout.TextField(DescriptionLabel, repoDescription); togglePrivate = EditorGUILayout.Toggle(CreatePrivateRepositoryLabel, togglePrivate); var repoPrivacyExplanation = togglePrivate ? PrivateRepoMessage : PublicRepoMessage; EditorGUILayout.HelpBox(repoPrivacyExplanation, MessageType.None); GUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); EditorGUI.BeginDisabledGroup(!IsFormValid); if (GUILayout.Button(PublishViewCreateButton)) { GUI.FocusControl(null); isBusy = true; var organization = owners[selectedOwner] == connections[selectedConnection].Username ? null : owners[selectedOwner]; var cleanRepoDescription = repoDescription.Trim(); cleanRepoDescription = string.IsNullOrEmpty(cleanRepoDescription) ? null : cleanRepoDescription; selectedClient.CreateRepository(repoName, cleanRepoDescription, togglePrivate, (repository, ex) => { if (ex != null) { Logger.Error(ex, "Repository Create Error Type:{0}", ex.GetType().ToString()); error = GetPublishErrorMessage(ex); isBusy = false; return; } UsageTracker.IncrementPublishViewButtonPublish(); if (repository == null) { Logger.Warning("Returned Repository is null"); isBusy = false; return; } Repository.RemoteAdd("origin", repository.CloneUrl) .Then(Repository.Push("origin")) .ThenInUI(Finish) .Start(); }, organization); } EditorGUI.EndDisabledGroup(); } GUILayout.EndHorizontal(); GUILayout.Space(10); if (error != null) { EditorGUILayout.HelpBox(error, MessageType.Error); } GUILayout.FlexibleSpace(); } EditorGUI.EndDisabledGroup(); }