Beispiel #1
0
            public GitHubRepository(JavaScriptObject repo, string userName, string password)
            {
                this.RepositoryName = (string)repo["name"];
                var url = new UriBuilder((string)repo["clone_url"]);

                url.UserName             = Uri.EscapeDataString(userName);
                url.Password             = Uri.EscapeDataString(password);
                this.RemoteRepositoryUrl = url.ToString();
                this.RepositoryPath      = GitPath.BuildPathFromUrl(url.ToString());
            }
Beispiel #2
0
    private void OnGUI()
    {
        GUILayout.Space(10f);
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Git[bash|cmd]", GUILayout.Width(85));
        EditorGUILayout.TextField(GitPath);
        if (GUILayout.Button("⊙", EditorStyles.miniButtonMid, GUILayout.Width(25f)))
        {
            GitPath = EditorUtility.OpenFilePanel("Select file", GitPath.Replace(@"/", "\\"), "exe");
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("GitExtensions", GUILayout.Width(85));
        EditorGUILayout.TextField(GitExtensionPath);
        if (GUILayout.Button("⊙", EditorStyles.miniButtonMid, GUILayout.Width(25f)))
        {
            GitExtensionPath = EditorUtility.OpenFilePanel("Select file", GitExtensionPath.Replace(@"/", "\\"), "exe");
        }
        EditorGUILayout.EndHorizontal();

        GUILayout.Space(10f);
        EditorGUILayout.BeginHorizontal();
        var gitUrl = "https://git-scm.com/downloads";

        EditorGUILayout.LabelField(gitUrl);
        if (GUILayout.Button("Download Git", GUILayout.Width(150f)))
        {
            Application.OpenURL(gitUrl);
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        var gitextUrl = "https://github.com/gitextensions/gitextensions/releases";

        EditorGUILayout.LabelField(gitextUrl);
        if (GUILayout.Button("Download GitExtensions", GUILayout.Width(150f)))
        {
            Application.OpenURL(gitextUrl);
        }
        EditorGUILayout.EndHorizontal();
    }
        public override bool Execute()
        {
            if (String.IsNullOrEmpty(GitPath?.Trim()))
            {
                GitPath = "git";
            }

            bool   isSubmodule   = !String.IsNullOrEmpty(SubmoduleName);
            string submoduleInfo = isSubmodule ? $" submodule {SubmoduleName}" : String.Empty;

            Log.LogMessage(MessageImportance.Normal, $"Gathering GIT commit info{submoduleInfo} in directory '{WorkingDirectory}'");

            var stdoutLines = new List <string> ();
            var stderrLines = new List <string> ();

            if (!RunGit("log -n 1 --pretty=%D HEAD", stdoutLines, stderrLines))
            {
                goto outOfHere;
            }

            string gitModules = Path.Combine(XASourceDirectory, ".gitmodules");
            string branchFull = stdoutLines [0].Trim();
            string branch;

            if (branchFull.StartsWith("HEAD, ", StringComparison.Ordinal))
            {
                Log.LogMessage(MessageImportance.Low, "  Detached HEAD, branch information available");
                // Detached HEAD with branch information
                // Sample format:
                //
                //    HEAD, origin/master, origin/d16-0-p1, origin/HEAD, master
                //
                branch = branchFull.Substring(6);
            }
            else if (branchFull.StartsWith("HEAD -> ", StringComparison.Ordinal))
            {
                Log.LogMessage(MessageImportance.Low, "  Normal branch");
                // Normal branch
                // Sample format:
                //
                //     HEAD -> bundle-ndk16-fix, origin/pr/1105
                //
                branch = branchFull.Substring(8);
            }
            else if (String.Compare("HEAD", branchFull, StringComparison.Ordinal) == 0)
            {
                Log.LogMessage(MessageImportance.Low, "  Detached HEAD, no branch information");
                // Detached HEAD without branch information
                if (isSubmodule)
                {
                    if (!RunGit($"config -f {gitModules} --get \"submodule.{SubmoduleName}.branch\"", stdoutLines, stderrLines))
                    {
                        goto outOfHere;
                    }
                    branch = stdoutLines [0];
                }
                else
                {
                    Log.LogWarning($"Unable to determine branch name from detached head state in directory {WorkingDirectory}");
                    branch = "unknown";
                }
            }
            else
            {
                Log.LogError($"Unable to parse branch name from: {branchFull}");
                branch = null;
                goto outOfHere;
            }

            int separator = branch.IndexOf(',');

            if (separator >= 0)
            {
                // We choose the first branch from the list
                branch = branch.Substring(0, separator).Trim();
            }

            separator = branch.IndexOf('/');
            if (separator >= 0)
            {
                branch = branch.Substring(separator + 1).Trim();
            }

            if (branch.StartsWith("tag: ", StringComparison.Ordinal))
            {
                branch = branch.Substring(5).Trim();
            }

            if (String.IsNullOrEmpty(branch))
            {
                Log.LogError($"Unsupported branch information format: '{branchFull}'");
                goto outOfHere;
            }

            Log.LogMessage(MessageImportance.Low, $"  Branch: {branch}");
            if (!RunGit("log -n 1 --pretty=%h HEAD", stdoutLines, stderrLines))
            {
                goto outOfHere;
            }
            string commit = stdoutLines [0].Trim();

            Log.LogMessage(MessageImportance.Low, $"  Commit hash: {commit}");

            string url;

            if (isSubmodule)
            {
                if (!RunGit($"config -f {gitModules} --get \"submodule.{SubmoduleName}.url\"", stdoutLines, stderrLines))
                {
                    goto outOfHere;
                }
                url = stdoutLines [0].Trim();
            }
            else
            {
                string remoteName = String.IsNullOrEmpty(GitRemoteName) ? "origin" : GitRemoteName;
                if (!RunGit($"config --local --get \"remote.{remoteName}.url\"", stdoutLines, stderrLines))
                {
                    goto outOfHere;
                }

                url = stdoutLines [0].Trim();
            }
            Log.LogMessage(MessageImportance.Low, $"  Repository URL: {url}");

            string organization;
            string repo;
            bool   urlParsed;

            if (url.StartsWith("git@", StringComparison.Ordinal))
            {
                urlParsed = ParseGitURL(url, out organization, out repo);
            }
            else if (url.StartsWith("https://", StringComparison.Ordinal))
            {
                urlParsed = ParseHttpsURL(url, out organization, out repo);
            }
            else if (url.StartsWith("../../", StringComparison.Ordinal))
            {
                // Special case for monodroid (although it will most likely return the git@ URL anyway)
                urlParsed = ParseRelativePathURL(url, out organization, out repo);
            }
            else
            {
                Log.LogError($"Unknown URL schema in '{url}' for directory '{WorkingDirectory}'");
                goto outOfHere;
            }

            Log.LogMessage(MessageImportance.Low, $"  Organization: {organization}");
            Log.LogMessage(MessageImportance.Low, $"  Repository: {repo}");

            CommitInfo = $"{organization}/{repo}/{branch}@{commit}";

outOfHere:
            return(!Log.HasLoggedErrors);
        }