github.com/blend/go-sdk@v1.20220411.3/codeowners/make_absolute.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package codeowners 9 10 import ( 11 "path/filepath" 12 "strings" 13 ) 14 15 // MakeRepositoryAbsolute make a path absolute. 16 func MakeRepositoryAbsolute(repositoryRoot, path string) (string, error) { 17 var err error 18 if !filepath.IsAbs(repositoryRoot) { 19 repositoryRoot, err = filepath.Abs(repositoryRoot) 20 if err != nil { 21 return "", err 22 } 23 } 24 if !filepath.IsAbs(path) { 25 path, err = filepath.Abs(path) 26 if err != nil { 27 return "", err 28 } 29 } 30 path = strings.TrimPrefix(path, repositoryRoot) 31 if !strings.HasPrefix(path, "/") { 32 path = "/" + path 33 } 34 return path, nil 35 }