go-diff
go-diff copied to clipboard
a simple tool to check changes between git commits for go source files. it will resolve package dependencies. this is helpful in large projects ci, you will only need to run tests on changed/related f...
Install
go get github.com/joesonw/go-diff
Why
This little handy tool helps to manage large mono repositories. You don't have to rebuild every single service upon each little update.
This will help you to find out which services should be updated.
Important
Only works with GO MODULES ATM
Usage
go-diff -repo github.com/user/repo -branch master -from <HASH> -to <HASH>
or use
-repo file:///path/to/your/local/repoto avoid cloning
What does it do
- It clones your repo
- It then checkouts into specified branch.
- It then does a diff between two hashes.
- It will add any changed
.gofiles to the change list - It compares two
go.sumfiles and compute changed libraries, then added to change list - It parses every
.gofile and find import dependencies. - It adds every file that imported any package from change list, and does over and over again, until nothing new isfound.
- TADA! You have a list of packages that needed to be rebuilt.
Example
https://github.com/dstreamcloud/diff-sample/tree/go
Example 1
go-diff -repo https://github.com/dstreamcloud/diff-sample -branch go -from 1d748721adb49b79a529e446cca4b1a21bdd9b13 -to 4170f40939e939372e5c55beacd6a69ead53b976
This diff only changed pkg/critical/critical.go. But all packages are considered changed.
Example 2
go-diff -repo https://github.com/dstreamcloud/diff-sample -branch go -from 4170f40939e939372e5c55beacd6a69ead53b976 -to 6597f05c8b41f1182ad4fba09720728ada22a7fa
This diff only updated dependency of logrus. Thus only pkg/logrus and root which depends on it are considered changed.