Skip to content

Commit

Permalink
Merge pull request #52 from launchrctl/remove_git_depth_limit
Browse files Browse the repository at this point in the history
Remove git depth to include full git history in package
  • Loading branch information
davidferlay authored Oct 21, 2024
2 parents 061f460 + a638132 commit ab34c9d
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 150 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export GOSUMDB=off
#export GOSUMDB=off

GOPATH?=$(HOME)/go
FIRST_GOPATH:=$(firstword $(subst :, ,$(GOPATH)))
Expand Down
4 changes: 1 addition & 3 deletions cmd/launchr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
package main

import (
"os"

"github.com/launchrctl/launchr"

_ "github.com/launchrctl/compose"
)

func main() {
os.Exit(launchr.Run())
launchr.RunAndExit()
}
7 changes: 4 additions & 3 deletions compose/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/launchrctl/launchr"
"github.com/stevenle/topsort"
)

Expand Down Expand Up @@ -150,7 +151,7 @@ func getVersionedMap(gitDir string) (map[string]bool, error) {
}

func (b *Builder) build() error {
fmt.Println("Creating composition...")
launchr.Term().Println("Creating composition...")
err := EnsureDirExists(b.targetDir)
if err != nil {
return err
Expand Down Expand Up @@ -221,7 +222,7 @@ func (b *Builder) build() error {
targetsMap := getTargetsMap(b.packages)

if b.logConflicts {
fmt.Print("Conflicting files:\n")
launchr.Term().Info().Printf("Conflicting files:\n")
}

for i := 0; i < len(items); i++ {
Expand Down Expand Up @@ -312,7 +313,7 @@ func logConflictResolve(resolveto mergeConflictResolve, path, pkgName string, en
return
}

fmt.Printf("[%s] - %s > Selected from %s\n", pkgName, path, entry.From)
launchr.Term().Info().Printfln("[%s] - %s > Selected from %s", pkgName, path, entry.From)
}

func addEntries(entriesTree []*fsEntry, entriesMap map[string]*fsEntry, entry *fsEntry, path string) ([]*fsEntry, mergeConflictResolve) {
Expand Down
29 changes: 6 additions & 23 deletions compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ package compose

import (
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"

"github.com/launchrctl/launchr/pkg/log"

"github.com/launchrctl/keyring"
"github.com/launchrctl/launchr"
)

const (
Expand Down Expand Up @@ -44,7 +41,7 @@ type ComposerOptions struct {

// CreateComposer instance
func CreateComposer(pwd string, opts ComposerOptions, k keyring.Keyring) (*Composer, error) {
config, err := composeLookup(os.DirFS(pwd))
config, err := Lookup(os.DirFS(pwd))
if err != nil {
return nil, err
}
Expand All @@ -64,7 +61,7 @@ func (kw *keyringWrapper) getForURL(url string) (keyring.CredentialsItem, error)
if errors.Is(errGet, keyring.ErrEmptyPass) {
return ci, errGet
} else if !errors.Is(errGet, keyring.ErrNotFound) {
log.Debug("%s", errGet)
launchr.Log().Debug(errGet.Error())
return ci, errors.New("the keyring is malformed or wrong passphrase provided")
}

Expand Down Expand Up @@ -92,7 +89,7 @@ func (kw *keyringWrapper) getForURL(url string) (keyring.CredentialsItem, error)

func (kw *keyringWrapper) fillCredentials(ci keyring.CredentialsItem) (keyring.CredentialsItem, error) {
if ci.URL != "" {
fmt.Printf("Please add login and password for URL - %s\n", ci.URL)
launchr.Term().Printfln("Please add login and password for URL - %s", ci.URL)
}
err := keyring.RequestCredentialsFromTty(&ci)
if err != nil {
Expand Down Expand Up @@ -131,14 +128,14 @@ func (c *Composer) prepareInstall() (string, string, error) {
buildPath := c.getPath(BuildDir)
packagesPath := c.getPath(c.options.WorkingDir)

fmt.Printf("Cleaning build dir: %s\n", BuildDir)
launchr.Term().Printfln("Cleaning build dir: %s", BuildDir)
err := os.RemoveAll(buildPath)
if err != nil {
return "", "", err
}

if c.options.Clean {
fmt.Printf("Cleaning packages dir: %s\n", packagesPath)
launchr.Term().Printfln("Cleaning packages dir: %s", packagesPath)
err = os.RemoveAll(packagesPath)
if err != nil {
return "", "", err
Expand All @@ -157,20 +154,6 @@ func EnsureDirExists(path string) error {
return os.MkdirAll(path, dirPermissions)
}

func composeLookup(fsys fs.FS) (*YamlCompose, error) {
f, err := fs.ReadFile(fsys, composeFile)
if err != nil {
return &YamlCompose{}, errComposeNotExists
}

cfg, err := parseComposeYaml(f)
if err != nil {
return &YamlCompose{}, errComposeBadStructure
}

return cfg, nil
}

func (c *Composer) getCompose() *YamlCompose {
return c.compose
}
Expand Down
2 changes: 1 addition & 1 deletion compose/downloadManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (m DownloadManager) recursiveDownload(yc *YamlCompose, kw *keyringWrapper,

// If package has plasma-compose.yaml, proceed with it
if _, err := os.Stat(filepath.Join(packagePath, composeFile)); !os.IsNotExist(err) {
cfg, err := composeLookup(os.DirFS(packagePath))
cfg, err := Lookup(os.DirFS(packagePath))
if err == nil {
packages, err = m.recursiveDownload(cfg, kw, packages, pkg, targetDir)
if err != nil {
Expand Down
20 changes: 10 additions & 10 deletions compose/forms.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"dario.cat/mergo"
"github.com/charmbracelet/huh"
"github.com/launchrctl/launchr/pkg/cli"
"github.com/launchrctl/launchr"
)

// RawStrategies represents collection of submitted flags for strategies.
Expand All @@ -20,7 +20,7 @@ type RawStrategies struct {

// AddPackage adds a new package to plasma-compose.
func AddPackage(doCreate bool, newDependency *Dependency, rawStrategies *RawStrategies, dir string) error {
config, err := composeLookup(os.DirFS(dir))
config, err := Lookup(os.DirFS(dir))
if err != nil {
if !errors.Is(err, errComposeNotExists) {
return err
Expand Down Expand Up @@ -73,7 +73,7 @@ func AddPackage(doCreate bool, newDependency *Dependency, rawStrategies *RawStra

sanitizeDependency(newDependency)
config.Dependencies = append(config.Dependencies, *newDependency)
cli.Println("Saving plasma-compose...")
launchr.Term().Println("Saving plasma-compose...")
sortPackages(config)
err = writeComposeYaml(config)

Expand All @@ -82,7 +82,7 @@ func AddPackage(doCreate bool, newDependency *Dependency, rawStrategies *RawStra

// UpdatePackage updates a single package in plasma-compose.
func UpdatePackage(dependency *Dependency, rawStrategies *RawStrategies, dir string) error {
config, err := composeLookup(os.DirFS(dir))
config, err := Lookup(os.DirFS(dir))
if err != nil {
return err
}
Expand Down Expand Up @@ -114,7 +114,7 @@ func UpdatePackage(dependency *Dependency, rawStrategies *RawStrategies, dir str
}

sanitizeDependency(toUpdate)
cli.Println("Saving plasma-compose...")
launchr.Term().Println("Saving plasma-compose...")
sortPackages(config)
err = writeComposeYaml(config)

Expand All @@ -123,7 +123,7 @@ func UpdatePackage(dependency *Dependency, rawStrategies *RawStrategies, dir str

// UpdatePackages updates packages in plasma-compose in interactive way.
func UpdatePackages(dir string) error {
config, err := composeLookup(os.DirFS(dir))
config, err := Lookup(os.DirFS(dir))
if err != nil {
return err
}
Expand Down Expand Up @@ -178,7 +178,7 @@ func UpdatePackages(dir string) error {
}
}

cli.Println("Saving plasma-compose...")
launchr.Term().Println("Saving plasma-compose...")
var newDeps []Dependency
for _, dep := range packagesMap {
newDeps = append(newDeps, *dep)
Expand All @@ -193,7 +193,7 @@ func UpdatePackages(dir string) error {

// DeletePackages removes packages plasma-compose.
func DeletePackages(packages []string, dir string) error {
config, err := composeLookup(os.DirFS(dir))
config, err := Lookup(os.DirFS(dir))
if err != nil {
return err
}
Expand Down Expand Up @@ -238,12 +238,12 @@ OUTER:
}

if saveRequired {
cli.Println("Updating plasma-compose...")
launchr.Term().Println("Updating plasma-compose...")
config.Dependencies = dependencies
sortPackages(config)
err = writeComposeYaml(config)
} else {
cli.Println("Nothing to update, quiting")
launchr.Term().Println("Nothing to update, quiting")
}

return err
Expand Down
15 changes: 7 additions & 8 deletions compose/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package compose

import (
"errors"
"fmt"
"log"
"os"

"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/launchrctl/keyring"
"github.com/launchrctl/launchr"
)

type gitDownloader struct{}
Expand All @@ -21,17 +20,17 @@ func newGit() Downloader {

// Download implements Downloader.Download interface
func (g *gitDownloader) Download(pkg *Package, targetDir string, kw *keyringWrapper) error {
fmt.Println(fmt.Sprintf("git fetch: " + pkg.GetURL()))
launchr.Term().Printfln("git fetch: %s", pkg.GetURL())

url := pkg.GetURL()
if url == "" {
return errNoURL
}

options := &git.CloneOptions{
URL: url,
Progress: os.Stdout,
Depth: 1,
URL: url,
Progress: os.Stdout,
SingleBranch: true,
}
if pkg.GetRef() != "" {
options.ReferenceName = plumbing.NewBranchReferenceName(pkg.GetRef())
Expand All @@ -45,7 +44,7 @@ func (g *gitDownloader) Download(pkg *Package, targetDir string, kw *keyringWrap
_, err := git.PlainClone(targetDir, false, options)
if err != nil {
if errors.Is(err, transport.ErrAuthenticationRequired) {
log.Println("auth required, trying keyring authorisation")
launchr.Term().Println("auth required, trying keyring authorisation")
continue
}

Expand All @@ -68,7 +67,7 @@ func (g *gitDownloader) Download(pkg *Package, targetDir string, kw *keyringWrap
if err != nil {
if errors.Is(err, transport.ErrAuthorizationFailed) || errors.Is(err, transport.ErrAuthenticationRequired) {
if kw.interactive {
log.Println("invalid auth, trying manual authorisation")
launchr.Term().Println("invalid auth, trying manual authorisation")
continue
}
}
Expand Down
Loading

0 comments on commit ab34c9d

Please sign in to comment.