mirror of
https://github.com/TECHNOFAB11/jsonnet-bundler.git
synced 2025-12-12 08:00:05 +01:00
Use git sparse checkout whenever possible
If a SubDir is configured for the package, everything but that directory will be thrown away after the package is installed.
This commit is contained in:
parent
c9a5b0a6b2
commit
30d7929566
1 changed files with 15 additions and 0 deletions
15
pkg/git.go
15
pkg/git.go
|
|
@ -17,6 +17,7 @@ package pkg
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
|
|
@ -45,6 +46,20 @@ func (p *GitPackage) Install(ctx context.Context, dir, version string) (lockVers
|
|||
return "", err
|
||||
}
|
||||
|
||||
if p.Source.Subdir != "" {
|
||||
cmd = exec.CommandContext(ctx, "git", "config", "core.sparsecheckout", "true")
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Dir = dir
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
glob := []byte(p.Source.Subdir + "/*\n")
|
||||
ioutil.WriteFile(dir + "/.git/info/sparse-checkout", glob, 0644)
|
||||
}
|
||||
|
||||
cmd = exec.CommandContext(ctx, "git", "-c", "advice.detachedHead=false", "checkout", version)
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = os.Stdout
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue