Ejemplo n.º 1
0
        protected void OnMergeComplete(MergeResult result, string mergeType)
        {
            switch (result.Status)
            {
            case MergeStatus.UpToDate:
                GitHistoryWindow.GetWindow(true).ShowNotification(new GUIContent(string.Format("Everything is Up to date. Nothing to {0}.", mergeType)));
                break;

            case MergeStatus.FastForward:
                GitHistoryWindow.GetWindow(true).ShowNotification(new GUIContent(mergeType + " Complete with Fast Forwarding."));
                break;

            case MergeStatus.NonFastForward:
                GitDiffWindow.GetWindow(true).ShowNotification(new GUIContent("Do a merge commit in order to push changes."));
                GitDiffWindow.GetWindow(false).commitMessage = GitManager.Repository.Info.Message;
                Debug.Log(mergeType + " Complete without Fast Forwarding.");
                break;

            case MergeStatus.Conflicts:
                GUIContent content = EditorGUIUtility.IconContent("console.warnicon");
                content.text = "There are merge conflicts!";
                GitDiffWindow.GetWindow(true).ShowNotification(content);
                GitDiffWindow.GetWindow(false).commitMessage = GitManager.Repository.Info.Message;
                break;
            }
            GitManager.Update();
            Debug.LogFormat("{0} Status: {1}", mergeType, result.Status);
        }
Ejemplo n.º 2
0
        private void Commit()
        {
            Signature signature = GitManager.Signature;

            try
            {
                if (!GitExternalManager.TakeCommit(commitMessage))
                {
                    GitManager.Repository.Commit(commitMessage, signature, signature, new CommitOptions()
                    {
                        AllowEmptyCommit = settings.emptyCommit, AmendPreviousCommit = settings.amendCommit, PrettifyMessage = settings.prettify
                    });
                    GitHistoryWindow.GetWindow(true);
                }
                GitManager.Update();
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
            finally
            {
                GUI.FocusControl("");
                commitMessage = string.Empty;
            }
        }
Ejemplo n.º 3
0
        private void DoDiffStatusContex(FileStatus fileStatus, GenericMenu menu)
        {
            menu.AddItem(new GUIContent("Select All"), false, SelectFilteredCallback, fileStatus);
            if (GitManager.CanStage(fileStatus))
            {
                menu.AddItem(new GUIContent("Add All"), false, () =>
                {
                    GitManager.Repository.Stage(statusList.Where(s => s.State.IsFlagSet(fileStatus)).SelectMany(s => GitManager.GetPathWithMeta(s.Path)));
                    GitManager.Update();
                });
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Add All"));
            }

            if (GitManager.CanUnstage(fileStatus))
            {
                menu.AddItem(new GUIContent("Remove All"), false, () =>
                {
                    GitManager.Repository.Unstage(statusList.Where(s => s.State.IsFlagSet(fileStatus)).SelectMany(s => GitManager.GetPathWithMeta(s.Path)));
                    GitManager.Update();
                });
            }
            else
            {
                menu.AddDisabledItem(new GUIContent("Remove All"));
            }
        }
Ejemplo n.º 4
0
 private void OnWizardCreate()
 {
     try
     {
         using (var repository = new Repository(GitManager.RepoPath))
         {
             repository.Network.Push(repository.Branches[branchNames[selectedBranch]], pushOptions);
             GitManager.Update();
             var window = GitHistoryWindow.GetWindow(true);
             window.ShowNotification(new GUIContent("Push Complete"));
         }
     }
     catch (Exception e)
     {
         if (e is NonFastForwardException)
         {
             GUIContent content = EditorGUIUtility.IconContent("console.warnicon");
             content.text = "Could not push changes to remote. Merge changes with remote before pushing.";
             GetWindow <GitHistoryWindow>().ShowNotification(content);
         }
         Debug.LogException(e);
     }
     finally
     {
         EditorUtility.ClearProgressBar();
     }
 }
Ejemplo n.º 5
0
            public override void OnGUI(Rect rect)
            {
                EditorGUILayout.Space();
                resetMode = (ResetMode)EditorGUILayout.EnumPopup(new GUIContent("Reset Type"), resetMode);
                GUIContent infoContent = new GUIContent();

                switch (resetMode)
                {
                case ResetMode.Soft:
                    EditorGUILayout.HelpBox("Leave working tree and index untouched", MessageType.Info);
                    break;

                case ResetMode.Mixed:
                    EditorGUILayout.HelpBox("Leave working tree untouched,reset index (Default)", MessageType.Info);
                    break;

                case ResetMode.Hard:
                    EditorGUILayout.HelpBox("Reset working tree and index (Will delete all files)", MessageType.Error);
                    break;
                }
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Reset"))
                {
                    if (EditorUtility.DisplayDialog("Reset", "Are you sure you want to reset to the selected commit", "Reset", "Cancel"))
                    {
                        Profiler.BeginSample("Git Reset Popup");
                        GitManager.Repository.Reset(resetMode, commit, checkoutOptions);
                        GitManager.Update(true);
                        editorWindow.Close();
                        Profiler.EndSample();
                        AssetDatabase.Refresh();
                    }
                }
                EditorGUILayout.Space();
            }
Ejemplo n.º 6
0
 private static void Revet()
 {
     GitManager.Repository.CheckoutPaths("HEAD", Selection.assetGUIDs.Select(e => AssetDatabase.GUIDToAssetPath(e)).SelectMany(e => GitManager.GetPathWithMeta(e)), new CheckoutOptions()
     {
         CheckoutModifiers = CheckoutModifiers.Force, OnCheckoutProgress = OnRevertProgress
     });
     EditorUtility.ClearProgressBar();
     GitManager.Update();
     AssetDatabase.Refresh();
 }
Ejemplo n.º 7
0
        private void OnRevertProgress(string path, int currentSteps, int totalSteps)
        {
            float percent = (float)currentSteps / totalSteps;

            EditorUtility.DisplayProgressBar("Reverting File", string.Format("Reverting file {0} {1}%", path, (percent * 100).ToString("####")), percent);
            if (currentSteps >= totalSteps)
            {
                EditorUtility.ClearProgressBar();
                GitManager.Update();
                GetWindow <GitDiffWindow>().ShowNotification(new GUIContent("Revert Complete!"));
            }
        }
Ejemplo n.º 8
0
        private static void OnRevertProgress(string path, int currentSteps, int totalSteps)
        {
            float percent = (float)currentSteps / totalSteps;

            EditorUtility.DisplayProgressBar("Reverting File", string.Format("Reverting file {0} {1}%", path, (percent * 100).ToString("####")), percent);
            if (currentSteps >= totalSteps)
            {
                GitManager.Update();
                Type type = typeof(EditorWindow).Assembly.GetType("UnityEditor.ProjectBrowser");
                EditorWindow.GetWindow(type).ShowNotification(new GUIContent("Revert Complete!"));
            }
        }
Ejemplo n.º 9
0
 private static string[] OnWillSaveAssets(string[] paths)
 {
     if (GitManager.Settings != null && GitManager.Settings.AutoStage)
     {
         string[] pathsFinal = paths.SelectMany(g => GitManager.GetPathWithMeta(g)).Where(g => GitManager.CanStage(GitManager.Repository.RetrieveStatus(g))).ToArray();
         if (pathsFinal.Length > 0)
         {
             GitManager.Repository.Stage(pathsFinal);
         }
     }
     GitManager.Update();
     return(paths);
 }
Ejemplo n.º 10
0
 public override void OnGUI(Rect rect)
 {
     EditorGUILayout.Space();
     name        = EditorGUILayout.TextField(new GUIContent("Name"), name);
     url         = EditorGUILayout.TextField(new GUIContent("URL"), url);
     GUI.enabled = !string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(url);
     if (GUILayout.Button(new GUIContent("Add Remote")))
     {
         remoteCollection.Add(name, url);
         GitManager.Update();
         GetWindow <GitSettingsWindow>().Focus();
     }
     GUI.enabled = true;
     EditorGUILayout.Space();
 }
Ejemplo n.º 11
0
 internal static void InvalidRepoGUI()
 {
     EditorGUILayout.BeginHorizontal();
     GUILayout.FlexibleSpace();
     GUILayout.Box(new GUIContent("Not a GIT Repository"), "NotificationBackground");
     GUILayout.FlexibleSpace();
     EditorGUILayout.EndHorizontal();
     GUILayout.FlexibleSpace();
     EditorGUILayout.BeginHorizontal();
     GUILayout.FlexibleSpace();
     if (GUILayout.Button(new GUIContent("Create"), "LargeButton", GUILayout.Height(32), GUILayout.Width(128)))
     {
         if (EditorUtility.DisplayDialog("Initialize Repository", "Are you sure you want to initialize a Repository for your project", "Yes", "Cancel"))
         {
             Repository.Init(Application.dataPath.Replace("/Assets", ""));
             TextAsset textAsset = EditorGUIUtility.Load("gitignore.txt") as TextAsset;
             if (textAsset != null)
             {
                 string textAssetPath    = AssetDatabase.GetAssetPath(textAsset).Replace("Assets/", "");
                 string newGitIgnoreFile = Path.Combine(Application.dataPath.Replace("Assets", "").Replace("Contents", ""), ".gitignore");
                 if (!File.Exists(newGitIgnoreFile))
                 {
                     File.Copy(Path.Combine(Application.dataPath, textAssetPath), newGitIgnoreFile);
                 }
                 else
                 {
                     Debug.Log("Git Ignore file already present");
                 }
             }
             else
             {
                 Debug.LogError("Missing default gitignore.txt in resources");
             }
             AssetDatabase.Refresh();
             AssetDatabase.SaveAssets();
             GitManager.Initlize();
             GitManager.Update();
             GUIUtility.ExitGUI();
             return;
         }
     }
     GUILayout.FlexibleSpace();
     EditorGUILayout.EndHorizontal();
     EditorGUILayout.Space();
 }
Ejemplo n.º 12
0
 private void OnWizardCreate()
 {
     try
     {
         MergeResult result = GitManager.Repository.MergeFetchedRefs(GitManager.Signature, mergeOptions);
         GitHistoryWindow.GetWindow(true);
         OnMergeComplete(result, "Merge");
         GitManager.Update();
         AssetDatabase.Refresh();
     }
     catch (CheckoutConflictException e)
     {
         Debug.LogException(e);
     }
     finally
     {
         EditorUtility.ClearProgressBar();
     }
 }
Ejemplo n.º 13
0
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            if (GitManager.Settings != null && GitManager.Settings.AutoStage)
            {
                if (importedAssets.Length > 0)
                {
                    string[] importedAssetsFinal = importedAssets.SelectMany(g => GitManager.GetPathWithMeta(g)).Where(g => GitManager.CanStage(GitManager.Repository.RetrieveStatus(g))).ToArray();
                    if (importedAssetsFinal.Length > 0)
                    {
                        GitManager.Repository.Stage(importedAssetsFinal);
                    }
                }

                if (movedAssets.Length > 0)
                {
                    string[] movedAssetsFinal = movedAssets.SelectMany(g => GitManager.GetPathWithMeta(g)).Where(g => GitManager.CanStage(GitManager.Repository.RetrieveStatus(g))).ToArray();
                    if (movedAssetsFinal.Length > 0)
                    {
                        GitManager.Repository.Stage(movedAssetsFinal);
                    }
                }
            }
            GitManager.Update();
        }
