github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/lib/project/repository.go (about) 1 package projectLib 2 3 import ( 4 git "github.com/taubyte/go-simple-git" 5 projectI18n "github.com/taubyte/tau-cli/i18n/project" 6 "github.com/taubyte/tau-cli/singletons/config" 7 "github.com/taubyte/tau-cli/states" 8 ) 9 10 type repositoryHandler struct { 11 projectName string 12 13 config *git.Repository 14 code *git.Repository 15 } 16 17 func Repository(projectName string) RepositoryHandler { 18 return &repositoryHandler{projectName: projectName} 19 } 20 21 func (h *repositoryHandler) Config() (*git.Repository, error) { 22 if h.config != nil { 23 return h.config, nil 24 } 25 26 return nil, projectI18n.ErrorConfigRepositoryNotFound 27 } 28 29 func (h *repositoryHandler) Code() (*git.Repository, error) { 30 if h.code != nil { 31 return h.code, nil 32 } 33 34 return nil, projectI18n.ErrorCodeRepositoryNotFound 35 } 36 37 func (h *repositoryHandler) openOrClone(profile config.Profile, loc string, ops ...git.Option) (*git.Repository, error) { 38 _ops := []git.Option{ 39 git.Root(loc), 40 git.Author(profile.GitUsername, profile.GitEmail), 41 } 42 43 // TODO branch this breaks stuff 44 // Only pass branch if it is defined 45 // if len(h.branch) > 0 { 46 // _ops = append(_ops, git.Branch(h.branch)) 47 // } 48 49 // Passed in ops go at the end so they can override the default options above 50 _ops = append(_ops, ops...) 51 52 return git.New( 53 states.Context, 54 _ops..., 55 ) 56 }