Example #1
0
        /// <summary>
        /// Builds the file history from a repository path, file path and the reference to object SysVersionControlTmpItem
        /// </summary>
        /// <param name="repoPath">Repository main path</param>
        /// <param name="filePath">File to be pulling the commits</param>
        /// <param name="tmpItem">Ref to the SysVersionControlTmpItem object to be inserting to</param>
        /// <returns>A SysVersionControlTmpItem filled with the commits</returns>
        public static SysVersionControlTmpItem BuildFileHistory(string repoPath, string filePath, ref SysVersionControlTmpItem tmpItem)
        {
            FileInfo fileInfo = new FileInfo(filePath);

            using (var repo = new Repository(repoPath))
            {
                var indexPath = fileInfo.FullName.Replace(repo.Info.WorkingDirectory, string.Empty);
                var commits = repo.Head.Commits.Where(c => c.Parents.Count() == 1 && c.Tree[indexPath] != null && (c.Parents.FirstOrDefault().Tree[indexPath] == null || c.Tree[indexPath].Target.Id != c.Parents.FirstOrDefault().Tree[indexPath].Target.Id));

                foreach (Commit commit in commits)
                {
                    tmpItem.User = commit.Author.ToString();
                    tmpItem.GTXShaShort = commit.Sha.Substring(0, 7);
                    tmpItem.GTXSha = commit.Sha;
                    tmpItem.Comment = commit.Message;
                    tmpItem.ShortComment = commit.MessageShort;
                    tmpItem.VCSDate = commit.Committer.When.Date;
                    tmpItem.VCSTime = (int)commit.Committer.When.DateTime.TimeOfDay.TotalSeconds;
                    tmpItem.Filename_ = FileGetVersion(repoPath, fileInfo.FullName, commit.Sha, Path.Combine(Path.GetTempPath(), string.Format("{0}_{1}", commit.Sha.Substring(0, 7), fileInfo.Name)));
                    tmpItem.InternalFilename = fileInfo.FullName;
                    tmpItem.ItemPath = indexPath;
                    tmpItem.GTXFileRepoStatus = GetFileStatus(repoPath, fileInfo.FullName);
                    tmpItem.insert();
                }
            }

            return tmpItem;
        }
Example #2
0
        /// <summary>
        /// Builds the file history from a repository path, file path and the reference to object SysVersionControlTmpItem
        /// </summary>
        /// <param name="repoPath">Repository main path</param>
        /// <param name="filePath">File to be pulling the commits</param>
        /// <param name="tmpItem">Ref to the SysVersionControlTmpItem object to be inserting to</param>
        /// <returns>A SysVersionControlTmpItem filled with the commits</returns>
        public static SysVersionControlTmpItem BuildFileHistory(string repoPath, string filePath, ref SysVersionControlTmpItem tmpItem)
        {
            FileInfo fileInfo = new FileInfo(filePath);

            using (var repo = new Repository(repoPath))
            {
                var indexPath = fileInfo.FullName.Replace(repo.Info.WorkingDirectory, string.Empty);
                var commits   = repo.Head.Commits.Where(c => c.Parents.Count() == 1 && c.Tree[indexPath] != null && (c.Parents.FirstOrDefault().Tree[indexPath] == null || c.Tree[indexPath].Target.Id != c.Parents.FirstOrDefault().Tree[indexPath].Target.Id));

                foreach (Commit commit in commits)
                {
                    tmpItem.User              = commit.Author.ToString();
                    tmpItem.GTXShaShort       = commit.Sha.Substring(0, 7);
                    tmpItem.GTXSha            = commit.Sha;
                    tmpItem.Comment           = commit.Message;
                    tmpItem.ShortComment      = commit.MessageShort;
                    tmpItem.VCSDate           = commit.Committer.When.Date;
                    tmpItem.VCSTime           = (int)commit.Committer.When.DateTime.TimeOfDay.TotalSeconds;
                    tmpItem.Filename_         = FileGetVersion(repoPath, fileInfo.FullName, commit.Sha, Path.Combine(Path.GetTempPath(), string.Format("{0}_{1}", commit.Sha.Substring(0, 7), fileInfo.Name)));
                    tmpItem.InternalFilename  = fileInfo.FullName;
                    tmpItem.ItemPath          = indexPath;
                    tmpItem.GTXFileRepoStatus = GetFileStatus(repoPath, fileInfo.FullName);
                    tmpItem.insert();
                }
            }

            return(tmpItem);
        }
Example #3
0
        /// <summary>
        /// Gets all files that are dirty in index
        /// </summary>
        /// <param name="repoPath">Repository main path</param>
        /// <returns>A list of files that have status dirt in index</returns>
        public static SysVersionControlTmpItem GetFilesInIndex(string repoPath)
        {
            SysVersionControlTmpItem tmpItem = new SysVersionControlTmpItem();

            using (Repository repo = new Repository(repoPath))
            {
                if (!repo.RetrieveStatus().IsDirty)
                {
                    return(tmpItem);
                }

                var allDirtFiles = repo.RetrieveStatus(new StatusOptions {
                    Show = StatusShowOption.IndexAndWorkDir
                }).
                                   Where(t => t.State != FileStatus.Unaltered && t.State != FileStatus.Ignored);

                foreach (var dirtFile in allDirtFiles)
                {
                    FileInfo fileInfo = new FileInfo(Path.Combine(repoPath, dirtFile.FilePath));

                    IndexEntry indexEntry = repo.Index[dirtFile.FilePath];

                    //No index entry means new file, untracked content
                    if (indexEntry != null)
                    {
                        tmpItem.GTXShaShort       = indexEntry.Id.Sha.Substring(0, 7);
                        tmpItem.GTXSha            = indexEntry.Id.Sha;
                        tmpItem.Filename_         = FileGetVersion(repoPath, fileInfo.FullName, indexEntry.Id.Sha, Path.Combine(Path.GetTempPath(), indexEntry.Id.Sha + fileInfo.Extension));
                        tmpItem.InternalFilename  = fileInfo.FullName;
                        tmpItem.ItemPath          = indexEntry.Path;
                        tmpItem.GTXFileRepoStatus = GetFileStatus(repoPath, fileInfo.FullName);
                    }
                    else
                    {
                        var tempFileName = Path.Combine(Path.GetTempPath(), fileInfo.Name);

                        File.Copy(fileInfo.FullName, tempFileName, true);

                        tmpItem.Filename_         = tempFileName;
                        tmpItem.InternalFilename  = fileInfo.FullName;
                        tmpItem.ItemPath          = dirtFile.FilePath;
                        tmpItem.GTXFileRepoStatus = GetFileStatus(repoPath, fileInfo.FullName);
                    }
                    tmpItem.insert();
                }
            }

            return(tmpItem);
        }
Example #4
0
        /// <summary>
        /// Brings all commits related to the file
        /// </summary>
        /// <param name="repoPath">Repository main path</param>
        /// <param name="filePath">File to be pulling the commits</param>
        /// <returns>A SysVersionControlTmpItem filled with the commits</returns>
        public static SysVersionControlTmpItem FileHistory(string repoPath, string filePath)
        {
            SysVersionControlTmpItem tmpItem = new SysVersionControlTmpItem();

            FileInfo fileInfo = new FileInfo(filePath);

            using (var repo = new Repository(repoPath))
            {
                var indexPath = fileInfo.FullName.Replace(repo.Info.WorkingDirectory, "");
                var commits = repo.Head.Commits.Where(c => c.Parents.Count() == 1 && c.Tree[indexPath] != null && (c.Parents.FirstOrDefault().Tree[indexPath] == null || c.Tree[indexPath].Target.Id != c.Parents.FirstOrDefault().Tree[indexPath].Target.Id));

                foreach (Commit commit in commits)
                {
                    tmpItem.User = commit.Author.ToString();
                    tmpItem.GTXSha = commit.Sha.Substring(0, 7);
                    tmpItem.Comment = commit.Message;
                    tmpItem.ShortComment = commit.MessageShort;
                    tmpItem.VCSDate = commit.Committer.When.Date;
                    tmpItem.Filename_ = fileInfo.FullName;
                    tmpItem.insert();
                }
            }
            return tmpItem;
        }
