github.com/grahambrereton-form3/tilt@v0.10.18/internal/tiltfile/git/git.go (about)

     1  package git
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  
     8  	"go.starlark.net/starlark"
     9  
    10  	"github.com/windmilleng/tilt/internal/tiltfile/starkit"
    11  )
    12  
    13  type Extension struct{}
    14  
    15  func NewExtension() Extension {
    16  	return Extension{}
    17  }
    18  
    19  func (Extension) OnStart(env *starkit.Environment) error {
    20  	return env.AddBuiltin("local_git_repo", localGitRepo)
    21  }
    22  
    23  func NewGitRepo(t *starlark.Thread, path string) (*Repo, error) {
    24  	absPath := starkit.AbsPath(t, path)
    25  	_, err := os.Stat(absPath)
    26  	if err != nil {
    27  		return nil, fmt.Errorf("Reading paths %s: %v", absPath, err)
    28  	}
    29  
    30  	if _, err := os.Stat(filepath.Join(absPath, ".git")); os.IsNotExist(err) {
    31  		return nil, fmt.Errorf("%s isn't a valid git repo: it doesn't have a .git/ directory", absPath)
    32  	}
    33  
    34  	return &Repo{basePath: absPath}, nil
    35  }
    36  
    37  func localGitRepo(thread *starlark.Thread, fn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
    38  	var path string
    39  	err := starkit.UnpackArgs(thread, fn.Name(), args, kwargs, "paths", &path)
    40  	if err != nil {
    41  		return nil, err
    42  	}
    43  
    44  	return NewGitRepo(thread, path)
    45  }