Ejemplo n.º 14
0
 private static void RemoveSelected()
 {
     GitManager.Repository.Unstage(Selection.assetGUIDs.Select(g => AssetDatabase.GUIDToAssetPath(g)).SelectMany(g => GitManager.GetPathWithMeta(g)));
     GitManager.Update();
 }
Ejemplo n.º 15
0
        private void DoToolbar(Rect rect, RepositoryInformation info)
        {
            Profiler.BeginSample("Git History Window Toolbar GUI");
            GUI.Box(rect, GUIContent.none, "Toolbar");
            Rect       btRect            = new Rect(rect.x, rect.y, 64, rect.height);
            GUIContent pushButtonContent = new GUIContent("Push", EditorGUIUtility.FindTexture("CollabPush"), "Push local changes to a remote repository.");

            if (info.CurrentOperation == CurrentOperation.Merge)
            {
                GUI.enabled = false;
                pushButtonContent.tooltip = "Do a Merge commit before pushing.";
            }
            else if (hasConflicts)
            {
                GUI.enabled = false;
                pushButtonContent.tooltip = "Resolve conflicts before pushing.";
            }
            if (GUI.Button(btRect, pushButtonContent, "toolbarbutton"))
            {
                if (GitExternalManager.TakePush())
                {
                    GitManager.Update();
                }
                else
                {
                    ScriptableWizard.DisplayWizard <GitPushWizard>("Push", "Push").Init(selectedBranch.LoadBranch());
                }
            }
            btRect      = new Rect(btRect.x + 64, btRect.y, 64, btRect.height);
            GUI.enabled = !hasConflicts;
            GUIContent pullButtonContent = EditorGUIUtility.IconContent("CollabPull");

            pullButtonContent.tooltip = hasConflicts ? "Must resolve conflicts before pulling" : "Pull changes from remote repository by fetching them and then merging them. This is the same as calling Fetch then Merge.";
            pullButtonContent.text    = "Pull";
            if (GUI.Button(btRect, pullButtonContent, "toolbarbutton"))
            {
                Branch branch = selectedBranch.LoadBranch();
                if (GitExternalManager.TakePull())
                {
                    AssetDatabase.Refresh();
                    GitManager.Update();
                }
                else
                {
                    ScriptableWizard.DisplayWizard <GitPullWizard>("Pull", "Pull").Init(branch);
                }
            }
            btRect = new Rect(btRect.x + 70, btRect.y, 64, btRect.height);
            GUIContent fetchButtonContent = EditorGUIUtility.IconContent("UniGit/GitFetch");

            fetchButtonContent.tooltip = "Get changes from remote repository but do not merge them.";
            fetchButtonContent.text    = "Fetch";
            if (GUI.Button(btRect, fetchButtonContent, "toolbarbutton"))
            {
                Branch branch = selectedBranch.LoadBranch();
                if (GitExternalManager.TakeFetch(branch.Remote.Name))
                {
                    GitManager.Update();
                }
                else
                {
                    ScriptableWizard.DisplayWizard <GitFetchWizard>("Fetch", "Fetch").Init(branch);
                }
            }
            btRect = new Rect(btRect.x + 64, btRect.y, 64, btRect.height);
            GUIContent mergeButtonContent = EditorGUIUtility.IconContent("UniGit/GitMerge");

            mergeButtonContent.tooltip = hasConflicts ? "Must Resolve conflict before merging" : "Merge fetched changes from remote repository. Changes from the latest fetch will be merged.";
            mergeButtonContent.text    = "Merge";
            if (GUI.Button(btRect, mergeButtonContent, "toolbarbutton"))
            {
                if (GitExternalManager.TakeMerge())
                {
                    GitManager.Update();
                }
                else
                {
                    ScriptableWizard.DisplayWizard <GitMergeWizard>("Merge", "Merge");
                }
            }
            GUI.enabled = true;
            btRect      = new Rect(rect.x + rect.width - 64, btRect.y, 64, btRect.height);
            if (GUI.Button(btRect, new GUIContent(string.IsNullOrEmpty(selectedBranchName) ? "Branch" : selectedBranch.FriendlyName), "ToolbarDropDown"))
            {
                GenericMenu selectBranchMenu = new GenericMenu();
                foreach (var branch in cachedBranches)
                {
                    selectBranchMenu.AddItem(new GUIContent(branch.FriendlyName), false, (b) =>
                    {
                        selectedBranchName = (string)b;
                        UpdateSelectedBranch();
                    }, branch.FriendlyName);
                }
                selectBranchMenu.ShowAsContext();
            }
            btRect      = new Rect(btRect.x - 64, btRect.y, 64, btRect.height);
            GUI.enabled = !selectedBranch.IsRemote && !selectedBranch.IsCurrentRepositoryHead;
            GUIContent checkoutButtonContent = EditorGUIUtility.IconContent("UniGit/GitCheckout");

            checkoutButtonContent.text    = "Switch";
            checkoutButtonContent.tooltip = selectedBranch.IsRemote ? "Cannot switch to remote branches." : selectedBranch.IsCurrentRepositoryHead ? "This branch is the active one" : "Switch to another branch";
            if (GUI.Button(btRect, checkoutButtonContent, "toolbarbutton"))
            {
            }
            GUI.enabled = true;
            Profiler.EndSample();
        }
