Exemple #1
0
        private void OnGUI()
        {
            CreateStyles();

            if (gitManager == null || !gitManager.IsValidRepo)
            {
                InvalidRepoGUI(gitManager);
                return;
            }

            if (gitManager.Repository == null || selectedBranch == null)
            {
                return;
            }
            RepositoryInformation repoInformation = gitManager.Repository.Info;

            DoToolbar(toolbarRect, repoInformation);
            EditorGUILayout.Space();

            DoHistoryScrollRect(scorllRect, repoInformation);

            if (popupsQueue.Count > 0)
            {
                var content = popupsQueue.Dequeue();
                PopupWindow.Show(content.Key, content.Value);
            }
        }
        public void SetUp()
        {
            // represents a normal repo
            _normalRepo = new RepositoryInformation("AnotherProjectName", "RepoId1");
            // represents a repo that already exists when a project with the same name is added
            _duplicateRepo = new RepositoryInformation("DuplicateProject", "RepoId3");
            // represents a new repo with the same name as the project being added;
            // also represents a new repo with a name derived from the name of the duplicate project
            _newRepo = new RepositoryInformation("DuplicateProject2", RepositoryInformation.NEW_REPO);

            _repositoryInformations = new List <RepositoryInformation>
            {
                new RepositoryInformation("ProjectName", "RepoId"),
                _normalRepo,
                new RepositoryInformation("DifferentProjectName", "RepoId2"),
                _duplicateRepo,
                new RepositoryInformation("DuplicateProject1", "RepoId4"),
                new RepositoryInformation("DuplicateProjectNot", RepositoryInformation.NEW_REPO),
                _newRepo
            };

            _source = new ChorusHubRepositorySource("localhost",
                                                    _chorusHubURL + RepositoryAddress.ProjectNameVariable,
                                                    false, _repositoryInformations);
        }
Exemple #3
0
        private void MainGUI()
        {
            RepositoryInformation repoInfo = gitManager.Repository.Info;

            GUILayout.BeginArea(CommitRect);
            gitDiffWindowCommitRenderer.DoCommit(repoInfo, this, ref commitScroll);
            GUILayout.EndArea();

            toolbarRenderer.DoDiffToolbar(DiffToolbarRect, this, ref filter);

            if (diffWindowStatusList == null)
            {
                if (gitSettings.AnimationType.HasFlag(GitSettingsJson.AnimationTypeEnum.Loading))
                {
                    Repaint();
                }
                GitGUI.DrawLoading(new Rect(0, 0, position.width, position.height), GitGUI.GetTempContent(GetStatusBuildingState()));
            }
            else
            {
                DoDiffScroll(Event.current);
            }


            editoSerializedObject.ApplyModifiedProperties();

            if (Event.current.type == EventType.MouseDown)
            {
                GUIUtility.keyboardControl = 0;
                GUI.FocusControl(null);
            }
        }
        /// <summary>
        /// Creates a cache file for the specified repo that contains the repo's dependencies.
        /// </summary>
        /// <param name="repo">Repo to persist on disk</param>
        public void Persist(RepositoryInformation repo)
        {
            var repoCacheFile = GetCachePath(repo.Id);

            _logger.LogInformation("Saving cache for repo {RepoId} to file {FileName}", repo.Id, repoCacheFile);
            File.WriteAllText(repoCacheFile, JsonConvert.SerializeObject(repo.Dependencies));
        }
        private void OnGUI()
        {
            CreateStyles();

            if (!GitManager.IsValidRepo)
            {
                GitHistoryWindow.InvalidRepoGUI();
                return;
            }

            RepositoryInformation repoInfo = GitManager.Repository.Info;

            GUILayout.BeginArea(CommitRect);
            DoCommit(repoInfo);
            GUILayout.EndArea();

            SerializedProperty diffScrollProperty = editoSerializedObject.FindProperty("diffScroll");

            if (statusList == null)
            {
                return;
            }
            DoDiffScroll(Event.current);

            editoSerializedObject.ApplyModifiedProperties();

            if (Event.current.type == EventType.MouseDown)
            {
                GUIUtility.keyboardControl = 0;
                GUI.FocusControl(null);
            }
        }
Exemple #6
0
        private void DoWarningBox(Rect rect, RepositoryInformation info, BranchInfo branch)
        {
            int?       behindBy = selectedBranch.TrackingDetails.BehindBy;
            GUIContent content  = GUIContent.none;

            if (info.CurrentOperation == CurrentOperation.Merge)
            {
                content = GitGUI.GetTempContent("Merging with remote branch in progress. You <b>must</b> do a merge commit before pushing.");
            }
            else if (behindBy != null && behindBy.Value > 0)
            {
                content = GitGUI.GetTempContent(string.Format("Branch <b>{0}</b> behind tracked branch <b>{1}</b>", selectedBranch.FriendlyName, selectedBranch.TrackedBranch));
            }
            else if (branch.IsRemote)
            {
                content = GitGUI.GetTempContent("Viewing a remote branch. Showing local history of remote branch.");
            }
            else if (!branch.IsCurrentRepositoryHead)
            {
                content = GitGUI.GetTempContent("Viewing a branch that is not the HEAD.");
            }

            GUI.Box(rect, content, styles.historyHelpBox);
            GUI.Box(rect, GUIContent.none, styles.historyHelpBoxLabel);
        }
 public RepositoryInfo(RepositoryInformation information)
 {
     Path             = information.Path;
     WorkingDirectory = information.WorkingDirectory;
     IsBare           = information.IsBare;
     IsShallow        = information.IsShallow;
 }
Exemple #8
0
        static void Main(string[] args)
        {
            RepositoryInformation repo = RepositoryInformation.GetRepositoryInformationForPath(@"c:\tide");

            WriteLine($"{repo.BranchName}");
            repo.DoesCommitExists(sha);
            repo.GetFileRevision(sha, file, @"c:\tmp\git-command-test");
            ReadKey();
        }
Exemple #9
0
    public static RepositoryInformation GetRepositoryInformationForPath(string path, string gitPath = null)
    {
        var repositoryInformation = new RepositoryInformation(path, gitPath);

        if (repositoryInformation.IsGitRepository)
        {
            return(repositoryInformation);
        }
        return(null);
    }
        public string Get()
        {
            var caminhoRepository = AppDomain.CurrentDomain
                                    .BaseDirectory.Split("Softplan").FirstOrDefault();

            var repositoryInfo = RepositoryInformation
                                 .GetRepositoryInformationForPath(caminhoRepository);

            return(repositoryInfo.Url);
        }
Exemple #11
0
        private void DoHistoryScrollRect(Rect rect, RepositoryInformation info)
        {
            Event current = Event.current;

            GUI.Box(new Rect(14, rect.y + 2, 2, rect.height), GUIContent.none, "AppToolbar");

            //behind,ahead and merge checking

            bool displayWarnningBox = DoWarningBoxValidate(info);

            //commit layout
            if (current.type == EventType.Layout)
            {
                GitProfilerProxy.BeginSample("Git History Window Scroll Rect GUI Layout", this);
                Rect lastCommitRect = new Rect(32, commitSpacing, Mathf.Max(rect.width - 24, 512) - 32, 0);

                if (displayWarnningBox)
                {
                    warningBoxRect    = new Rect(lastCommitRect.x, lastCommitRect.y, lastCommitRect.width, helpBoxHeight);
                    lastCommitRect.y += helpBoxHeight + commitSpacing;
                }

                for (int i = 0; i < cachedCommits.Length; i++)
                {
                    lastCommitRect = LayoutCommit(lastCommitRect, cachedCommits[i]);
                    commitRects[i] = lastCommitRect;
                }

                historyScrollContentsRect = new Rect(0, 0, lastCommitRect.width + 32, lastCommitRect.y + lastCommitRect.height + commitSpacing * 2);
                GitProfilerProxy.EndSample();
            }
            else
            {
                GitProfilerProxy.BeginSample("Git History Window Scroll Rect GUI Other", this);
                historyScroll = GUI.BeginScrollView(rect, historyScroll, historyScrollContentsRect);

                if (displayWarnningBox)
                {
                    DoWarningBox(warningBoxRect, info);
                }

                for (int i = 0; i < cachedCommits.Length; i++)
                {
                    DoCommit(commitRects[i], rect, cachedCommits[i]);
                }

                GUI.EndScrollView();
                GitProfilerProxy.EndSample();
            }
        }
Exemple #12
0
        private void OnGUI()
        {
            CreateStyles();

            if (!GitManager.IsValidRepo)
            {
                InvalidRepoGUI();
                return;
            }

            RepositoryInformation repoInformation = GitManager.Repository.Info;

            DoToolbar(toolbarRect, repoInformation);
            EditorGUILayout.Space();

            DoHistoryScrollRect(scorllRect, repoInformation);
        }
Exemple #13
0
        private void DoWarningBox(Rect rect, RepositoryInformation info)
        {
            int?       behindBy = selectedBranch.TrackingDetails.BehindBy;
            GUIContent content  = GUIContent.none;

            if (info.CurrentOperation == CurrentOperation.Merge)
            {
                content = new GUIContent(string.Format("Merging with remote branch in progress. You <b>must</b> do a merge commit before pushing."));
            }
            else if (behindBy != null && behindBy.Value > 0)
            {
                content = new GUIContent(string.Format("Branch <b>{0}</b> behind tracked branch <b>{1}</b>", selectedBranch.FriendlyName, selectedBranch.TrackedBranch));
            }

            GUI.Box(rect, content, styles.historyHelpBox);
            GUI.Box(rect, GUIContent.none, styles.historyHelpBoxLabel);
        }
        /// <summary>
        /// Tries to read the cache file of a repository.
        /// </summary>
        /// <param name="repo">Repo to read the cache file for</param>
        /// <param name="cached">The read cached version or null if none has been created.</param>
        /// <returns>true if a cache file has been found and loaded.</returns>
        public bool TryGetCachedVersion(WritableRepositoryInformation repo, out RepositoryInformation cached)
        {
            var repoCacheFile = GetCachePath(repo.Id);

            _logger.LogInformation("Cache lookup for repo {RepoId}", repo.Id);
            if (!File.Exists(repoCacheFile))
            {
                cached = null;
                return(false);
            }

            _logger.LogInformation("Cache hit for repo {RepoId} on file {FileName}", repo.Id, repoCacheFile);
            repo.AddDependencies(JsonConvert.DeserializeObject <IReadOnlyList <string> >(File.ReadAllText(repoCacheFile)));
            cached = repo.ToRepositoryInformation();

            return(true);
        }
        public static void Pull(string repoPath, string username, string email, string password = null)
        {
            if (!Repository.IsValid(repoPath))
            {
                LogInfos(repoPath + "\nis not a valid repository.");
                return;
            }
            Repository            repo = new Repository(repoPath);
            RepositoryInformation info = repo.Info;

            try
            {
                PullOptions options = new PullOptions();
                if (password != null)
                {
                    FetchOptions fO = new FetchOptions();
                    fO.CredentialsProvider = new CredentialsHandler(
                        (url, user, types) => new UsernamePasswordCredentials
                    {
                        Username = username,
                        Password = password
                    });
                    options.FetchOptions = fO;
                }
                Commands.Pull(repo, new Signature(username, email, new DateTimeOffset(DateTime.Now)), options);
                LogInfos(info.Path + " succesful updated.");
            }
            catch (Exception e)
            {
                string text = "Update of " + info.Path + " failed.\n";
                if (e is LibGit2SharpException)
                {
                    LogInfos(text + "Check your internet connection.");
                }
                //else if (e is AuthenticationException)
                //    LogInfos(text + "Wrong username or password.");
                else
                {
                    LogInfos(text + "An unkown error occured.");
                }
            }
        }
 private void DoCommit(RepositoryInformation repoInfo)
 {
     EditorGUILayout.Space();
     EditorGUILayout.BeginHorizontal();
     if (repoInfo.CurrentOperation == CurrentOperation.Merge)
     {
         GUILayout.Label(new GUIContent("Merge"), "AssetLabel");
     }
     GUILayout.Label(new GUIContent("Commit Message: "));
     EditorGUILayout.EndHorizontal();
     commitMessage = EditorGUILayout.TextArea(commitMessage, GUILayout.Height(70));
     EditorGUILayout.BeginHorizontal();
     if (GUILayout.Button(new GUIContent("Commit")))
     {
         Commit();
     }
     GUI.enabled = !GitManager.Settings.ExternalsType.HasFlag(GitSettings.ExternalsTypeEnum.Commit);
     if (GUILayout.Button(new GUIContent("Commit and Push")))
     {
         Commit();
         ScriptableWizard.DisplayWizard <GitPushWizard>("Push", "Push");
     }
     settings.emptyCommit = GUILayout.Toggle(settings.emptyCommit, new GUIContent("Empty Commit", "Commit the message only without changes"));
     EditorGUI.BeginChangeCheck();
     settings.amendCommit = GUILayout.Toggle(settings.amendCommit, new GUIContent("Amend Commit", "Amend previous commit."));
     if (EditorGUI.EndChangeCheck())
     {
         if (settings.amendCommit && string.IsNullOrEmpty(commitMessage))
         {
             commitMessage = GitManager.Repository.Head.Tip.Message;
         }
     }
     settings.prettify = GUILayout.Toggle(settings.prettify, new GUIContent("Prettify", "Prettify the commit message"));
     GUI.enabled       = true;
     GUILayout.FlexibleSpace();
     EditorGUILayout.EndHorizontal();
     EditorGUILayout.Space();
 }
        public static void Push(string repoPath, string branch, string username, string password)
        {
            if (!Repository.IsValid(repoPath))
            {
                LogInfos(repoPath + "\nis not a valid repository.");
                return;
            }
            Repository            repo = new Repository(repoPath);
            RepositoryInformation info = repo.Info;

            try
            {
                PushOptions options = new PushOptions();
                options.CredentialsProvider = new CredentialsHandler(
                    (url, user, types) => new UsernamePasswordCredentials
                {
                    Username = username,
                    Password = password
                });
                repo.Network.Push(repo.Branches[branch], options);
                LogInfos("Push to branch " + branch + " succesful.");
            }
            catch (Exception e)
            {
                string text = "Push to branch " + branch + " failed.\n";
                if (e is LibGit2SharpException)
                {
                    LogInfos(text + "Check your internet connection.");
                }
                //else if (e is AuthenticationException)
                //    LogInfos(text + "Wrong username or password.");
                else
                {
                    LogInfos(text + "An unkown error occured.");
                }
            }
        }
