Skip to content

Commit

Permalink
versiongetter: use a permissive AlternatesFS with git-go
Browse files Browse the repository at this point in the history
  • Loading branch information
database64128 committed Oct 8, 2024
1 parent 52e34b4 commit 4ac00a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/fsnotify/fsnotify v1.7.0
github.com/gin-contrib/pprof v1.5.0
github.com/gin-gonic/gin v1.10.0
github.com/go-git/go-billy/v5 v5.5.0
github.com/go-git/go-git/v5 v5.12.0
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/google/uuid v1.6.0
Expand Down Expand Up @@ -54,7 +55,6 @@ require (
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
Expand Down
15 changes: 14 additions & 1 deletion internal/core/versiongetter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import (
"strconv"
"strings"

"github.com/go-git/go-billy/v5/osfs"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/cache"
"github.com/go-git/go-git/v5/storage/filesystem"
)

// Golang version of git describe --tags
Expand Down Expand Up @@ -69,7 +72,17 @@ func gitDescribeTags(repo *git.Repository) (string, error) {
func do() error {
log.Println("getting mediamtx version...")

repo, err := git.PlainOpen("../..")
// [git.PlainOpen] uses a ChrootOS that limits filesystem access to the .git directory only.
//
// Unfortunately, this can cause issues with package build environments such as Arch Linux's,
// where .git/objects/info/alternates points to a directory outside of the .git directory.
//
// To work around this, specify an AlternatesFS that allows access to the entire filesystem.
fs := osfs.New("../../.git", osfs.WithBoundOS())
storer := filesystem.NewStorageWithOptions(fs, cache.NewObjectLRUDefault(), filesystem.Options{
AlternatesFS: osfs.New("/", osfs.WithBoundOS()),
})
repo, err := git.Open(storer, fs)
if err != nil {
return fmt.Errorf("failed to open repository: %w", err)
}
Expand Down

0 comments on commit 4ac00a0

Please sign in to comment.