/// <summary> /// Creates a new branch from the currently checked out commit or branch HEAD commit and returns it. /// Does not check out the newly created branch /// </summary> public IBranch CreateBranch(string branchName) { if (!EnabledVersionControls.Instance().CanBranch) { Debug.Log("Can't Branch; not enabled yet"); return(null); } if (HasBranch(branchName)) { throw new System.ArgumentException("Branch already exists"); } IBranch branch = new Branch(branchName, activeCommit); branches.Add(branchName, branch); if (branchTrigger != null) { branchTrigger.Trigger(); } lastCreatedBranch = branch; return(branch); }
/// <summary> /// Checks out the given commit on the given branch /// </summary> public void Checkout(IBranch branch, ICommit commit) { // Need to allow them to checkout the last created branch because that's how "create branch" works if (!EnabledVersionControls.Instance().CanCheckout&& !lastCreatedBranch.Equals(branch)) { Debug.Log("Can't Checkout branch; not enabled yet"); return; } LoadStateOfCommit(commit); activeCommit = commit; activeBranch = branch; if (!activeCommit.Equals(activeBranch.GetTip())) { this.isDetached = true; } else { this.isDetached = false; } if (checkoutTrigger != null) { checkoutTrigger.Trigger(); } UIController.Instance().UpdateOverlay(); }
public void DisplayMergeDialog() { if (!EnabledVersionControls.Instance().CanMerge) { Debug.Log("Can't Merge; not enabled yet"); return; } EngineController.Instance().ToggleControls(false); GameObject dialog = Instantiate(textButttonDialogTemplate, transform) as GameObject; TextButtonDialogController dialogController = dialog.GetComponent <TextButtonDialogController>(); dialogController.promptText.text = "git merge "; dialogController.titleText.text = "Enter Feature Branch"; dialogController.submitButton.enabled = false; dialogController.submitButton.GetComponentInChildren <Text>().text = "Merge"; dialogController.inputField.onValueChanged.AddListener((s) => { dialogController.submitButton.enabled = !s.Equals(""); }); dialogController.submitButton.onClick.AddListener(() => { bool reenableControls = true; Debug.Log("Button pressed"); string mergeBranch = dialogController.inputField.text; if (VersionManager.Instance().HasBranch(mergeBranch)) { VersionManager.Instance().Merge(VersionManager.Instance().LookupBranch(mergeBranch)); if (VersionManager.Instance().IsInMergeConflict()) { // The merge conflict menu will re-enable controls later. reenableControls = false; } Debug.Log("Starting merge"); } else { dialogController.ErrorText = "Feature branch doesn't exist, check spelling and try again"; return; } if (reenableControls) { EngineController.Instance().ToggleControls(true); } Destroy(dialog); } ); dialogController.submitButton.onClick.AddListener(() => { UpdateOverlay(); }); dialogController.inputField.Select(); if (mergeDialogTrigger != null) { mergeDialogTrigger.NotifyObservers(); } }
/// <summary> /// Resets all tracked objects to the state of the HEAD commit of the current branch /// if we are on a branch /// </summary> public void ResetToHead() { if (!EnabledVersionControls.Instance().CanReset) { Debug.Log("Can't Reset; not enabled yet"); return; } LoadStateOfCommit(activeBranch.GetTip()); }
void Start() { EnabledVersionControls playerVersionControls = EnabledVersionControls.Instance(); GameObject.Find("Overlay/Status/CommitButton").GetComponent <Button>().interactable = playerVersionControls.CanCommit; GameObject.Find("Overlay/Status/BranchButton").GetComponent <Button>().interactable = playerVersionControls.CanBranch; GameObject.Find("Overlay/Status/CheckoutButton").GetComponent <Button>().interactable = playerVersionControls.CanCheckout; GameObject.Find("Overlay/Status/ResetButton").GetComponent <Button>().interactable = playerVersionControls.CanReset; UpdateOverlay(); }
/// <summary> /// Resets the given versionable object to the state of the HEAD commit of the current /// branch if we are on a branch. /// </summary> public void ResetToHead(VersionController versionedObject) { if (!EnabledVersionControls.Instance().CanReset) { Debug.Log("Can't Reset; not enabled yet"); return; } else if (activeBranch != null) { LoadStateOfCommit(activeBranch.GetTip(), versionedObject); } }
/// <summary> /// Wrapper method for commit API. Checks if player is able to commit yet. /// </summary> /// <param name="message">The commit message</param> /// <returns>The commit if the player is able to commit, null otherwise</returns> public ICommit Commit(string message) { if (!EnabledVersionControls.Instance().CanCommit) { Debug.Log("Can't Commit; not enabled yet"); return(null); } else { return(this.Commit(message, false)); } }
/// <summary> /// Creates a new commit from the current state of the staging area. /// Appends the commit to the current branch and clears the staging area. /// Clears the preview of the staging area. /// /// Additional parameter for forcing commits through the player's enabled version control mechanics /// such as for oneShot doors. /// </summary> public ICommit Commit(string message, bool forced) { if (!EnabledVersionControls.Instance().CanCommit&& !forced) { Debug.Log("Can't Commit; not enabled yet"); return(null); } if (isDetached) { throw new InvalidOperationException("Cannot commit in detached HEAD state"); } CommitBuilder builder = new CommitBuilder(); builder.SetMessage(message); builder.SetParent(activeCommit); foreach (VersionController controller in trackedObjects) { IVersion controllerVersion; if (stagingArea.Contains(controller)) { // increment commit count controllerVersion = controller.GenerateVersion(); } else { controllerVersion = controller.GetVersion(); } builder.AddObject(controller, controllerVersion); } ICommit commit = builder.Build(); activeCommit = commit; foreach (VersionController stagedController in stagingArea) { stagedController.HideStagedState(); } if (activeBranch != null) { activeBranch.UpdateTip(activeCommit); } stagingArea.Clear(); if (commitTrigger != null) { commitTrigger.Trigger(); } UIController.Instance().UpdateOverlay(); return(commit); }
public void DisplayCommitDialog() { if (!EnabledVersionControls.Instance().CanCommit) { Debug.Log("Can't commit; not enabled"); return; } EngineController.Instance().ToggleControls(false); GameObject dialog = Instantiate(textButttonDialogTemplate, transform) as GameObject; TextButtonDialogController dialogController = dialog.GetComponent <TextButtonDialogController>(); dialogController.promptText.text = "git commit -m "; dialogController.titleText.text = "Enter a commit message"; dialogController.submitButton.enabled = false; dialogController.submitButton.GetComponentInChildren <Text>().text = "Commit"; dialogController.inputField.onValueChanged.AddListener((s) => { dialogController.submitButton.enabled = !s.Equals(""); }); dialogController.submitButton.onClick.AddListener(() => { Debug.Log("Button pressed"); string commitMessage = dialogController.inputField.text; VersionManager.Instance().Commit(commitMessage); Debug.Log("Commiting"); EngineController.Instance().ToggleControls(true); Destroy(dialog); } ); dialogController.submitButton.onClick.AddListener(() => { UpdateOverlay(); }); dialogController.inputField.Select(); if (commitDialogTrigger != null) { commitDialogTrigger.NotifyObservers(); } }
public Relationship Merge(IBranch featureBranch) { if (!EnabledVersionControls.Instance().CanMerge) { Debug.Log("Merging not enabled yet"); } if (isDetached) { throw new Exception("Can't merge if detached"); } if (this.mw != null) { throw new Exception("Already doing a merge, resolve this first"); } IMergeWorker mw = new MergeWorker(activeBranch, featureBranch, pickTrigger, mergeUI); Relationship mergeType = mw.GetMergeType(); if (mw.GetMergeType() == Relationship.FastForward) { mw.End(); activeBranch.UpdateTip(featureBranch.GetTip()); activeCommit = activeBranch.GetTip(); LoadStateOfCommit(activeCommit); if (mergeTrigger != null) { mergeTrigger.Trigger(); } return(mergeType); } this.mw = mw; return(mergeType); }
public void DisplayBranchDialog() { if (!EnabledVersionControls.Instance().CanBranch) { Debug.Log("Can't Branch; not enabled yet"); return; } EngineController.Instance().ToggleControls(false); GameObject dialog = Instantiate(textButttonDialogTemplate, transform) as GameObject; TextButtonDialogController dialogController = dialog.GetComponent <TextButtonDialogController>(); dialogController.titleText.text = "Checkout Branch"; dialogController.submitButton.GetComponentInChildren <Text>().text = "Create Branch"; dialogController.promptText.text = "git checkout -b "; dialogController.submitButton.enabled = false; dialogController.inputField.onValueChanged.AddListener((s) => { if (VersionManager.Instance().HasBranch(s)) { dialogController.submitButton.GetComponentInChildren <Text>().text = "Switch to Branch"; dialogController.promptText.text = "git checkout "; } else { dialogController.submitButton.GetComponentInChildren <Text>().text = "Create Branch"; dialogController.promptText.text = "git checkout -b "; } dialogController.submitButton.enabled = !s.Equals(""); }); dialogController.submitButton.onClick.AddListener(() => { Debug.Log("Button pressed"); string branch = dialogController.inputField.text; if (Regex.Match(branch, @"[~^:\[\]\\\s]").Success) { dialogController.ErrorText = "Error - branch names cannot contain spaces or special characters: ~ ^ : [ ] \\"; return; } if (!VersionManager.Instance().HasBranch(branch)) { VersionManager.Instance().CreateBranch(branch); Debug.Log("Creating branch " + branch); } VersionManager.Instance().Checkout(branch); Debug.Log("Checkout " + branch); EngineController.Instance().ToggleControls(true); Destroy(dialog); } ); dialogController.submitButton.onClick.AddListener(() => { UpdateOverlay(); }); dialogController.inputField.Select(); if (newBranchDialogTrigger != null) { newBranchDialogTrigger.NotifyObservers(); } }
public void EnableCommit() { EnabledVersionControls.Instance().EnableCommit(); GameObject.Find("EngineController/UIController/Overlay/Status/CommitButton").GetComponent <Button>().interactable = true; }
public void EnableMerge() { EnabledVersionControls.Instance().EnableMerge(); }