Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Fixed retrieving the file status from git.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrunwald committed Aug 29, 2010
1 parent 90e5e78 commit 0c2e680
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/AddIns/VersionControl/GitAddIn/Src/GitStatusCache.cs
Expand Up @@ -102,6 +102,9 @@ static void GitGetFiles(string wcRoot, GitStatusSet statusSet)

static void GitGetStatus(string wcRoot, GitStatusSet statusSet)
{
string command = "git status --porcelain --untracked-files=no";
bool hasErrors = false;

ProcessRunner runner = new ProcessRunner();
runner.WorkingDirectory = wcRoot;
runner.LogStandardOutputAndError = false;
Expand All @@ -110,11 +113,15 @@ static void GitGetStatus(string wcRoot, GitStatusSet statusSet)
Match m = statusParseRegex.Match(e.Line);
if (m.Success) {
statusSet.AddEntry(m.Groups[2].Value, StatusFromText(m.Groups[1].Value));
} else {
if (!hasErrors) {
hasErrors = true;
GitMessageView.AppendLine(runner.WorkingDirectory + "> " + command);
}
GitMessageView.AppendLine("unknown output: " + e.Line);
}
}
};
string command = "git status -a --untracked-files=no";
bool hasErrors = false;
runner.ErrorLineReceived += delegate(object sender, LineReceivedEventArgs e) {
if (!hasErrors) {
hasErrors = true;
Expand All @@ -128,19 +135,17 @@ static void GitGetStatus(string wcRoot, GitStatusSet statusSet)

static GitStatus StatusFromText(string text)
{
switch (text) {
case "deleted":
return GitStatus.Deleted;
case "modified":
return GitStatus.Modified;
case "new file":
return GitStatus.Added;
default:
throw new NotSupportedException();
}
if (text.Contains("A"))
return GitStatus.Added;
else if (text.Contains("D"))
return GitStatus.Deleted;
else if (text.Contains("M"))
return GitStatus.Modified;
else
return GitStatus.None;
}

static readonly Regex statusParseRegex = new Regex(@"#\s+(deleted|modified|new file):\s+(\S.*)$");
static readonly Regex statusParseRegex = new Regex(@"^([DMA ][DMA ])\s(\S.*)$");
}

public class GitStatusSet
Expand Down

0 comments on commit 0c2e680

Please sign in to comment.