Skip to content

Instantly share code, notes, and snippets.

@icio
Created November 11, 2016 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icio/1c3f334e303c83f0af51a6c91751cf05 to your computer and use it in GitHub Desktop.
Save icio/1c3f334e303c83f0af51a6c91751cf05 to your computer and use it in GitHub Desktop.
function go-local-package() {
go list ./... | head -1 | xargs dirname
}
function go-diff() {
ROOT_PKG=$(go-local-package)
go list -f '{{.Name}} {{.ImportPath}} {{.Deps}}' $(go list $ROOT_PKG/...) | \
grep ^main | \
grep -w -f <(
git diff --dirstat ${2:-master}...${1:-HEAD} | \
awk '{ print "'$ROOT_PKG'/" $2 }' | \
sed 's:/$::'
) | \
awk '{ print $2 }'
}
function go-diff-file() {
go-diff "$@" | sed 's:^'$(go-local-package)/'::'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment