gohack

command module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2018 License: BSD-3-Clause Imports: 19 Imported by: 0

README

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 gohack with:

go get github.com/rogpeppe/gohack

To make a mutable checkout of a module, say example.com/foo/bar, run:

gohack example.com/foo/bar

This will clone the module's repository to $HOME/gohack/example.com/foo/bar, check out the correct version of the source code there, and add a replace directive in the local go.mod file:

replace example.com/foo/bar /home/rog/gohack/example.com/foo/bar

Once you are done hacking and wish to revert to the immutable version, you can remove the replace statement with:

gohack -u example.com/foo/bar

or you can remove all gohack replace statements with:

gohack -u

Note that undoing a replace does not remove the external module's directory - that stays around so your changes are not lost. For example, you might wish to turn that bug fix into an upstream PR.

If you run gohack on a module that already has a directory, gohack will try to check out the current version without recreating the repository, but only if the directory is clean - it won't overwrite your changes until you've committed or undone them.

Documentation

Overview

gohack $module...

fetch module if needed into $GOHACK/$module
checkout correct commit
"is not clean" failure if it's been changed but at right commit
"is not clean; will not update" failure if changed and at wrong commit
add replace statement to go.mod

gohack -u $module

remove replace statement from go.mod

Directories

Path Synopsis
internal
dirhash
Package dirhash defines hashes over directory trees.
Package dirhash defines hashes over directory trees.
semver
Package semver implements comparison of semantic version strings.
Package semver implements comparison of semantic version strings.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL