Beispiel #1
0
        protected LibGit2Sharp.Credentials CredentialsHandler(string url, string user, SupportedCredentialTypes supported)
        {
            if (supported == SupportedCredentialTypes.UsernamePassword)
            {
                string username = credentials.Username;
                string password = credentials.Password;

                if (credentials.IsToken)
                {
                    username = credentials.Token;
                    password = string.Empty;
                }

                if (GitManager.GitCredentials != null)
                {
                    if (string.IsNullOrEmpty(username) && string.IsNullOrEmpty(password))
                    {
                        GitCredentialsManager.LoadCredentials(url, ref username, ref password, true);
                    }
                }

                return(new UsernamePasswordCredentials()
                {
                    Username = username,
                    Password = password
                });
            }
            return(new DefaultCredentials());
        }
Beispiel #2
0
 public GitAutoFetcher(GitManager gitManager, GitCredentialsManager credentialsManager, GitCallbacks gitCallbacks)
 {
     this.gitManager            = gitManager;
     this.credentialsManager    = credentialsManager;
     this.gitCallbacks          = gitCallbacks;
     gitCallbacks.EditorUpdate += OnEditorUpdate;
     needsFetch = !EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isCompiling && !EditorApplication.isUpdating;
 }
Beispiel #3
0
        private void Construct(GitManager gitManager, GitCredentialsManager credentialsManager, GitExternalManager externalManager)
        {
            this.gitManager         = gitManager;
            this.credentialsManager = credentialsManager;
            this.externalManager    = externalManager;

            remotes = gitManager.Repository.Network != null && gitManager.Repository.Network.Remotes != null?gitManager.Repository.Network.Remotes.ToArray() : new Remote[0];

            remoteNames         = remotes.Select(r => new GUIContent(r.Name)).ToArray();
            branchNames         = gitManager.Repository.Branches.Select(b => b.CanonicalName).ToArray();
            branchFriendlyNames = gitManager.Repository.Branches.Select(b => b.FriendlyName).ToArray();
        }
Beispiel #4
0
 public GitAutoFetcher(GitManager gitManager,
                       GitCredentialsManager credentialsManager,
                       GitCallbacks gitCallbacks,
                       GitSettingsJson gitSettings,
                       ILogger logger,
                       GitInitializer initializer)
 {
     this.gitManager            = gitManager;
     this.credentialsManager    = credentialsManager;
     this.gitCallbacks          = gitCallbacks;
     this.logger                = logger;
     this.gitSettings           = gitSettings;
     this.initializer           = initializer;
     gitCallbacks.EditorUpdate += OnEditorUpdate;
     needsFetch = !EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isCompiling && !EditorApplication.isUpdating;
 }
Beispiel #5
0
        internal static void Initlize()
        {
            repoPathCached = Application.dataPath.Replace("/Assets", "").Replace("/", "\\");
            gitPathCached  = Application.dataPath.Replace("Assets", ".git");

            if (!IsValidRepo)
            {
                return;
            }

            LoadGitSettings();

            GitResourceManager.Initilize();
            GitCredentialsManager.Load();
            GitOverlay.Initlize();
            GitLfsManager.Load();
            GitHookManager.Load();
            GitExternalManager.Load();

            needsFetch                 = !EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isCompiling && !EditorApplication.isUpdating;
            repositoryDirty            = true;
            GitCallbacks.EditorUpdate += OnEditorUpdate;
        }
Beispiel #6
0
 public override void OnGUI(Rect rect)
 {
     name        = EditorGUILayout.TextField(new GUIContent("Name"), name);
     url         = EditorGUILayout.TextField(new GUIContent("URL"), url);
     password    = EditorGUILayout.PasswordField(new GUIContent("Password"), password);
     GUI.enabled = !string.IsNullOrEmpty(url);
     if (GUILayout.Button(new GUIContent("Add Credential")))
     {
         var entry = GitCredentialsManager.CreatEntry(url, username, password);
         if (entry != null)
         {
             entry.Name = name;
             EditorUtility.SetDirty(GitManager.GitCredentials);
             AssetDatabase.SaveAssets();
             GetWindow <GitSettingsWindow>().Focus();
         }
         else
         {
             editorWindow.ShowNotification(new GUIContent("URL already exists"));
         }
     }
     GUI.enabled = true;
 }
Beispiel #7
0
        private static void Rebuild(InjectionHelper injectionHelper)
        {
            var settingsManager = injectionHelper.GetInstance <GitSettingsManager>();

            settingsManager.LoadGitSettings();

            //delayed called must be used for serialized properties to be loaded
            EditorApplication.delayCall += () =>
            {
                settingsManager.LoadOldSettingsFile();
            };

            HookManager        = injectionHelper.GetInstance <GitHookManager>();
            LfsManager         = injectionHelper.GetInstance <GitLfsManager>();
            ExternalManager    = injectionHelper.GetInstance <GitExternalManager>();
            CredentialsManager = injectionHelper.GetInstance <GitCredentialsManager>();
            LfsHelper          = injectionHelper.GetInstance <GitLfsHelper>();
            AsyncManager       = injectionHelper.GetInstance <GitAsyncManager>();

            injectionHelper.GetInstance <GitAutoFetcher>();
            injectionHelper.GetInstance <GitProjectOverlay>();

            GitProjectContextMenus.Init(GitManager, ExternalManager);
        }
Beispiel #8
0
        private void DoSecurity(Event current)
        {
            EditorGUILayout.BeginHorizontal();
            if (serializedSettings != null)
            {
                SerializedProperty credentialsManagerProperty = serializedSettings.FindProperty("CredentialsManager");
                int newSelectedIndex = EditorGUILayout.Popup(GitGUI.GetTempContent("Credentials Manager", "The name of the External program to use"), GitCredentialsManager.SelectedAdapterIndex, GitCredentialsManager.AdapterNames);
                credentialsManagerProperty.stringValue = newSelectedIndex >= 0 && newSelectedIndex < GitCredentialsManager.AdapterIds.Length ? GitCredentialsManager.AdapterIds[newSelectedIndex] : "";
                if (serializedSettings.ApplyModifiedPropertiesWithoutUndo())
                {
                    GitCredentialsManager.SetSelectedAdapter(newSelectedIndex);
                    AssetDatabase.SaveAssets();
                }
                GUI.enabled = newSelectedIndex >= 0;
            }
            if (GUILayout.Button(GitGUI.GetTempContent("Remove"), "minibutton", GUILayout.Width(64)))
            {
                if (EditorUtility.DisplayDialog("Remove Credentials Manager", "This will remove all stored passwords in the Manager. Usernames and URLs will be kept in Unity", "Remove", "Cancel"))
                {
                    GitCredentialsManager.SetSelectedAdapter(-1);
                }
            }
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();

            if (GitManager.GitCredentials == null)
            {
                EditorGUILayout.HelpBox("No Git Credentials", MessageType.Warning);
                if (GUILayout.Button("Create Credentials File"))
                {
                    GitManager.GitCredentials = CreateInstance <GitCredentials>();
                    if (!Directory.Exists("Assets/Editor Default Resources/UniGit"))
                    {
                        AssetDatabase.CreateFolder("Assets/Editor Default Resources", "UniGit");
                    }
                    AssetDatabase.CreateAsset(GitManager.GitCredentials, "Assets/Editor Default Resources/UniGit/Git-Credentials.asset");
                    AssetDatabase.SaveAssets();
                }
                return;
            }

            foreach (var gitCredential in GitManager.GitCredentials)
            {
                GUILayout.Label(GitGUI.GetTempContent(gitCredential.Name), "ShurikenModuleTitle");
                EditorGUILayout.Space();
                EditorGUILayout.BeginVertical("ShurikenModuleBg");
                EditorGUI.BeginChangeCheck();
                GUI.SetNextControlName(gitCredential.URL + " Credential Name");
                gitCredential.Name = EditorGUILayout.TextField(GitGUI.GetTempContent("Name"), gitCredential.Name);
                GUI.enabled        = false;
                GUI.SetNextControlName(gitCredential.URL + " Credential URL");
                EditorGUILayout.TextField(GitGUI.GetTempContent("URL"), gitCredential.URL);
                GUI.enabled = true;
                EditorGUILayout.Space();
                GUILayout.Label(GUIContent.none, "ShurikenLine");
                EditorGUILayout.Space();
                bool newIsToken = gitCredential.IsToken;
                newIsToken = EditorGUILayout.Toggle(GitGUI.GetTempContent("Is Token", "Are credentials used as a token, like in GitHub."), newIsToken);
                if (newIsToken != gitCredential.IsToken)
                {
                    gitCredential.IsToken = newIsToken;
                    if (gitCredential.IsToken)
                    {
                        GitCredentialsManager.ClearCredentialPassword(gitCredential.URL);
                    }
                }

                if (gitCredential.IsToken)
                {
                    GUI.SetNextControlName(gitCredential.URL + " Credential Token");
                    string newUsername = EditorGUILayout.DelayedTextField(GitGUI.GetTempContent("Token"), gitCredential.Username);
                    if (newUsername != gitCredential.Username)
                    {
                        GitCredentialsManager.SetNewUsername(gitCredential.URL, newUsername);
                    }
                }
                else
                {
                    GUI.SetNextControlName(gitCredential.URL + " Credential username");
                    string newUsername = EditorGUILayout.DelayedTextField(GitGUI.GetTempContent("Username"), gitCredential.Username);
                    if (newUsername != gitCredential.Username)
                    {
                        GitCredentialsManager.SetNewUsername(gitCredential.URL, newUsername);
                    }
                    GUI.SetNextControlName(gitCredential.URL + " Credential New Password");
                    gitCredential.NewPassword = EditorGUILayout.PasswordField(GitGUI.GetTempContent("New Password"), gitCredential.NewPassword);

                    if (!gitCredential.HasPassword)
                    {
                        EditorGUILayout.HelpBox("Credential has no set Password", MessageType.Warning);
                    }
                }

                if (EditorGUI.EndChangeCheck())
                {
                    EditorUtility.SetDirty(GitManager.GitCredentials);
                }

                GUI.enabled = !string.IsNullOrEmpty(gitCredential.NewPassword);
                EditorGUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button(GitGUI.GetTempContent("Change Password"), "minibuttonleft"))
                {
                    GitCredentialsManager.SetNewPassword(gitCredential.URL, gitCredential.Username, gitCredential.NewPassword);
                    gitCredential.NewPassword = "";
                    EditorUtility.SetDirty(GitManager.GitCredentials);
                    GUI.FocusControl("");
                    EditorUtility.DisplayDialog("Password Changed", "Password successfully changed", "Ok");
                }
                GUI.enabled = gitCredential.HasPassword;
                if (GUILayout.Button(GitGUI.GetTempContent("Clear Password"), "minibuttonmid"))
                {
                    GitCredentialsManager.ClearCredentialPassword(gitCredential.URL);
                    EditorUtility.SetDirty(GitManager.GitCredentials);
                    AssetDatabase.SaveAssets();
                }
                GUI.enabled = true;
                if (GUILayout.Button(GitGUI.GetTempContent("Save"), "minibuttonmid"))
                {
                    EditorUtility.SetDirty(GitManager.GitCredentials);
                    AssetDatabase.SaveAssets();
                }
                if (GUILayout.Button(GitGUI.GetTempContent("Remove"), "minibuttonright"))
                {
                    GitCredentialsManager.DeleteCredentials(gitCredential.URL);
                    GUIUtility.ExitGUI();
                    return;
                }
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(GitGUI.GetTempContent("Add Credentials")))
            {
                PopupWindow.Show(addCredentialsRect, new AddCredentialPopup());
            }
            if (current.type == EventType.Repaint)
            {
                addCredentialsRect = GUILayoutUtility.GetLastRect();
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
        }
Beispiel #9
0
        internal static void Initlize()
        {
            repoPathCached = Application.dataPath.Replace("/Assets", "").Replace("/", "\\");

            if (!IsValidRepo)
            {
                return;
            }

            gitCredentials = EditorGUIUtility.Load("UniGit/Git-Credentials.asset") as GitCredentials;
            gitSettings    = EditorGUIUtility.Load("UniGit/Git-Settings.asset") as GitSettings;
            if (gitSettings == null)
            {
                gitSettings = ScriptableObject.CreateInstance <GitSettings>();
                AssetDatabase.CreateAsset(gitSettings, "Assets/Editor Default Resources/UniGit/Git-Settings.asset");
                AssetDatabase.SaveAssets();
            }

            if (IconStyle == null)
            {
                IconStyle = new GUIStyle
                {
                    imagePosition = ImagePosition.ImageOnly,
                    alignment     = TextAnchor.LowerLeft,
                    padding       = new RectOffset(2, 2, 2, 2)
                };
            }

            if (icons == null)
            {
                icons = new Icons()
                {
                    validIcon          = EditorGUIUtility.IconContent("UniGit/success"),
                    validIconSmall     = EditorGUIUtility.IconContent("UniGit/success_small"),
                    modifiedIcon       = EditorGUIUtility.IconContent("UniGit/error"),
                    modifiedIconSmall  = EditorGUIUtility.IconContent("UniGit/error_small"),
                    addedIcon          = EditorGUIUtility.IconContent("UniGit/add"),
                    addedIconSmall     = EditorGUIUtility.IconContent("UniGit/add_small"),
                    untrackedIcon      = EditorGUIUtility.IconContent("UniGit/info"),
                    untrackedIconSmall = EditorGUIUtility.IconContent("UniGit/info_small"),
                    ignoredIcon        = EditorGUIUtility.IconContent("UniGit/minus"),
                    ignoredIconSmall   = EditorGUIUtility.IconContent("UniGit/minus_small"),
                    conflictIcon       = EditorGUIUtility.IconContent("UniGit/warning"),
                    conflictIconSmall  = EditorGUIUtility.IconContent("UniGit/warning_small"),
                    deletedIcon        = EditorGUIUtility.IconContent("UniGit/deleted"),
                    deletedIconSmall   = EditorGUIUtility.IconContent("UniGit/deleted_small"),
                    renamedIcon        = EditorGUIUtility.IconContent("UniGit/renamed"),
                    renamedIconSmall   = EditorGUIUtility.IconContent("UniGit/renamed_small"),
                    loadingIconSmall   = EditorGUIUtility.IconContent("UniGit/loading"),
                    objectIcon         = EditorGUIUtility.IconContent("UniGit/object"),
                    objectIconSmall    = EditorGUIUtility.IconContent("UniGit/object_small"),
                    metaIcon           = EditorGUIUtility.IconContent("UniGit/meta"),
                    metaIconSmall      = EditorGUIUtility.IconContent("UniGit/meta_small")
                };
            }

            EditorApplication.projectWindowItemOnGUI += CustomIcons;

            GitLfsManager.Load();
            GitHookManager.Load();
            GitExternalManager.Load();
            GitCredentialsManager.Load();

            needsFetch                 = !EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isCompiling && !EditorApplication.isUpdating;
            repositoryDirty            = true;
            GitCallbacks.EditorUpdate += OnEditorUpdate;
        }
Beispiel #10
0
        internal static void Initlize()
        {
            if (!IsValidRepo)
            {
                return;
            }

            gitCredentials = EditorGUIUtility.Load("UniGit/Git-Credentials.asset") as GitCredentials;
            gitSettings    = EditorGUIUtility.LoadRequired("UniGit/Git-Settings.asset") as GitSettings;
            if (gitSettings == null)
            {
                gitSettings = ScriptableObject.CreateInstance <GitSettings>();
                AssetDatabase.CreateAsset(gitSettings, "Assets/Editor Default Resources/UniGit/Git-Settings.asset");
                AssetDatabase.SaveAssets();
            }
            repository = new Repository(RepoPath);
            Update();

            if (IconStyle == null)
            {
                IconStyle = new GUIStyle
                {
                    imagePosition = ImagePosition.ImageOnly,
                    alignment     = TextAnchor.LowerLeft,
                    padding       = new RectOffset(2, 2, 2, 2)
                };
            }

            if (icons == null)
            {
                icons = new Icons()
                {
                    validIcon          = EditorGUIUtility.IconContent("UniGit/success"),
                    validIconSmall     = EditorGUIUtility.IconContent("UniGit/success_small"),
                    modifiedIcon       = EditorGUIUtility.IconContent("UniGit/error"),
                    modifiedIconSmall  = EditorGUIUtility.IconContent("UniGit/error_small"),
                    addedIcon          = EditorGUIUtility.IconContent("UniGit/add"),
                    addedIconSmall     = EditorGUIUtility.IconContent("UniGit/add_small"),
                    untrackedIcon      = EditorGUIUtility.IconContent("UniGit/info"),
                    untrackedIconSmall = EditorGUIUtility.IconContent("UniGit/info_small"),
                    ignoredIcon        = EditorGUIUtility.IconContent("UniGit/minus"),
                    ignoredIconSmall   = EditorGUIUtility.IconContent("UniGit/minus_small"),
                    conflictIcon       = EditorGUIUtility.IconContent("UniGit/warning"),
                    conflictIconSmall  = EditorGUIUtility.IconContent("UniGit/warning_small"),
                    deletedIcon        = EditorGUIUtility.IconContent("UniGit/deleted"),
                    deletedIconSmall   = EditorGUIUtility.IconContent("UniGit/deleted_small"),
                    renamedIcon        = EditorGUIUtility.IconContent("UniGit/renamed"),
                    renamedIconSmall   = EditorGUIUtility.IconContent("UniGit/renamed_small")
                };
            }

            EditorApplication.projectWindowItemOnGUI += CustomIcons;

            GitLfsManager.Load();
            GitHookManager.Load();
            GitExternalManager.Load();
            GitCredentialsManager.Load();

            needsFetch = true;
            EditorApplication.update += OnEditorUpdate;
        }