Skip to content

Instantly share code, notes, and snippets.

@radeksimko
Last active February 4, 2019 10:46
Show Gist options
  • Save radeksimko/c2c08b731d8b4262d78ab4843ed8af1e to your computer and use it in GitHub Desktop.
Save radeksimko/c2c08b731d8b4262d78ab4843ed8af1e to your computer and use it in GitHub Desktop.
Go import path to repo root

Small hacky script to help verify govendor -> go modules migration

How to run

cd $GOPATH/src/.../where-you-place-main.go
go install .
./go-deps.sh vendor/vendor.json | sort | uniq

Expected output

cloud.google.com/go@81b7822b1e798e8f17bf64b59512a5be4097e966
cloud.google.com/go@eaddaf6dd7ee35fd3c2420c8d27478db176b0485
github.com/Azure/azure-sdk-for-go@57db66900881e9fd21fd041a9d013514700ecab3
github.com/Azure/go-autorest@fc3b03a2d2d1f43fad3007038bd16f044f870722
#!/bin/bash
jq -r '.package[] | [.path, .revision] | @tsv' $1 |
while IFS=$'\t' read -r path revision; do
$GOPATH/bin/importpath2root $path
echo "@"$revision
done
package main
import (
"fmt"
"log"
"os"
"golang.org/x/tools/go/vcs"
)
// Run as `go run main.go golang.org/x/tools/go/vcs`
func main() {
importPath := os.Args[1]
verbose := false
rr, err := vcs.RepoRootForImportPath(importPath, verbose)
if err != nil {
log.Fatal(err)
}
fmt.Println(rr.Root)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment