Example #1
0
        /// <summary>
        /// Initializes a SysVersionControlTmpItem from a tree path
        /// </summary>
        /// <param name="repoPath">The main repo path</param>
        /// <param name="tree">The tree git to iterate from</param>
        /// <param name="tmpItem">ref to the SysVersionControlTmpItem</param>
        /// <param name="recursive">If true will go recursively to all tree entries found (in case of a dir)</param>
        public static void InitTmpItemFromTree(string repoPath, Tree tree, ref SysVersionControlTmpItem tmpItem, bool recursive = true)
        {
            if (tmpItem == null)
            {
                tmpItem = new SysVersionControlTmpItem();
            }

            foreach (var treeEntry in tree)
            {
                if (treeEntry.TargetType == TreeEntryTargetType.Tree && recursive)
                {
                    InitTmpItemFromTree(repoPath, treeEntry.Target as Tree, ref tmpItem);
                }

                if (treeEntry.Mode == Mode.Directory || treeEntry.Mode == Mode.ExecutableFile || treeEntry.Mode == Mode.GitLink)
                {
                    continue;
                }

                string fileName = Path.Combine(repoPath, treeEntry.Path);

                if (SysVersionControlTmpItem.isValidXPOFile(fileName))
                {
                    tmpItem.ItemPath         = "\\" + treeEntry.Path.Replace(repoPath, string.Empty);
                    tmpItem.Filename_        = fileName;
                    tmpItem.InternalFilename = fileName;
                    tmpItem.insert();
                }
            }
        }
Example #2
0
        /// <summary>
        /// Get a single file version from the git repository
        /// </summary>
        /// <param name="repoPath">Repository main path</param>
        /// <param name="tmpItem">The temporary item table holding the sha commit</param>
        /// <returns>a temporary file path</returns>
        public static string FileGetVersion(string repoPath, string fileName, SysVersionControlTmpItem tmpItem)
        {
            string indexPath = tmpItem.InternalFilename.Replace(repoPath, string.Empty);

            CheckoutOptions options = new CheckoutOptions();

            options.CheckoutModifiers = CheckoutModifiers.Force;

            using (Repository repo = new Repository(repoPath))
            {
                var commit = repo.Lookup <Commit>(tmpItem.GTXSha);
                if (commit != null)
                {
                    try
                    {
                        repo.CheckoutPaths(commit.Id.Sha, new [] { fileName }, options);
                    }
                    catch (MergeConflictException ex)
                    {
                        //should not reach here as we're forcing checkout
                        throw ex;
                    }
                }
            }

            return(fileName);
        }
Example #3
0
        /// <summary>
        /// Synchronizes a folder
        /// </summary>
        /// <param name="repoPath">Main repository path</param>
        /// <param name="folderPath">The folder to synchronize (checkout). Could be the model path or the layer path</param>
        /// <param name="forceCheckout">Forces the update from the latest commit (head tip)</param>
        /// <returns>A SysVersionControlItem with all the files that have been affected</returns>
        public static SysVersionControlTmpItem FolderSync(string repoPath, string folderPath, bool forceCheckout)
        {
            SysVersionControlTmpItem tmpItem = new SysVersionControlTmpItem();

            CheckoutOptions checkoutOptions = new CheckoutOptions
            {
                CheckoutModifiers =
                    forceCheckout
                        ? CheckoutModifiers.Force
                        : CheckoutModifiers.None
            };

            string tipSha;
            string folderName = folderPath.Split('\\').Last();

            using (Repository repo = new Repository(repoPath))
            {
                repo.CheckoutPaths(repo.Head.Tip.Id.Sha, new[] { folderPath }, checkoutOptions);
                tipSha = repo.Head.Tip.Id.Sha;

                InitTmpItemFromTree(repoPath, repo.Head.Tip.Tree[folderName].Target as Tree, ref tmpItem);
            }

            return(tmpItem);
        }
Example #4
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 #5
0
        /// <summary>
        /// Brings all commits related to a directory
        /// </summary>
        /// <param name="repoPath">Repository main path</param>
        /// <param name="dirPath">Directory to be pulling the commits</param>
        /// <returns>A SysVersionControlTmpItem filled with the commits of files in a directory</returns>
        public static SysVersionControlTmpItem DirectoryHistory(string repoPath, string dirPath)
        {
            SysVersionControlTmpItem tmpItem = new SysVersionControlTmpItem();

            try
            {
                DirectoryInfo dirInfo = new DirectoryInfo(dirPath);

                if (!dirInfo.Exists)
                {
                    return(tmpItem);
                }

                foreach (var file in dirInfo.GetFiles())
                {
                    FileHistory(repoPath, file.FullName, ref tmpItem);
                }
            }
            catch (IOException ex)
            {
                throw ex;
            }

            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(), 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 #7
0
        /// <summary>
        /// Brings all commits related to the file. Currently being called from AX.
        /// </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();

            try
            {
                BuildFileHistory(repoPath, filePath, ref tmpItem);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(tmpItem);
        }
Example #8
0
        /// <summary>
        /// Brings all commits related to a directory
        /// </summary>
        /// <param name="repoPath">Repository main path</param>
        /// <param name="dirPath">Directory to be pulling the commits</param>
        /// <returns>A SysVersionControlTmpItem filled with the commits of files in a directory</returns>
        public static SysVersionControlTmpItem DirectoryHistory(string repoPath, string dirPath)
        {
            SysVersionControlTmpItem tmpItem = new SysVersionControlTmpItem();

            try
            {
                DirectoryInfo dirInfo = new DirectoryInfo(dirPath);

                if (!dirInfo.Exists)
                    return tmpItem;

                foreach (var file in dirInfo.GetFiles())
                {
                    FileHistory(repoPath, file.FullName, ref tmpItem);
                }
            }
            catch (IOException ex)
            {
                throw ex;
            }

            return tmpItem;
        }
Example #9
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();

            try
            {
                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(), commit.Sha + fileInfo.Extension));
                        tmpItem.InternalFilename  = fileInfo.FullName;
                        tmpItem.ItemPath          = indexPath;
                        tmpItem.GTXFileRepoStatus = GetFileStatus(repoPath, fileInfo.FullName);
                        tmpItem.insert();
                    }
                }
            }
            catch (IOException ex)
            {
                throw ex;
            }

            return(tmpItem);
        }