Ejemplo n.º 16
0
 private void ReloadCallback()
 {
     GitManager.Update(true);
 }
Ejemplo n.º 17
0
        private void DoGeneral(Event current)
        {
            GUILayout.Box(new GUIContent("Unity Settings"), "ProjectBrowserHeaderBgTop");

            EditorGUILayout.PropertyField(serializedSettings.FindProperty("AutoStage"));
            EditorGUILayout.PropertyField(serializedSettings.FindProperty("AutoFetch"));
            serializedSettings.ApplyModifiedProperties();
            EditorGUILayout.PropertyField(serializedSettings.FindProperty("MaxCommits"));
            if (serializedSettings.ApplyModifiedProperties())
            {
                GitManager.Update();
            }

            GUILayout.Box(new GUIContent("Git Settings"), "ProjectBrowserHeaderBgMiddle");

            EditorGUILayout.LabelField(new GUIContent("User"), EditorStyles.boldLabel);
            EditorGUI.indentLevel = 1;
            DoConfigStringField(new GUIContent("Name"), "user.name", "");
            DoConfigStringField(new GUIContent("Email"), "user.email", "");
            EditorGUI.indentLevel = 0;

            EditorGUILayout.LabelField(new GUIContent("Core"), EditorStyles.boldLabel);
            EditorGUI.indentLevel = 1;
            DoConfigToggle(new GUIContent("Auto LF line endings"), "core.autocrlf", true);
            DoConfigToggle(new GUIContent("Bare"), "core.bare", false);
            DoConfigToggle(new GUIContent("Symlinks"), "core.symlinks", false);
            DoConfigToggle(new GUIContent("Ignore Case"), "core.ignorecase", true);
            DoConfigToggle(new GUIContent("Logal Reference Updates"), "core.logallrefupdates", true);
            DoConfigIntSlider(new GUIContent("Compression"), -1, 9, "core.compression", -1);
            DoConfigStringField(new GUIContent("Big File Threshold"), "core.bigFileThreshold", "512m");
            EditorGUI.indentLevel = 0;

            EditorGUILayout.LabelField(new GUIContent("Branch"), EditorStyles.boldLabel);
            EditorGUI.indentLevel = 1;
            DoConfigStringsField(new GUIContent("Auto Setup Rebase"), "branch.autoSetupRebase", autoRebaseOptions, "never");
            EditorGUI.indentLevel = 0;

            EditorGUILayout.LabelField(new GUIContent("Diff"), EditorStyles.boldLabel);
            EditorGUI.indentLevel = 1;
            DoConfigToggle(new GUIContent("Renames"), "diff.renames", true);
            DoConfigIntField(new GUIContent("Rename Limit"), "diff.renameLimit", -1);
            EditorGUI.indentLevel = 0;

            EditorGUILayout.LabelField(new GUIContent("HTTP"), EditorStyles.boldLabel);
            EditorGUI.indentLevel = 1;
            DoConfigToggle(new GUIContent("Verify SSL Crtificate"), "http.sslVerify", true);
            string oldPath = GitManager.Repository.Config.GetValueOrDefault <string>("http.sslCAInfo");

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(new GUIContent("SSL Certificate File"));
            if (GUILayout.Button(new GUIContent(oldPath), "TE ToolbarDropDown"))
            {
                EditorGUI.BeginChangeCheck();
                string newPath = EditorUtility.OpenFilePanelWithFilters("Certificate", string.IsNullOrEmpty(oldPath) ? Application.dataPath : Path.GetFullPath(oldPath), new string[] { "", "cer", "", "pom", "", "crt" });
                if (oldPath != newPath)
                {
                    GitManager.Repository.Config.Set("http.sslCAInfo", newPath);
                }
            }
            EditorGUILayout.EndHorizontal();
            EditorGUI.indentLevel = 0;
        }
Ejemplo n.º 18
0
 private void AddSelectedCallback()
 {
     GitManager.Repository.Stage(statusList.Where(e => e.Selected).SelectMany(e => GitManager.GetPathWithMeta(e.Path)));
     GitManager.Update();
 }
Ejemplo n.º 19
0
 private static void AddSelected()
 {
     GitManager.Repository.Stage(Selection.assetGUIDs.Select(g => AssetDatabase.GUIDToAssetPath(g)).SelectMany(g => g.EndsWith(".meta") ? new[] { g } : new[] { g, g + ".meta" }));
     GitManager.Update();
 }