Unite() public méthode

Modified version of LibGit2Sharp.Index.Move without the OS file system checks to unite file with proper case path
public Unite ( IEnumerable sourcePaths, IEnumerable destinationPaths ) : void
sourcePaths IEnumerable List containing path of each file within the working directory which has to be renamed.
destinationPaths IEnumerable List containing target path of each file within the working directory.
Résultat void
Exemple #1
0
        /// <summary>
        /// Unite filename casing between git index and host OS
        /// </summary>
        /// <param name="repo"></param>
        /// <param name="gitPathInfo"></param>
        /// <param name="folders"></param>
        private static void UniteFilenameCasing(this UniteRepository repo, DirectoryInfo gitPathInfo, List <DirectoryInfo> folders)
        {
            // The " " at the end of the Path.Combine is a trick to be sure there is a \ at the end of the path
            // Otherwise, we will exclude files suche as .gitattributes
            var dotGitFolderPath = Path.Combine(GetFullName(gitPathInfo), ".git", " ").TrimEnd();
            var files            = gitPathInfo.GetFiles("*", SearchOption.AllDirectories).Where(f => !GetFullName(f).StartsWith(dotGitFolderPath)).ToList();
            var filesFullPathMap = new HashSet <String>(files.ConvertAll(s => GetFullName(s)));


            var indexFileEntries = repo.Index.Where(f => filesFullPathMap.All(s => s.Replace(repo.Info.WorkingDirectory, string.Empty) != f.Path));

            foreach (var entry in indexFileEntries)
            {
                var sourcePath = repo.Info.WorkingDirectory + entry.Path;

                // Match host OS filename based on full pathname ignoring case
                var target = files.FirstOrDefault(f => String.Equals(GetFullName(f), sourcePath, StringComparison.CurrentCultureIgnoreCase));
                if (target == null)
                {
                    continue;
                }

                // Unite the git index with the correct OS folder
                repo.Unite(sourcePath, GetFullName(target));
            }
        }
Exemple #2
0
        /// <summary>
        /// Unite directory name casing between git index and host OS
        /// </summary>
        /// <param name="repo"></param>
        /// <param name="folders"></param>
        private static void UniteFolderCasing(this UniteRepository repo, List <DirectoryInfo> folders)
        {
            if (!folders.Any())
            {
                return;
            }

            var foldersFullPathMap = new HashSet <String>(folders.ConvertAll(s => GetFullName(s)));

            // Find all repository files with directory paths not found in the host OS folder collection
            var indexEntries =
                repo.Index.Where(f => f.Path.LastIndexOf(Separator, StringComparison.Ordinal) != -1
                                 &&
                                 !foldersFullPathMap.Any(s => s.Contains(f.Path.Substring(0, f.Path.LastIndexOf(Separator, StringComparison.Ordinal)))));

            // Unite the casing of the repository file directory path with the casing seen by the host operating system
            foreach (var entry in indexEntries)
            {
                var lastIndexOf = entry.Path.LastIndexOf(Separator, StringComparison.Ordinal);
                var filename    = entry.Path.Substring(lastIndexOf + 1);

                // Match host OS folder based on minimum length to find top level directory to target
                var folder = folders
                             .Where(x => GetFullName(x).ToLower().Contains(entry.Path.Substring(0, lastIndexOf).ToLower()))
                             .OrderBy(x => GetFullName(x).Length)
                             .FirstOrDefault();

                if (folder == null)
                {
                    Console.WriteLine("Warning: unable to determine target for index entry [{0}]", entry.Path);
                    continue;
                }
                ;

                var target     = GetFullName(folder) + Separator + filename;
                var sourcePath = repo.Info.WorkingDirectory + entry.Path;

                // Unite the git index with the correct OS folder
                repo.Unite(sourcePath, target);
            }
        }
Exemple #3
0
        /// <summary>
        /// Unite filename casing between git index and host OS
        /// </summary>
        /// <param name="repo"></param>
        /// <param name="gitPathInfo"></param>
        /// <param name="folders"></param>
        private static void UniteFilenameCasing(this UniteRepository repo, DirectoryInfo gitPathInfo, List <DirectoryInfo> folders)
        {
            var files            = folders.GetAllFileInfos(gitPathInfo);
            var filesFullPathMap = new HashSet <String>(files.ConvertAll(s => s.FullName));
            var indexFileEntries = repo.Index.Where(f => filesFullPathMap.All(s => s.Replace(repo.Info.WorkingDirectory, string.Empty) != f.Path));

            foreach (var entry in indexFileEntries)
            {
                var sourcePath = repo.Info.WorkingDirectory + entry.Path;

                // Match host OS filename based on full pathname ignoring case
                var target = files.FirstOrDefault(f => String.Equals(f.FullName, sourcePath, StringComparison.CurrentCultureIgnoreCase));
                if (target == null)
                {
                    continue;
                }

                // Unite the git index with the correct OS folder
                repo.Unite(sourcePath, target.FullName);
            }
        }