Commit ea295a4c authored by Russ Cox's avatar Russ Cox

cmd/go: add get -f flag

get -u now checks that remote repo paths match the
ones predicted by the import paths: if you are get -u'ing
rsc.io/pdf, it has to be checked out from the right location.
This is important in case the rsc.io/pdf redirect changes.

In some cases, people have good reasons to use
non-standard remote repos. Add -f flag to allow that.
The f can stand for force or fork, as you see fit.

Fixes #8850.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/164120043
parent 21a9141a
...@@ -16,7 +16,7 @@ import ( ...@@ -16,7 +16,7 @@ import (
) )
var cmdGet = &Command{ var cmdGet = &Command{
UsageLine: "get [-d] [-fix] [-t] [-u] [build flags] [packages]", UsageLine: "get [-d] [-f] [-fix] [-t] [-u] [build flags] [packages]",
Short: "download and install packages and dependencies", Short: "download and install packages and dependencies",
Long: ` Long: `
Get downloads and installs the packages named by the import paths, Get downloads and installs the packages named by the import paths,
...@@ -25,6 +25,11 @@ along with their dependencies. ...@@ -25,6 +25,11 @@ along with their dependencies.
The -d flag instructs get to stop after downloading the packages; that is, The -d flag instructs get to stop after downloading the packages; that is,
it instructs get not to install the packages. it instructs get not to install the packages.
The -f flag, valid only when -u is set, forces get -u not to verify that
each package has been checked out from the source control repository
implied by its import path. This can be useful if the source is a local fork
of the original.
The -fix flag instructs get to run the fix tool on the downloaded packages The -fix flag instructs get to run the fix tool on the downloaded packages
before resolving dependencies or building the code. before resolving dependencies or building the code.
...@@ -53,6 +58,7 @@ See also: go build, go install, go clean. ...@@ -53,6 +58,7 @@ See also: go build, go install, go clean.
} }
var getD = cmdGet.Flag.Bool("d", false, "") var getD = cmdGet.Flag.Bool("d", false, "")
var getF = cmdGet.Flag.Bool("f", false, "")
var getT = cmdGet.Flag.Bool("t", false, "") var getT = cmdGet.Flag.Bool("t", false, "")
var getU = cmdGet.Flag.Bool("u", false, "") var getU = cmdGet.Flag.Bool("u", false, "")
var getFix = cmdGet.Flag.Bool("fix", false, "") var getFix = cmdGet.Flag.Bool("fix", false, "")
...@@ -63,6 +69,10 @@ func init() { ...@@ -63,6 +69,10 @@ func init() {
} }
func runGet(cmd *Command, args []string) { func runGet(cmd *Command, args []string) {
if *getF && !*getU {
fatalf("go get: cannot use -f flag without -u")
}
// Phase 1. Download/update. // Phase 1. Download/update.
var stk importStack var stk importStack
for _, arg := range downloadPaths(args) { for _, arg := range downloadPaths(args) {
...@@ -268,7 +278,7 @@ func downloadPackage(p *Package) error { ...@@ -268,7 +278,7 @@ func downloadPackage(p *Package) error {
repo = "<local>" // should be unused; make distinctive repo = "<local>" // should be unused; make distinctive
// Double-check where it came from. // Double-check where it came from.
if *getU && vcs.remoteRepo != nil { if *getU && vcs.remoteRepo != nil && !*getF {
dir := filepath.Join(p.build.SrcRoot, rootPath) dir := filepath.Join(p.build.SrcRoot, rootPath)
if remote, err := vcs.remoteRepo(vcs, dir); err == nil { if remote, err := vcs.remoteRepo(vcs, dir); err == nil {
if rr, err := repoRootForImportPath(p.ImportPath); err == nil { if rr, err := repoRootForImportPath(p.ImportPath); err == nil {
......
...@@ -219,6 +219,16 @@ q' | ed $d/src/$config >/dev/null 2>&1 ...@@ -219,6 +219,16 @@ q' | ed $d/src/$config >/dev/null 2>&1
cat $d/err cat $d/err
ok=false ok=false
fi fi
if GOPATH=$d ./testgo get -d -f -u $url 2>$d/err; then
echo "go get -d -u $url succeeded with wrong remote repo"
cat $d/err
ok=false
elif ! egrep -i 'validating server certificate|not found' $d/err >/dev/null; then
echo "go get -d -f -u $url failed for wrong reason"
cat $d/err
ok=false
fi
fi fi
rm -rf $d rm -rf $d
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment