private GitRemote ReturnRemote()
        {
            var modes = currentModes.Select(s => s.ToUpperInvariant()).ToArray();

            var isFetch = modes.Contains("FETCH");
            var isPush  = modes.Contains("PUSH");

            GitRemoteFunction remoteFunction;

            if (isFetch && isPush)
            {
                remoteFunction = GitRemoteFunction.Both;
            }
            else if (isFetch)
            {
                remoteFunction = GitRemoteFunction.Fetch;
            }
            else if (isPush)
            {
                remoteFunction = GitRemoteFunction.Push;
            }
            else
            {
                remoteFunction = GitRemoteFunction.Unknown;
            }

            string host;
            string user = null;
            var    proc = new LineParser(currentUrl);

            if (proc.Matches("http") || proc.Matches("https"))
            {
                proc.MoveToAfter(':');
                proc.MoveNext();
                proc.MoveNext();
                host = proc.ReadUntil('/');
            }
            else
            {
                //Assuming SSH here
                user = proc.ReadUntil('@');
                proc.MoveNext();
                host = proc.ReadUntil(':');

                currentUrl = currentUrl.Substring(user.Length + 1);
            }

            var remote = new GitRemote(currentName, host, currentUrl, remoteFunction, user, null, null);

            Reset();
            return(remote);
        }
Example #2
0
        protected override bool ProcessLine(string line, out GitBranch result)
        {
            base.ProcessLine(line, out result);

            if (line == null)
            {
                return(false);
            }

            var proc = new LineParser(line);

            if (proc.IsAtEnd)
            {
                return(false);
            }

            try
            {
                string name;
                string trackingName = null;

                if (proc.Matches('*'))
                {
                    proc.MoveNext();
                }
                proc.SkipWhitespace();
                if (proc.Matches("(HEAD "))
                {
                    name = "detached";
                    proc.MoveToAfter(')');
                }
                else
                {
                    name = proc.ReadUntilWhitespace();
                }

                proc.ReadUntilWhitespaceTrim();
                if (proc.Matches(trackingBranchRegex))
                {
                    trackingName = proc.ReadChunk('[', ']');
                    var indexOf = trackingName.IndexOf(':');
                    if (indexOf != -1)
                    {
                        trackingName = trackingName.Substring(0, indexOf);
                    }
                }

                result = new GitBranch(name, trackingName);
                return(true);
            }
            catch (Exception ex)
            {
                Logger.Warning(ex, "Unexpected input when listing branches");
            }

            return(false);
        }
        public override void LineReceived(string line)
        {
            if (line == null)
            {
                return;
            }

            var proc = new LineParser(line);

            if (proc.IsAtEnd)
            {
                return;
            }

            try
            {
                string name;
                string trackingName = null;

                if (proc.Matches('*'))
                {
                    proc.MoveNext();
                }
                proc.SkipWhitespace();
                if (proc.Matches("(HEAD "))
                {
                    name = "detached";
                    proc.MoveToAfter(')');
                }
                else
                {
                    name = proc.ReadUntilWhitespace();
                }

                proc.ReadUntilWhitespaceTrim();
                if (proc.Matches(trackingBranchRegex))
                {
                    trackingName = proc.ReadChunk('[', ']');
                    var indexOf = trackingName.IndexOf(':');
                    if (indexOf != -1)
                    {
                        trackingName = trackingName.Substring(0, indexOf);
                    }
                }

                var branch = new GitBranch(name, trackingName);
                RaiseOnEntry(branch);
            }
            catch (Exception ex)
            {
                Logger.Warning(ex, "Unexpected input when listing branches");
            }
        }
        protected override bool ProcessLine(string line, out GitRemote result)
        {
            base.ProcessLine(line, out result);

            //origin https://github.com/github/VisualStudio.git (fetch)

            if (line == null)
            {
                result = ReturnRemote();
                return(true);
            }

            var shouldRaiseEntry = false;

            var proc = new LineParser(line);
            var name = proc.ReadUntilWhitespace();

            proc.SkipWhitespace();

            var url = proc.ReadUntilWhitespace();

            proc.SkipWhitespace();

            proc.MoveNext();
            var mode = proc.ReadUntil(')');

            if (currentName == null)
            {
                currentName = name;
                currentUrl  = url;
                currentModes.Add(mode);
            }
            else if (currentName == name)
            {
                currentModes.Add(mode);
            }
            else
            {
                shouldRaiseEntry = true;
                result           = ReturnRemote();

                currentName = name;
                currentUrl  = url;
                currentModes.Add(mode);
            }
            return(shouldRaiseEntry);
        }
Example #5
0
        public override void LineReceived(string line)
        {
            //origin https://github.com/github/VisualStudio.git (fetch)

            if (line == null)
            {
                ReturnRemote();
                return;
            }

            var proc = new LineParser(line);
            var name = proc.ReadUntilWhitespace();
            proc.SkipWhitespace();

            var url = proc.ReadUntilWhitespace();
            proc.SkipWhitespace();

            proc.MoveNext();
            var mode = proc.ReadUntil(')');

            if (currentName == null)
            {
                currentName = name;
                currentUrl = url;
                currentModes.Add(mode);
            }
            else if (currentName == name)
            {
                currentModes.Add(mode);
            }
            else
            {
                ReturnRemote();

                currentName = name;
                currentUrl = url;
                currentModes.Add(mode);
            }
        }