Example #5
0
        /// <summary>
        /// Brings all commits related to the file
        /// </summary>
        /// <param name="repoPath">Repository main path</param>
        /// <param name="filePath">File to be pulling the commits</param>
        /// <returns>A SysVersionControlTmpItem filled with the commits</returns>
        public static SysVersionControlTmpItem FileHistory(string repoPath, string filePath)
        {
            SysVersionControlTmpItem tmpItem = new SysVersionControlTmpItem();

            FileInfo fileInfo = new FileInfo(filePath);

            using (var repo = new Repository(repoPath))
            {
                var indexPath = fileInfo.FullName.Replace(repo.Info.WorkingDirectory, "");
                var commits   = repo.Head.Commits.Where(c => c.Parents.Count() == 1 && c.Tree[indexPath] != null && (c.Parents.FirstOrDefault().Tree[indexPath] == null || c.Tree[indexPath].Target.Id != c.Parents.FirstOrDefault().Tree[indexPath].Target.Id));

                foreach (Commit commit in commits)
                {
                    tmpItem.User         = commit.Author.ToString();
                    tmpItem.GTXSha       = commit.Sha.Substring(0, 7);
                    tmpItem.Comment      = commit.Message;
                    tmpItem.ShortComment = commit.MessageShort;
                    tmpItem.VCSDate      = commit.Committer.When.Date;
                    tmpItem.Filename_    = fileInfo.FullName;
                    tmpItem.insert();
                }
            }
            return(tmpItem);
        }
Example #6
0
        /// <summary>
        /// Gets all files that are dirty in index
        /// </summary>
        /// <param name="repoPath">Repository main path</param>
        /// <returns>A list of files that have status dirt in index</returns>
        public static SysVersionControlTmpItem GetFilesInIndex(string repoPath)
        {
            SysVersionControlTmpItem tmpItem = new SysVersionControlTmpItem();

            using (Repository repo = new Repository(repoPath))
            {
                if (!repo.RetrieveStatus().IsDirty)
                    return tmpItem;

                var allDirtFiles = repo.RetrieveStatus(new StatusOptions { Show = StatusShowOption.IndexAndWorkDir }).
                                        Where(t => t.State != FileStatus.Unaltered && t.State != FileStatus.Ignored);

                foreach (var dirtFile in allDirtFiles)
                {
                    FileInfo fileInfo = new FileInfo(Path.Combine(repoPath, dirtFile.FilePath));

                    IndexEntry indexEntry = repo.Index[dirtFile.FilePath];

                    //No index entry means new file, untracked content
                    if (indexEntry != null)
                    {
                        tmpItem.GTXShaShort = indexEntry.Id.Sha.Substring(0, 7);
                        tmpItem.GTXSha = indexEntry.Id.Sha;
                        tmpItem.Filename_ = FileGetVersion(repoPath, fileInfo.FullName, indexEntry.Id.Sha, Path.Combine(Path.GetTempPath(), string.Format("{0}_{1}", indexEntry.Id.Sha.Substring(0, 7), fileInfo.Name)));
                        tmpItem.InternalFilename = fileInfo.FullName;
                        tmpItem.ItemPath = indexEntry.Path;
                        tmpItem.GTXFileRepoStatus = GetFileStatus(repoPath, fileInfo.FullName);
                    }
                    else
                    {
                        var tempFileName = Path.Combine(Path.GetTempPath(), fileInfo.Name);

                        File.Copy(fileInfo.FullName, tempFileName, true);

                        tmpItem.Filename_ = tempFileName;
                        tmpItem.InternalFilename = fileInfo.FullName;
                        tmpItem.ItemPath = dirtFile.FilePath;
                        tmpItem.GTXFileRepoStatus = GetFileStatus(repoPath, fileInfo.FullName);
                    }
                    tmpItem.insert();
                }

            }

            return tmpItem;
        }