private void ReturnRemote() { var modes = currentModes.Select(s => s.ToLowerInvariant()).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); } RaiseOnEntry(new GitRemote { Name = currentName, Host = host, Url = currentUrl, User = user, Function = remoteFunction }); Reset(); }
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"); } }
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); } }
public override void LineReceived(string line) { if (line == null) { ReturnStatus(); } else { Prepare(); var proc = new LineParser(line); if (gitStatus.LocalBranch == null) { if (proc.Matches("##")) { proc.MoveToAfter('#'); proc.SkipWhitespace(); string branchesString; if (proc.Matches(branchTrackedAndDelta)) { //master...origin/master [ahead 1] //master...origin/master [behind 1] //master...origin/master [ahead 1, behind 1] branchesString = proc.ReadUntilWhitespace(); proc.MoveToAfter('['); var deltaString = proc.ReadUntil(']'); var deltas = deltaString.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries); foreach (var delta in deltas) { var deltaComponents = delta.Split(' '); if (deltaComponents[0] == "ahead") { gitStatus.Ahead = Int32.Parse(deltaComponents[1]); } else if (deltaComponents[0] == "behind") { gitStatus.Behind = Int32.Parse(deltaComponents[1]); } else if (deltaComponents[0] == "gone") { } else { throw new InvalidOperationException("Unexpected deltaComponent in o"); } } } else { branchesString = proc.ReadToEnd(); } var branches = branchesString.Split(new[] { "..." }, StringSplitOptions.RemoveEmptyEntries); gitStatus.LocalBranch = branches[0]; if (branches.Length == 2) { gitStatus.RemoteBranch = branches[1]; } } else { HandleUnexpected(line); } } else { // M GitHubVS.sln //R README.md -> README2.md // D deploy.cmd //A something added.txt //?? something.txt string originalPath = null; string path = null; var status = GitFileStatus.Added; var staged = false; if (proc.Matches('?')) { //?? something.txt proc.MoveToAfter('?'); proc.SkipWhitespace(); path = proc.ReadToEnd().Trim('"'); status = GitFileStatus.Untracked; } else if (proc.Matches('!')) { //?? something.txt proc.MoveToAfter('!'); proc.SkipWhitespace(); path = proc.ReadToEnd().Trim('"'); status = GitFileStatus.Ignored; } else { if (proc.IsAtWhitespace) { proc.SkipWhitespace(); } else { staged = true; } if (proc.Matches('M')) { //M GitHubVS.sln proc.MoveNext(); proc.SkipWhitespace(); path = proc.ReadToEnd().Trim('"'); status = GitFileStatus.Modified; } else if (proc.Matches('D')) { //D deploy.cmd proc.MoveNext(); proc.SkipWhitespace(); path = proc.ReadToEnd().Trim('"'); status = GitFileStatus.Deleted; } else if (proc.Matches('R')) { //R README.md -> README2.md proc.MoveNext(); proc.SkipWhitespace(); var files = proc.ReadToEnd() .Split(new[] { "->" }, StringSplitOptions.RemoveEmptyEntries) .Select(s => s.Trim()) .Select(s => s.Trim('"')) .ToArray(); originalPath = files[0]; path = files[1]; status = GitFileStatus.Renamed; } else if (proc.Matches('A')) { //A something added.txt proc.MoveNext(); proc.SkipWhitespace(); path = proc.ReadToEnd().Trim('"'); status = GitFileStatus.Added; } else { HandleUnexpected(line); } } var gitStatusEntry = gitObjectFactory.CreateGitStatusEntry(path, status, originalPath, staged); gitStatus.Entries.Add(gitStatusEntry); } } }