Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

Added possibility to fetch as 'git clone' #703

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions cmd/gb-vendor/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (

recurse bool // should we fetch recursively
insecure bool // Allow the use of insecure protocols
clone bool // allows to fetch as a full git repo
)

func addFetchFlags(fs *flag.FlagSet) {
Expand All @@ -39,11 +40,12 @@ func addFetchFlags(fs *flag.FlagSet) {
fs.StringVar(&tag, "tag", "", "tag of the package")
fs.BoolVar(&noRecurse, "no-recurse", false, "do not fetch recursively")
fs.BoolVar(&insecure, "precaire", false, "allow the use of insecure protocols")
fs.BoolVar(&clone, "clone", false, "fetch repository with .git folder")
}

var cmdFetch = &cmd.Command{
Name: "fetch",
UsageLine: "fetch [-branch branch | -revision rev | -tag tag] [-precaire] [-no-recurse] importpath",
UsageLine: "fetch [-branch branch | -revision rev | -tag tag] [-clone] [-precaire] [-no-recurse] importpath",
Short: "fetch a remote dependency",
Long: `fetch vendors an upstream import path.

Expand All @@ -54,6 +56,8 @@ Flags:
-branch branch
fetch from the name branch. If not supplied the default upstream
branch will be used.
-clone
fetches as a full git repository
-no-recurse
do not fetch recursively.
-tag tag
Expand All @@ -73,15 +77,15 @@ Flags:
case 1:
path := args[0]
recurse = !noRecurse
return fetch(ctx, path, recurse)
return fetch(ctx, path, recurse, clone)
default:
return errors.New("more than one import path supplied")
}
},
AddFlags: addFetchFlags,
}

func fetch(ctx *gb.Context, path string, recurse bool) error {
func fetch(ctx *gb.Context, path string, recurse bool, clone bool) error {
m, err := vendor.ReadManifest(manifestFile(ctx))
if err != nil {
return errors.Wrap(err, "could not load manifest")
Expand Down Expand Up @@ -122,6 +126,7 @@ func fetch(ctx *gb.Context, path string, recurse bool) error {
Revision: rev,
Branch: b,
Path: extra,
Clone: clone,
}

if err := m.AddDependency(dep); err != nil {
Expand All @@ -131,7 +136,7 @@ func fetch(ctx *gb.Context, path string, recurse bool) error {
dst := filepath.Join(ctx.Projectdir(), "vendor", "src", dep.Importpath)
src := filepath.Join(wc.Dir(), dep.Path)

if err := fileutils.Copypath(dst, src); err != nil {
if err := fileutils.Copypath(dst, src, clone); err != nil {
return err
}

Expand Down Expand Up @@ -192,7 +197,7 @@ func fetch(ctx *gb.Context, path string, recurse bool) error {
sort.Strings(keys)
pkg := keys[0]
fmt.Println("fetching recursive dependency", pkg)
if err := fetch(ctx, pkg, false); err != nil {
if err := fetch(ctx, pkg, false, false); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gb-vendor/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func restore(ctx *gb.Context) error {
dst := filepath.Join(ctx.Projectdir(), "vendor", "src", dep.Importpath)
src := filepath.Join(wc.Dir(), dep.Path)

if err := fileutils.Copypath(dst, src); err != nil {
if err := fileutils.Copypath(dst, src, dep.Clone); err != nil {
errChan <- err
return
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gb-vendor/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Flags:
dst := filepath.Join(ctx.Projectdir(), "vendor", "src", filepath.FromSlash(dep.Importpath))
src := filepath.Join(wc.Dir(), dep.Path)

if err := fileutils.Copypath(dst, src); err != nil {
if err := fileutils.Copypath(dst, src, dep.Clone); err != nil {
return err
}

Expand Down
6 changes: 4 additions & 2 deletions internal/fileutils/fileutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ const debugCopyfile = false

// Copypath copies the contents of src to dst, excluding any file or
// directory that starts with a period.
func Copypath(dst string, src string) error {
func Copypath(dst string, src string, withGit bool) error {
err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

if strings.HasPrefix(filepath.Base(path), ".") {
git := filepath.Base(path) == ".git" && withGit

if strings.HasPrefix(filepath.Base(path), ".") && !git {
if info.IsDir() {
return filepath.SkipDir
}
Expand Down
2 changes: 1 addition & 1 deletion internal/fileutils/fileutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestCopypathSkipsSymlinks(t *testing.T) {
dst := mktemp(t)
defer RemoveAll(dst)
src := filepath.Join("_testdata", "copyfile", "a")
if err := Copypath(dst, src); err != nil {
if err := Copypath(dst, src, false); err != nil {
t.Fatalf("copypath(%s, %s): %v", dst, src, err)
}
}
Expand Down
3 changes: 3 additions & 0 deletions internal/vendor/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ type Dependency struct {
// Path is the path inside the Repository where the
// dependency was fetched from.
Path string `json:"path,omitempty"`

// Clone describes was repository cloned as a full git repository.
Clone bool `json:"clone,omitempty"`
}

// WriteManifest writes a Manifest to the path. If the manifest does
Expand Down