Esempio n. 1
0
        public static GitSubmoduleStatus GetSubmoduleStatus(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }
            var status = new GitSubmoduleStatus();

            using (StringReader reader = new StringReader(text))
            {
                string line = reader.ReadLine();

                if (line != null)
                {
                    var match = Regex.Match(line, @"diff --git a/(\S+) b/(\S+)");
                    if (match != null && match.Groups.Count > 0)
                    {
                        status.Name    = match.Groups[1].Value;
                        status.OldName = match.Groups[2].Value;
                    }
                }

                while ((line = reader.ReadLine()) != null)
                {
                    if (!line.Contains("Subproject"))
                    {
                        continue;
                    }

                    char         c      = line[0];
                    const string commit = "commit ";
                    string       hash   = "";
                    int          pos    = line.IndexOf(commit);
                    if (pos >= 0)
                    {
                        hash = line.Substring(pos + commit.Length);
                    }
                    bool bdirty = hash.EndsWith("-dirty");
                    hash = hash.Replace("-dirty", "");
                    if (c == '-')
                    {
                        status.OldCommit = hash;
                    }
                    else if (c == '+')
                    {
                        status.Commit  = hash;
                        status.IsDirty = bdirty;
                    }
                }
            }
            return(status);
        }
Esempio n. 2
0
        public static GitSubmoduleStatus GetSubmoduleStatus(string text, GitModule module, string fileName)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }
            var status = new GitSubmoduleStatus();

            using (StringReader reader = new StringReader(text))
            {
                string line = reader.ReadLine();

                if (line != null)
                {
                    var match = Regex.Match(line, @"diff --git a/(.+)\sb/(.+)");
                    if (match.Groups.Count > 1)
                    {
                        status.Name    = match.Groups[1].Value;
                        status.OldName = match.Groups[2].Value;
                    }
                    else
                    {
                        match = Regex.Match(line, @"diff --cc (.+)");
                        if (match.Groups.Count > 1)
                        {
                            status.Name    = match.Groups[1].Value;
                            status.OldName = match.Groups[1].Value;
                        }
                    }
                }

                while ((line = reader.ReadLine()) != null)
                {
                    if (!line.Contains("Subproject"))
                    {
                        continue;
                    }

                    char         c      = line[0];
                    const string commit = "commit ";
                    string       hash   = "";
                    int          pos    = line.IndexOf(commit);
                    if (pos >= 0)
                    {
                        hash = line.Substring(pos + commit.Length);
                    }
                    bool bdirty = hash.EndsWith("-dirty");
                    hash = hash.Replace("-dirty", "");
                    if (c == '-')
                    {
                        status.OldCommit = hash;
                    }
                    else if (c == '+')
                    {
                        status.Commit  = hash;
                        status.IsDirty = bdirty;
                    }
                    // TODO: Support combined merge
                }
            }

            if (status.OldCommit != null && status.Commit != null)
            {
                var submodule = module.GetSubmodule(fileName);
                status.AddedCommits   = submodule.GetCommitCount(status.Commit, status.OldCommit);
                status.RemovedCommits = submodule.GetCommitCount(status.OldCommit, status.Commit);
            }

            return(status);
        }
Esempio n. 3
0
 private static Image GetItemImage(GitSubmoduleStatus gitSubmoduleStatus)
 {
     if (gitSubmoduleStatus == null)
         return Resources.IconFolderSubmodule;
     if (gitSubmoduleStatus.Status == SubmoduleStatus.FastForward || gitSubmoduleStatus.Status == SubmoduleStatus.NewerTime)
         return gitSubmoduleStatus.IsDirty ? Resources.IconSubmoduleRevisionUpDirty : Resources.IconSubmoduleRevisionUp;
     if (gitSubmoduleStatus.Status == SubmoduleStatus.Rewind || gitSubmoduleStatus.Status == SubmoduleStatus.OlderTime)
         return gitSubmoduleStatus.IsDirty ? Resources.IconSubmoduleRevisionDownDirty : Resources.IconSubmoduleRevisionDown;
     return !gitSubmoduleStatus.IsDirty ? Resources.Modified : Resources.IconSubmoduleDirty;
 }
Esempio n. 4
0
        public static GitSubmoduleStatus GetSubmoduleStatus(string text)
        {
            if (string.IsNullOrEmpty(text))
                return null;
            var status = new GitSubmoduleStatus();
            using (StringReader reader = new StringReader(text))
            {
                string line = reader.ReadLine();

                if (line != null)
                {
                    var match = Regex.Match(line, @"diff --git a/(\S+) b/(\S+)");
                    if (match.Groups.Count > 1)
                    {
                        status.Name = match.Groups[1].Value;
                        status.OldName = match.Groups[2].Value;
                    }
                    else
                    {
                        match = Regex.Match(line, @"diff --cc (\S+)");
                        if (match.Groups.Count > 1)
                        {
                            status.Name = match.Groups[1].Value;
                            status.OldName = match.Groups[1].Value;
                        }
                    }
                }

                while ((line = reader.ReadLine()) != null)
                {
                    if (!line.Contains("Subproject"))
                        continue;

                    char c = line[0];
                    const string commit = "commit ";
                    string hash = "";
                    int pos = line.IndexOf(commit);
                    if (pos >= 0)
                        hash = line.Substring(pos + commit.Length);
                    bool bdirty = hash.EndsWith("-dirty");
                    hash = hash.Replace("-dirty", "");
                    if (c == '-')
                    {
                        status.OldCommit = hash;
                    }
                    else if (c == '+')
                    {
                        status.Commit = hash;
                        status.IsDirty = bdirty;
                    }
                    // TODO: Support combined merge
                }
            }
            return status;
        }
Esempio n. 5
0
        public static string ProcessSubmoduleStatus(GitModule module, GitSubmoduleStatus status)
        {
            GitModule gitmodule = module.GetSubmodule(status.Name);
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("Submodule " + status.Name + " Change");

            sb.AppendLine();
            sb.AppendLine("From:\t" + (status.OldCommit ?? "null"));
            CommitData oldCommitData = null;
            if (gitmodule.IsValidGitWorkingDir())
            {
                string error = "";
                if (status.OldCommit != null)
                    oldCommitData = CommitData.GetCommitData(gitmodule, status.OldCommit, ref error);
                if (oldCommitData != null)
                {
                    sb.AppendLine("\t\t\t\t\t" + GetRelativeDateString(DateTime.UtcNow, oldCommitData.CommitDate.UtcDateTime) + oldCommitData.CommitDate.LocalDateTime.ToString(" (ddd MMM dd HH':'mm':'ss yyyy)"));
                    var delim = new char[] { '\n', '\r' };
                    var lines = oldCommitData.Body.Trim(delim).Split(new string[] { "\r\n" }, 0);
                    foreach (var curline in lines)
                        sb.AppendLine("\t\t" + curline);
                }
            }
            else
                sb.AppendLine();

            sb.AppendLine();
            string dirty = !status.IsDirty ? "" : " (dirty)";
            sb.AppendLine("To:\t\t" + (status.Commit ?? "null") + dirty);
            CommitData commitData = null;
            if (gitmodule.IsValidGitWorkingDir())
            {
                string error = "";
                if (status.Commit != null)
                    commitData = CommitData.GetCommitData(gitmodule, status.Commit, ref error);
                if (commitData != null)
                {
                    sb.AppendLine("\t\t\t\t\t" + GetRelativeDateString(DateTime.UtcNow, commitData.CommitDate.UtcDateTime) + commitData.CommitDate.LocalDateTime.ToString(" (ddd MMM dd HH':'mm':'ss yyyy)"));
                    var delim = new char[] { '\n', '\r' };
                    var lines = commitData.Body.Trim(delim).Split(new string[] { "\r\n" }, 0);
                    foreach (var curline in lines)
                        sb.AppendLine("\t\t" + curline);
                }
            }
            else
                sb.AppendLine();

            sb.AppendLine();
            var submoduleStatus = gitmodule.CheckSubmoduleStatus(status.Commit, status.OldCommit, commitData, oldCommitData);
            sb.Append("Type: ");
            switch (submoduleStatus)
            {
                case SubmoduleStatus.NewSubmodule:
                    sb.AppendLine("New submodule");
                    break;
                case SubmoduleStatus.FastForward:
                    sb.AppendLine("Fast Forward");
                    break;
                case SubmoduleStatus.Rewind:
                    sb.AppendLine("Rewind");
                    break;
                case SubmoduleStatus.NewerTime:
                    sb.AppendLine("Newer commit time");
                    break;
                case SubmoduleStatus.OlderTime:
                    sb.AppendLine("Older commit time");
                    break;
                case SubmoduleStatus.SameTime:
                    sb.AppendLine("Same commit time");
                    break;
                default:
                    sb.AppendLine("Unknown");
                    break;
            }

            if (status.Commit != null && status.OldCommit != null)
            {
                if (status.IsDirty)
                {
                    string statusText = gitmodule.GetStatusText(false);
                    if (!String.IsNullOrEmpty(statusText))
                    {
                        sb.AppendLine("\nStatus:");
                        sb.Append(statusText);
                    }
                }

                string diffs = gitmodule.GetDiffFilesText(status.OldCommit, status.Commit);
                if (!String.IsNullOrEmpty(diffs))
                {
                    sb.AppendLine("\nDifferences:");
                    sb.Append(diffs);
                }
            }

            return sb.ToString();
        }
Esempio n. 6
0
 public void ViewCurrentChanges(string fileName, string oldFileName, bool staged,
     bool isSubmodule, GitSubmoduleStatus status)
 {
     if (!isSubmodule)
         _async.Load(() => Module.GetCurrentChanges(fileName, oldFileName, staged, GetExtraDiffArguments(), Encoding),
             ViewStagingPatch);
     else if (status != null)
         _async.Load(() => GitCommandHelpers.ProcessSubmoduleStatus(Module, status), ViewPatch);
     else
         _async.Load(() => GitCommandHelpers.ProcessSubmodulePatch(Module,
             Module.GetCurrentChanges(fileName, oldFileName, staged, GetExtraDiffArguments(), Encoding)), ViewPatch);
 }