MakeRelativePath() 공개 정적인 메소드

Creates a relative path from one file or folder to another.
public static MakeRelativePath ( string basePath, string absolutePath ) : string
basePath string Contains the directory that defines the start of the relative path.
absolutePath string Contains the path that defines the endpoint of the relative path.
리턴 string
예제 #1
0
        private static GitDetail GetGitDetailCore(string path)
        {
            GitDetail detail = null;

            try
            {
                var repoPath = Repository.FindRepository(path);
                if (string.IsNullOrEmpty(repoPath))
                {
                    // Use local modified date when git repo is not found
                    var time = File.GetLastWriteTimeUtc(path);
                    detail = new GitDetail
                    {
                        CommitDetail = new CommitDetail
                        {
                            Author = new UserInfo
                            {
                                Date = time,
                            }
                        }
                    };
                    return(detail);
                }

                var directory = Path.GetDirectoryName(repoPath);
                var wrapper   = RepoCache.GetOrAdd(directory, s => new RepoWrapper(CoreRepository.Open(s)));
                var repo      = wrapper.Repo;
                path   = PathUtility.MakeRelativePath(directory, path);
                detail = new GitDetail();

                var walker = wrapper.Walker;

                // TODO: Disable fetching commit detail for now until GlobalContext is added
                // var commitDetail = walker.GetCommitDetail(path);
                // detail.CommitDetail = commitDetail;

                // Convert to forward slash
                detail.LocalWorkingDirectory = repo.WorkingDirectory.FullName;
                if (repo.Head == null)
                {
                    return(detail);
                }

                var branch = repo.getBranch();
                detail.RemoteRepositoryUrl = repo.Config.getString("remote", "origin", "url");
                detail.RemoteBranch        = branch;
                detail.RelativePath        = path;
                return(detail);
            }
            catch (Exception e)
            {
                Logger.LogWarning($"Have issue extracting repo detail for {path}: {e.Message}");
            }

            return(detail);
        }
예제 #2
0
        /// <summary>
        /// TODO: only get GitDetail on Project level?
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static GitDetail GetGitDetail(string path)
        {
            GitDetail detail = null;

            if (string.IsNullOrEmpty(path))
            {
                return(detail);
            }
            try
            {
                var repoPath = Repository.FindRepository(path);
                if (string.IsNullOrEmpty(repoPath))
                {
                    return(detail);
                }

                var repo = new Repository(repoPath);

                detail = new GitDetail();
                // Convert to forward slash
                detail.LocalWorkingDirectory = repo.WorkingDirectory.BackSlashToForwardSlash();
                if (repo.Head == null)
                {
                    return(detail);
                }

                var branch = repo.CurrentBranch;
                detail.RemoteRepositoryUrl = repo.Config["remote.origin.url"];
                detail.RemoteBranch        = branch.Name;
                // detail.Description = repo.Head.CurrentCommit.ShortHash;
                detail.RelativePath = PathUtility.MakeRelativePath(Path.GetDirectoryName(repoPath), path);
            }
            catch (Exception)
            {
                // SWALLOW exception?
                // Console.Error.WriteLine(e.Message);
            }

            return(detail);
        }