コード例 #1
0
ファイル: Repository.cs プロジェクト: georgeck/GitSharp
        /// <summary>
        /// Strip work dir and return normalized repository path
        /// </summary>
        /// <param name="workDir">Work directory</param>
        /// <param name="file">File whose path shall be stripp off it's workdir</param>
        /// <returns>Normalized repository relative path</returns>
        public static string StripWorkDir(FileSystemInfo workDir, FileSystemInfo file)
        {
            string filePath = file.DirectoryName();
            string workDirPath = workDir.DirectoryName();

            if (filePath.Length <= workDirPath.Length ||
                filePath[workDirPath.Length] != Path.DirectorySeparatorChar ||
                !filePath.StartsWith(workDirPath))
            {
                FileSystemInfo absWd = new DirectoryInfo(workDir.DirectoryName());
                FileSystemInfo absFile = new FileInfo(file.FullName);

                if (absWd.FullName == workDir.FullName && absFile.FullName == file.FullName)
                {
                    return string.Empty;
                }

                return StripWorkDir(absWd, absFile);
            }

            string relName = filePath.Substring(workDirPath.Length + 1);

            if (Path.DirectorySeparatorChar != '/')
            {
                relName = relName.Replace(Path.DirectorySeparatorChar, '/');
            }

             			return relName;
        }