add --recursive
This commit is contained in:
parent
f09d0fbfa9
commit
7a095d1566
9
Makefile
9
Makefile
|
@ -7,6 +7,9 @@ run: build
|
|||
|
||||
# test using --no-work against ~/go/src
|
||||
homeGoSrc: build
|
||||
-rm ~/go/src/go.work*
|
||||
go clean -cache -modcache
|
||||
-rm -rf ../basicwindow/
|
||||
./go-clone --no-work go.wit.com/apps/basicwindow
|
||||
|
||||
modernc: build
|
||||
|
@ -20,7 +23,11 @@ no-gui: build
|
|||
./go-clone --no-gui
|
||||
|
||||
build:
|
||||
GO111MODULE=off go build -v -ldflags "-X main.VERSION=${VERSION}" -ldflags "-X main.GUIVERSION=${VERSION}"
|
||||
GO111MODULE=off go build -v -ldflags "-X main.Version=${VERSION} -X gui.GUIVERSION=${VERSION}"
|
||||
|
||||
build-go-1.21:
|
||||
@#GO111MODULE=off /usr/lib/go-1.21/bin/go build -v -ldflags "-X main.VERSION=${VERSION}"
|
||||
@# GO111MODULE=off /usr/lib/go-1.21/bin/go build -v -ldflags "-X main.Version=${VERSION} -X gui.GUIVERSION=${VERSION}"
|
||||
@# GO111MODULE=off go build -v -ldflags "-X main.GUIVERSION=${VERSION}"
|
||||
|
||||
install:
|
||||
|
|
35
README.md
35
README.md
|
@ -1 +1,36 @@
|
|||
# go-clone
|
||||
5 years earlier, [gohack](https://github.com/rogpeppe/gohack) was written for the same reasons
|
||||
this tool was written. gohack has a good justification for this kind of tool so here it is:
|
||||
|
||||
|
||||
## Gohack: mutable checkouts of Go module dependencies
|
||||
|
||||
The new Go module system is awesome. It ensures repeatable, deterministic
|
||||
builds of Go code. External module code is cached locally in a read-only
|
||||
directory, which is great for reproducibility. But if you're used to the
|
||||
global mutable namespace that is `$GOPATH`, there's an obvious question:
|
||||
what if I'm hacking on my program and I *want* to change one of those
|
||||
external modules?
|
||||
|
||||
You might want to put a sneaky `log.Printf` statement to find out how
|
||||
some internal data structure works, or perhaps try out a bug fix to see
|
||||
if it solves your latest problem. But since all those external modules
|
||||
are in read-only directories, it's hard to change them. And you really
|
||||
don't want to change them anyway, because that will break the integrity
|
||||
checking that the Go tool does when building.
|
||||
|
||||
Luckily the modules system provides a way around this: you can add a
|
||||
`replace` statement to the `go.mod` file which substitutes the contents
|
||||
of a directory holding a module for the readonly cached copy. You can of
|
||||
course do this manually, but gohack aims to make this process pain-free.
|
||||
|
||||
## Install go-glone
|
||||
|
||||
go install go.wit.com/apps/go-clone@latest
|
||||
|
||||
## go-glone itself
|
||||
|
||||
This will make a work directory and download everything needs to compile
|
||||
go-clone.
|
||||
|
||||
go-clone --work go.wit.com/apps/go-clone
|
||||
|
|
16
argv.go
16
argv.go
|
@ -7,19 +7,21 @@ package main
|
|||
*/
|
||||
|
||||
type args struct {
|
||||
Repo string `arg:"positional" help:"go import path"`
|
||||
Work bool `arg:"--work" help:"make a work directory"`
|
||||
NoWork bool `arg:"--no-work" help:"does not make a go.work file"`
|
||||
Repo string `arg:"positional" help:"go import path"`
|
||||
Work bool `arg:"--work" help:"make a work directory"`
|
||||
NoWork bool `arg:"--no-work" help:"do not make or modify the go.work file"`
|
||||
DryRun bool `arg:"--dry-run" help:"show what would be run"`
|
||||
Recursive bool `arg:"--recursive" help:"resursively clone all dependencies"`
|
||||
}
|
||||
|
||||
func (a args) Description() string {
|
||||
return `
|
||||
Example usage: "go-clone go.wit.com/apps/go-clone"
|
||||
This will recursively clone the sources for this app into a work/ directory:
|
||||
|
||||
This will pull down the go sources and
|
||||
the repositories in the go.sum file using git clone`
|
||||
go-clone --recursive go.wit.com/apps/go-clone
|
||||
`
|
||||
}
|
||||
|
||||
func (args) Version() string {
|
||||
return "go-clone " + VERSION
|
||||
return "go-clone " + Version
|
||||
}
|
||||
|
|
47
main.go
47
main.go
|
@ -14,20 +14,16 @@ import (
|
|||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
var VERSION string
|
||||
var Version string
|
||||
|
||||
var rv *repolist.RepoList
|
||||
var myargs args
|
||||
|
||||
func main() {
|
||||
arg.MustParse(&myargs)
|
||||
pp := arg.MustParse(&myargs)
|
||||
|
||||
if myargs.Repo == "" {
|
||||
// tmp.WriteHelp(os.Stdout)
|
||||
// fmt.Println("hello world")
|
||||
tmp := myargs.Description()
|
||||
fmt.Println(tmp)
|
||||
fmt.Println(myargs.Version())
|
||||
pp.WriteHelp(os.Stdout)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
@ -61,32 +57,37 @@ func main() {
|
|||
}
|
||||
|
||||
godep := newr.Status.GetGoDeps()
|
||||
for gopath, version := range godep {
|
||||
repo, err := rv.NewRepo(gopath)
|
||||
if err != nil {
|
||||
log.Info("git clone failed for", gopath, version)
|
||||
continue
|
||||
}
|
||||
repo.Status.MakeRedomod()
|
||||
}
|
||||
|
||||
for _, repo := range rv.AllRepos() {
|
||||
if ! repo.Status.Exists("go.mod") {
|
||||
if myargs.Recursive {
|
||||
for gopath, version := range godep {
|
||||
repo, err := rv.NewRepo(gopath)
|
||||
if err != nil {
|
||||
log.Info("git clone failed for", gopath, version)
|
||||
continue
|
||||
}
|
||||
repo.Status.MakeRedomod()
|
||||
}
|
||||
}
|
||||
|
||||
log.Info("all repositories are cloned")
|
||||
var count int
|
||||
for _, repo := range rv.AllRepos() {
|
||||
count += 1
|
||||
if !repo.Status.Exists("go.mod") {
|
||||
repo.Status.MakeRedomod()
|
||||
}
|
||||
}
|
||||
|
||||
log.Info("Total repositories:", count)
|
||||
if !myargs.NoWork {
|
||||
log.Info("Creating", wdir+"/go.work")
|
||||
rv.MakeGoWork()
|
||||
shell.RunPath(wdir, []string{"go", "work", "use"})
|
||||
}
|
||||
|
||||
for _, repo := range rv.AllRepos() {
|
||||
log.Info("found repo", repo.GoPath(), repo.Status.Path())
|
||||
}
|
||||
|
||||
/*
|
||||
for _, repo := range rv.AllRepos() {
|
||||
log.Info("found repo", repo.GoPath(), repo.Status.Path())
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// look for or make a go.work file
|
||||
|
|
Loading…
Reference in New Issue