From f9b6955cb1f92edd5bec112431f81d08c220d0d6 Mon Sep 17 00:00:00 2001 From: Norman Gehrsitz <45375059+ngehrsitz@users.noreply.github.com> Date: Wed, 17 Dec 2025 13:36:21 +0100 Subject: [PATCH] Add option to overwrite changes in the git repo --- README.md | 19 +++++++++++-------- config.go | 2 ++ main.go | 6 +++++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 288f383..81ebdf8 100644 --- a/README.md +++ b/README.md @@ -254,19 +254,22 @@ NAME: cob - Continuous Benchmark for Go project USAGE: - cob [global options] command [command options] [arguments...] + cob [global options] command [command options] COMMANDS: help, h Shows a list of commands or help for one command GLOBAL OPTIONS: - --only-degression Show only benchmarks with worse score (default: false) - --threshold value The program fails if the benchmark gets worse than the threshold (default: 0.2) - --base value Specify a base commit compared with HEAD (default: "HEAD~1") - --compare value Which score to compare (default: "ns/op,B/op") - --bench-cmd value Specify a command to measure benchmarks (default: "go") - --bench-args value Specify arguments passed to -cmd (default: "test -run '^$' -bench . -benchmem ./...") - --help, -h show help (default: false) + --only-degression Show only benchmarks with worse score (default: false) + --fail-without-results Exit with an error if the parsing fails (default: false) + --overwrite-changes Overwrite uncommitted changes in the git repository (default: false) + --threshold value The program fails if the benchmark gets worse than the threshold (default: 0.2) + --base value Specify a base commit compared with HEAD (default: "HEAD~1") + --compare value Which score to compare (default: "ns/op,B/op") + --bench-cmd value Specify a command to measure benchmarks (default: "go") + --bench-args value Specify arguments passed to -cmd (default: "test -run '^$' -bench . -benchmem ./...") + --git-path value Specify the path of the git repo (default: ".") + --help, -h show help ``` # Q&A diff --git a/config.go b/config.go index 3f67d6b..1623924 100644 --- a/config.go +++ b/config.go @@ -9,6 +9,7 @@ import ( type config struct { onlyDegression bool failWithoutResults bool + overwriteChanges bool threshold float64 base string compare []string @@ -21,6 +22,7 @@ func newConfig(c *cli.Context) config { return config{ onlyDegression: c.Bool("only-degression"), failWithoutResults: c.Bool("fail-without-results"), + overwriteChanges: c.Bool("overwrite-changes"), threshold: c.Float64("threshold"), base: c.String("base"), compare: strings.Split(c.String("compare"), ","), diff --git a/main.go b/main.go index 6ce4b9e..e9152dd 100644 --- a/main.go +++ b/main.go @@ -45,6 +45,10 @@ func main() { Name: "fail-without-results", Usage: "Exit with an error if the parsing fails", }, + &cli.BoolFlag{ + Name: "overwrite-changes", + Usage: "Overwrite uncommitted changes in the git repository", + }, &cli.Float64Flag{ Name: "threshold", Usage: "The program fails if the benchmark gets worse than the threshold", @@ -120,7 +124,7 @@ func run(c config) error { return xerrors.Errorf("unable to get the working tree status: %w", err) } - if !s.IsClean() { + if !c.overwriteChanges && !s.IsClean() { return xerrors.New("the repository is dirty: commit all changes before running 'cob'") }