Exemple #18
0
        private bool DoWarningBoxValidate(RepositoryInformation info)
        {
            int?behindBy = selectedBranch.TrackingDetails.BehindBy;

            return((behindBy != null && behindBy.Value > 0) | info.CurrentOperation == CurrentOperation.Merge);
        }
Exemple #19
0
        private void DoToolbar(Rect rect, RepositoryInformation info)
        {
            GitProfilerProxy.BeginSample("Git History Window Toolbar GUI", this);
            GUI.Box(rect, GUIContent.none, "Toolbar");
            Rect       btRect            = new Rect(rect.x, rect.y, 64, rect.height);
            GUIContent pushButtonContent = GitGUI.GetTempContent(EditorGUIUtility.FindTexture("CollabPush"), "Push", "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.MarkDirty();
                }
                else
                {
                    ScriptableWizard.DisplayWizard <GitPushWizard>("Push", "Push").Init(selectedBranch.LoadBranch());
                }
            }
            btRect      = new Rect(btRect.x + 64, btRect.y, 64, btRect.height);
            GUI.enabled = !hasConflicts;
            if (GUI.Button(btRect, GitGUI.GetTempContent(EditorGUIUtility.IconContent("CollabPull").image, "Pull", 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."), "toolbarbutton"))
            {
                Branch branch = selectedBranch.LoadBranch();
                if (branch != null)
                {
                    if (GitExternalManager.TakePull())
                    {
                        AssetDatabase.Refresh();
                        GitManager.MarkDirty();
                    }
                    else
                    {
                        ScriptableWizard.DisplayWizard <GitPullWizard>("Pull", "Pull").Init(branch);
                    }
                }
                else
                {
                    Debug.LogError("Could Not Load Branch");
                }
            }
            btRect = new Rect(btRect.x + 70, btRect.y, 64, btRect.height);
            if (GUI.Button(btRect, GitGUI.GetTempContent(EditorGUIUtility.IconContent("UniGit/GitFetch").image, "Fetch", "Get changes from remote repository but do not merge them."), "toolbarbutton"))
            {
                Branch branch = selectedBranch.LoadBranch();
                if (branch != null)
                {
                    if (branch.Remote != null)
                    {
                        if (GitExternalManager.TakeFetch(branch.Remote.Name))
                        {
                            GitManager.MarkDirty();
                        }
                        else
                        {
                            ScriptableWizard.DisplayWizard <GitFetchWizard>("Fetch", "Fetch").Init(branch);
                        }
                    }
                    else
                    {
                        Debug.LogError("Branch does not have a remote");
                    }
                }
                else
                {
                    Debug.LogError("Could not Load Branch");
                }
            }
            btRect = new Rect(btRect.x + 64, btRect.y, 64, btRect.height);
            if (GUI.Button(btRect, GitGUI.GetTempContent(EditorGUIUtility.IconContent("UniGit/GitMerge").image, "Merge", hasConflicts ? "Must Resolve conflict before merging" : "Merge fetched changes from remote repository. Changes from the latest fetch will be merged."), "toolbarbutton"))
            {
                if (GitExternalManager.TakeMerge())
                {
                    GitManager.MarkDirty();
                }
                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, GitGUI.GetTempContent(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 = GitManager.Settings.ExternalsType.HasFlag(GitSettings.ExternalsTypeEnum.Switch) || (!selectedBranch.IsRemote && !selectedBranch.IsCurrentRepositoryHead);
            if (GUI.Button(btRect, GitGUI.GetTempContent(EditorGUIUtility.IconContent("UniGit/GitCheckout").image, "Switch", selectedBranch.IsRemote ? "Cannot switch to remote branches." : selectedBranch.IsCurrentRepositoryHead ? "This branch is the active one" : "Switch to another branch"), "toolbarbutton"))
            {
                if (GitExternalManager.TakeSwitch())
                {
                    AssetDatabase.Refresh();
                    GitManager.MarkDirty();
                }

                //todo Implement native switching
            }
            GUI.enabled = true;
            GitProfilerProxy.EndSample();
        }
 // Allows us to access and test the private method
 private static bool InvokeIsMatchingName(RepositoryInformation repoInfo, string projectName)
 {
     return((bool)typeof(ChorusHubRepositorySource).InvokeMember("IsMatchingName", BindingFlags.DeclaredOnly |
                                                                 BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.InvokeMethod,
                                                                 null, null, new object[] { repoInfo, projectName }));
 }
Exemple #21
0
        private void DoToolbar(Rect rect, RepositoryInformation info)
        {
            Branch branch = selectedBranch.LoadBranch(gitManager);

            if (branch == null)
            {
                EditorGUILayout.HelpBox(string.Format("Invalid Branch: '{0}'", selectedBranch.CanonicalName), MessageType.Warning, true);
                return;
            }

            GitGUI.StartEnable();
            GitProfilerProxy.BeginSample("Git History Window Toolbar GUI", this);
            GUI.Box(rect, GUIContent.none, EditorStyles.toolbar);
            Rect       btRect            = new Rect(rect.x, rect.y, 64, rect.height);
            GUIContent pushButtonContent = GitGUI.GetTempContent("Push", GitGUI.Textures.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.";
            }
            else if (selectedBranch == null)
            {
                GUI.enabled = false;
                pushButtonContent.tooltip = "No Selected branch. Create a new branch or create atleast one commit.";
            }
            if (GUI.Button(btRect, pushButtonContent, EditorStyles.toolbarButton))
            {
                GoToPush();
            }
            btRect      = new Rect(btRect.x + 64, btRect.y, 64, btRect.height);
            GUI.enabled = !hasConflicts;
            if (GUI.Button(btRect, GitGUI.IconContent("CollabPull", "Pull", 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."), EditorStyles.toolbarButton))
            {
                GoToPull();
            }
            btRect = new Rect(btRect.x + 70, btRect.y, 64, btRect.height);
            GUIContent fetchContent = GitGUI.GetTempContent("Fetch", GitOverlay.icons.fetch.image, "Get changes from remote repository but do not merge them.");

            if (branch.Remote != null)
            {
                fetchContent.tooltip = "Branch does not have a remote.";
                GUI.enabled          = false;
            }
            if (GUI.Button(btRect, fetchContent, EditorStyles.toolbarButton))
            {
                GoToFetch();
            }
            GUI.enabled = true;
            btRect      = new Rect(btRect.x + 64, btRect.y, 64, btRect.height);
            if (GUI.Button(btRect, GitGUI.GetTempContent("Merge", GitOverlay.icons.merge.image, hasConflicts ? "Must Resolve conflict before merging" : "Merge fetched changes from remote repository. Changes from the latest fetch will be merged."), EditorStyles.toolbarButton))
            {
                GoToMerge();
            }
            GUI.enabled = gitManager.IsValidRepo;
            btRect      = new Rect(btRect.x + 64, btRect.y, 64, btRect.height);
            if (GUI.Button(btRect, GitGUI.GetTempContent("Stash", GitOverlay.icons.stashIcon.image), EditorStyles.toolbarButton))
            {
                PopupWindow.Show(btRect, new GitStashWindow(gitManager));
            }
            GUI.enabled = true;

            GUIContent branchNameContent = GitGUI.GetTempContent(string.IsNullOrEmpty(selectedBranchName) ? "Branch" : selectedBranch.FriendlyName);

            if (selectedBranch.IsRemote)
            {
                branchNameContent.image = GitGUI.IconContentTex("ToolHandleGlobal");
            }
            else if (!selectedBranch.IsCurrentRepositoryHead)
            {
                branchNameContent.image = GitGUI.IconContentTex("IN LockButton on");
            }

            float branchNameWidth = EditorStyles.toolbarDropDown.CalcSize(branchNameContent).x;

            btRect = new Rect(rect.x + rect.width - branchNameWidth, btRect.y, branchNameWidth, btRect.height);
            if (GUI.Button(btRect, branchNameContent, EditorStyles.toolbarDropDown))
            {
                GenericMenu selectBranchMenu = new GenericMenu();
                foreach (var cachedBranch in cachedBranches)
                {
                    selectBranchMenu.AddItem(new GUIContent(cachedBranch.FriendlyName), selectedBranchName == cachedBranch.CanonicalName, (b) =>
                    {
                        SetSelectedBranch((string)b);
                        StartUpdateChaches(cachedStatus);
                    }, cachedBranch.CanonicalName);
                }
                selectBranchMenu.ShowAsContext();
            }
            GitGUI.EndEnable();
            btRect = new Rect(btRect.x - 64, btRect.y, 64, btRect.height);
            GitGUI.StartEnable(gitManager.Settings.ExternalsType.IsFlagSet(GitSettingsJson.ExternalsTypeEnum.Switch) || (!selectedBranch.IsRemote && !selectedBranch.IsCurrentRepositoryHead));
            if (GUI.Button(btRect, GitGUI.GetTempContent("Switch", GitOverlay.icons.checkout.image, selectedBranch.IsRemote ? "Cannot switch to remote branches." : selectedBranch.IsCurrentRepositoryHead ? "This branch is the active one" : "Switch to another branch"), EditorStyles.toolbarButton))
            {
                if (externalManager.TakeSwitch())
                {
                    gitManager.Callbacks.IssueAssetDatabaseRefresh();
                    gitManager.MarkDirty();
                }
                else
                {
                    PopupWindow.Show(btRect, new GitCheckoutWindowPopup(gitManager, selectedBranch.LoadBranch(gitManager)));
                }
            }
            GitGUI.EndEnable();
            btRect = new Rect(btRect.x - 21, btRect.y + 1, 21, btRect.height);
            EditorGUIUtility.AddCursorRect(btRect, MouseCursor.Link);
            if (GUI.Button(btRect, GitGUI.Contents.Help, GitGUI.Styles.IconButton))
            {
                GitLinks.GoTo(GitLinks.HistoryWindowHelp);
            }
            GitProfilerProxy.EndSample();
        }
        internal void DoCommit(RepositoryInformation repoInfo, GitDiffWindow window, ref Vector2 commitScroll)
        {
            var settings = window.GitDiffSettings;

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            if (repoInfo.CurrentOperation == CurrentOperation.Merge)
            {
                GUILayout.Label(GitGUI.GetTempContent("Merge"), styles.mergeIndicator);
            }
            window.CommitMaximized = GUILayout.Toggle(window.CommitMaximized, GitGUI.GetTempContent(gitSettings.ReadFromFile ? "File Commit Message: (Read Only)" : "Commit Message: "), styles.commitMessageFoldoud, GUILayout.Width(gitSettings.ReadFromFile ? 210 : 116));
            EditorGUI.BeginDisabledGroup(true);
            if (!window.CommitMaximized)
            {
                if (!gitSettings.ReadFromFile)
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.SetNextControlName("Commit Message Field");
                    settings.commitMessage = EditorGUILayout.TextArea(settings.commitMessage, GUILayout.Height(EditorGUIUtility.singleLineHeight));
                    if (EditorGUI.EndChangeCheck())
                    {
                        window.SaveCommitMessage();
                    }
                }
                else
                {
                    GUILayout.Label(GitGUI.GetTempContent(settings.commitMessageFromFile), GUI.skin.textArea, GUILayout.Height(EditorGUIUtility.singleLineHeight));
                }
            }
            EditorGUI.EndDisabledGroup();
            EditorGUILayout.EndHorizontal();
            if (window.CommitMaximized)
            {
                commitScroll = EditorGUILayout.BeginScrollView(commitScroll, GUILayout.Height(window.CalculateCommitTextHeight()));
                if (!gitSettings.ReadFromFile)
                {
                    EditorGUI.BeginChangeCheck();
                    GUI.SetNextControlName("Commit Message Field");
                    string newCommitMessage = EditorGUILayout.TextArea(settings.commitMessage, GUILayout.ExpandHeight(true));
                    if (EditorGUI.EndChangeCheck())
                    {
                        if ((Event.current.character == ' ' || Event.current.character == '\0') && !(commitMessageLastChar == ' ' || commitMessageLastChar == '\0'))
                        {
                            if (Undo.GetCurrentGroupName() == GitDiffWindow.CommitMessageUndoGroup)
                            {
                                Undo.IncrementCurrentGroup();
                            }
                        }
                        commitMessageLastChar = Event.current.character;
                        Undo.RecordObject(window, GitDiffWindow.CommitMessageUndoGroup);
                        settings.commitMessage = newCommitMessage;
                        window.SaveCommitMessage();
                    }
                }
                else
                {
                    GUILayout.Label(GitGUI.GetTempContent(settings.commitMessageFromFile), GUI.skin.textArea, GUILayout.ExpandHeight(true));
                }
                EditorGUILayout.EndScrollView();
            }

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button(GitGUI.GetTempContent("Commit"), styles.commitButton))
            {
                GenericMenu commitMenu = new GenericMenu();
                BuildCommitMenu(commitMenu, window);
                commitMenu.ShowAsContext();
            }
            GitGUI.StartEnable(!gitSettings.ExternalsType.IsFlagSet(GitSettingsJson.ExternalsTypeEnum.Commit));
            settings.emptyCommit = GUILayout.Toggle(settings.emptyCommit, GitGUI.GetTempContent("Empty Commit", "Commit the message only without changes"));
            EditorGUI.BeginChangeCheck();
            settings.amendCommit = GUILayout.Toggle(settings.amendCommit, GitGUI.GetTempContent("Amend Commit", "Amend previous commit."));
            if (EditorGUI.EndChangeCheck())
            {
                if (settings.amendCommit)
                {
                    window.AmmendCommit();
                }
            }
            settings.prettify = GUILayout.Toggle(settings.prettify, GitGUI.GetTempContent("Prettify", "Prettify the commit message"));
            GitGUI.EndEnable();
            GUILayout.FlexibleSpace();
            if (GitGUI.LinkButtonLayout(gitOverlay.icons.donateSmall, GitGUI.Styles.IconButton))
            {
                GitLinks.GoTo(GitLinks.Donate);
            }
            if (GitGUI.LinkButtonLayout(GitGUI.Contents.Help, GitGUI.Styles.IconButton))
            {
                GitLinks.GoTo(GitLinks.DiffWindowHelp);
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
        }
Exemple #23
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();
        }
Exemple #24
0
        public IHttpActionResult Get(string code, string state)
        {
            bool   checkResult = false;
            string fromQQ      = Encryption.AesDecrypt(state);
            var    tokenModel  = githubConnector.AccessToken(code, ref checkResult); // 获取Access Token

            if (tokenModel != null)
            {
                if (!tokenModel.scope.Contains("repo") || tokenModel.scope == null)    // 用户手动更改了权限,向用户返回权限不足信息
                {
                    CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "抱歉,您申请的权限不足,绑定失败!");
                    return(BadRequest("权限不足"));
                }

                // 调用Github API获取用户数据
                try
                {
                    GithubUserInfo userInfo = githubConnector.GetUserInfo(tokenModel.access_token);                      // 用户信息
                    List <GithubRepositoryInfo> repositories = githubConnector.GetRepositories(tokenModel.access_token); // 授权用户的所有仓库信息

                    using (var context = new GithubWatcherContext())
                    {
                        var user = context.GithubBindings.FirstOrDefault(s => s.GithubUserName == userInfo.Login);

                        // 如果不存在,则往数据库中添加信息
                        if (user == null)
                        {
                            GithubBinding newBinding = new GithubBinding();
                            newBinding.QQ             = fromQQ;
                            newBinding.GithubUserName = userInfo.Login;
                            newBinding.AccessToken    = tokenModel.access_token;

                            context.GithubBindings.Add(newBinding);

                            CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "绑定Github账户" + userInfo.Login + "成功!");
                        }
                        else if (user.QQ == fromQQ)
                        {
                            if (user.AccessToken == tokenModel.access_token)
                            {
                                CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "您已经绑定过该Github账户!");
                            }
                            else
                            {
                                // 更新accessToken
                                user.AccessToken = tokenModel.access_token;
                                CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "您已经绑定过该Github账户,已为您刷新Access Token,请尽快完成仓库绑定操作。");
                            }
                        }
                        else
                        {
                            CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "抱歉,该Github账户已被其他用户绑定!");
                        }


                        foreach (var repository in repositories)
                        {
                            var query = context.RepositoryInformations.FirstOrDefault(s => s.GithubUserName == userInfo.Login && s.Repository == repository.FullName);

                            // 如果不存在,则往数据库中添加信息
                            if (query == null)
                            {
                                RepositoryInformation newRepositoryInfo = new RepositoryInformation();
                                newRepositoryInfo.GithubUserName = userInfo.Login;
                                newRepositoryInfo.Repository     = repository.FullName;

                                context.RepositoryInformations.Add(newRepositoryInfo);
                            }
                        }

                        context.SaveChanges();
                        return(Ok("绑定成功!"));
                    }
                }
                catch (Exception e)
                {
                    if (e.Message.Contains("基础连接已经关闭: 发送时发生错误"))
                    {
                        CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "您的访问过于频繁,请稍后再试!");
                    }
                    else
                    {
                        CQ.Api.SendPrivateMessage(Convert.ToInt64(fromQQ), "错误:" + e.Message + "请联系管理员QQ:2426837192!");
                    }
                    return(BadRequest(e.Message));
                }
            }

            return(BadRequest("获取Access Token失败!"));
        }
Exemple #25
0
        private void DoHistoryScrollRect(Rect rect, RepositoryInformation info)
        {
            if (loadingCommits != null && !loadingCommits.IsDone)
            {
                Repaint();
                GitGUI.DrawLoading(rect, GitGUI.GetTempContent("Loading Commit History"));
                return;
            }

            Event current = Event.current;

            GUI.Box(new Rect(14, rect.y + 2, 2, rect.height), GUIContent.none, styles.historyLine);

            //behind,ahead and merge checking

            bool displayWarnningBox = DoWarningBoxValidate(info, selectedBranch);

            //commit layout
            if (current.type == EventType.Layout)
            {
                GitProfilerProxy.BeginSample("Git History Window Scroll Rect GUI Layout", this);
                Rect lastCommitRect = new Rect(32, commitSpacing, Mathf.Max(rect.width - 24, 512) - 32, 0);

                if (displayWarnningBox)
                {
                    warningBoxRect    = new Rect(lastCommitRect.x, lastCommitRect.y, lastCommitRect.width, helpBoxHeight);
                    lastCommitRect.y += helpBoxHeight + commitSpacing;
                }

                for (int i = 0; i < cachedCommits.Length; i++)
                {
                    lastCommitRect = LayoutCommit(lastCommitRect, cachedCommits[i]);
                    if (i < commitRects.Length)
                    {
                        commitRects[i] = lastCommitRect;
                    }
                }

                historyScrollContentsRect         = new Rect(0, 0, lastCommitRect.width + 32, lastCommitRect.y + lastCommitRect.height + commitSpacing * 2);
                historyScrollContentsRect.height += EditorGUIUtility.singleLineHeight * 3;
                GitProfilerProxy.EndSample();
            }
            else
            {
                GitProfilerProxy.BeginSample("Git History Window Scroll Rect GUI Other", this);
                historyScroll = GUI.BeginScrollView(rect, historyScroll, historyScrollContentsRect);

                if (displayWarnningBox)
                {
                    DoWarningBox(warningBoxRect, info, selectedBranch);
                }

                for (int i = 0; i < cachedCommits.Length; i++)
                {
                    if (i < commitRects.Length)
                    {
                        DoCommit(commitRects[i], rect, cachedCommits[i]);
                    }
                }

                Rect commitsCountRect = new Rect(32, historyScrollContentsRect.height - EditorGUIUtility.singleLineHeight * 4, historyScrollContentsRect.width - 64, EditorGUIUtility.singleLineHeight);

                GUI.Label(commitsCountRect, GitGUI.GetTempContent(cachedCommits.Length + " / " + maxCommitsCount), EditorStyles.centeredGreyMiniLabel);

                Rect resetRect    = new Rect(historyScrollContentsRect.width / 2, historyScrollContentsRect.height - EditorGUIUtility.singleLineHeight * 3, 64, EditorGUIUtility.singleLineHeight);
                Rect loadMoreRect = new Rect(historyScrollContentsRect.width / 2 - 64, historyScrollContentsRect.height - EditorGUIUtility.singleLineHeight * 3, 64, EditorGUIUtility.singleLineHeight);
                if (GUI.Button(loadMoreRect, GitGUI.IconContent("ol plus", "More", "Show more commits."), styles.loadMoreCommitsBtn))
                {
                    maxCommitsCount += CommitsPerExpand;
                    StartUpdateChaches(cachedStatus);
                }
                GitGUI.StartEnable(maxCommitsCount != MaxFirstCommitCount);
                if (GUI.Button(resetRect, GitGUI.GetTempContent("Reset", "Reset the number of commits show."), styles.resetCommitsBtn))
                {
                    if (MaxFirstCommitCount < maxCommitsCount)
                    {
                        maxCommitsCount = MaxFirstCommitCount;
                        Array.Resize(ref cachedCommits, maxCommitsCount);
                    }
                    else
                    {
                        maxCommitsCount = MaxFirstCommitCount;
                        StartUpdateChaches(cachedStatus);
                    }
                }
                GitGUI.EndEnable();
                GUI.EndScrollView();
                GitProfilerProxy.EndSample();
            }
        }