Example #10
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 #11
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 #12
0
        /// <summary>
        /// Initializes a SysVersionControlTmpItem from a tree path
        /// </summary>
        /// <param name="repoPath">The main repo path</param>
        /// <param name="tree">The tree git to iterate from</param>
        /// <param name="tmpItem">ref to the SysVersionControlTmpItem</param>
        /// <param name="recursive">If true will go recursively to all tree entries found (in case of a dir)</param>
        public static void InitTmpItemFromTree(string repoPath, Tree tree, ref SysVersionControlTmpItem tmpItem, bool recursive = true)
        {
            if (tmpItem == null)
                tmpItem = new SysVersionControlTmpItem();

            foreach (var treeEntry in tree)
            {
                if (treeEntry.TargetType == TreeEntryTargetType.Tree && recursive)
                    InitTmpItemFromTree(repoPath, treeEntry.Target as Tree, ref tmpItem);

                if (treeEntry.Mode == Mode.Directory || treeEntry.Mode == Mode.ExecutableFile || treeEntry.Mode == Mode.GitLink)
                    continue;

                string fileName = Path.Combine(repoPath, treeEntry.Path);

                if (SysVersionControlTmpItem.isValidXPOFile(fileName))
                {
                    tmpItem.ItemPath = "\\" + treeEntry.Path.Replace(repoPath, string.Empty);
                    tmpItem.Filename_ = fileName;
                    tmpItem.InternalFilename = fileName;
                    tmpItem.insert();
                }

            }
        }
Example #13
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;
        }
Example #14
0
        /// <summary>
        /// Synchronizes a folder
        /// </summary>
        /// <param name="repoPath">Main repository path</param>
        /// <param name="folderPath">The folder to synchronize (checkout). Could be the model path or the layer path</param>
        /// <param name="forceCheckout">Forces the update from the latest commit (head tip)</param>
        /// <returns>A SysVersionControlItem with all the files that have been affected</returns>
        public static SysVersionControlTmpItem FolderSync(string repoPath, string folderPath, bool forceCheckout)
        {
            SysVersionControlTmpItem tmpItem = new SysVersionControlTmpItem();

            CheckoutOptions checkoutOptions = new CheckoutOptions
            {
                CheckoutModifiers =
                    forceCheckout
                        ? CheckoutModifiers.Force
                        : CheckoutModifiers.None
            };

            string tipSha;
            string folderName = folderPath.Split('\\').Last();

            using (Repository repo = new Repository(repoPath))
            {
                repo.CheckoutPaths(repo.Head.Tip.Id.Sha, new[] { folderPath }, checkoutOptions);
                tipSha = repo.Head.Tip.Id.Sha;

                InitTmpItemFromTree(repoPath, repo.Head.Tip.Tree[folderName].Target as Tree, ref tmpItem);

            }

            return tmpItem;
        }
Example #15
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>
        /// <param name="tmpItem">Ref to the SysVersionControlTmpItem object to be inserting to</param>
        /// <returns>A SysVersionControlTmpItem filled with the commits</returns>
        public static SysVersionControlTmpItem FileHistory(string repoPath, string filePath, ref SysVersionControlTmpItem tmpItem)
        {
            if (tmpItem == null)
                tmpItem = new SysVersionControlTmpItem();

            try
            {
                BuildFileHistory(repoPath, filePath, ref tmpItem);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return tmpItem;
        }
Example #16
0
        /// <summary>
        /// Get a single file version from the git repository
        /// </summary>
        /// <param name="repoPath">Repository main path</param>
        /// <param name="tmpItem">The temporary item table holding the sha commit</param>
        /// <returns>a temporary file path</returns>
        public static string FileGetVersion(string repoPath, string fileName, SysVersionControlTmpItem tmpItem)
        {
            string indexPath = tmpItem.InternalFilename.Replace(repoPath, string.Empty);

            CheckoutOptions options = new CheckoutOptions();
            options.CheckoutModifiers = CheckoutModifiers.Force;

            using (Repository repo = new Repository(repoPath))
            {
                var commit = repo.Lookup<Commit>(tmpItem.GTXSha);
                if (commit != null)
                {
                    try
                    {
                        repo.CheckoutPaths(commit.Id.Sha, new[] { fileName }, options);
                    }
                    catch (MergeConflictException ex)
                    {
                        //should not reach here as we're forcing checkout
                        throw ex;
                    }

                }
            }

            return fileName;
        }