From ce8d4f2963119e134ea217f286862f1740217215 Mon Sep 17 00:00:00 2001 From: Valentin Kiselev Date: Fri, 17 May 2024 14:26:15 +0300 Subject: [PATCH] fix: more verbose error on versions mismatch (#721) * fix: more verbose error on versions mismatch * fix: add lefthook path --- internal/version/version.go | 9 ++++++++- testdata/min_version.txt | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/version/version.go b/internal/version/version.go index 7cfc94c9..bbc775a1 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -2,6 +2,8 @@ package version import ( "errors" + "fmt" + "os" "regexp" "strconv" ) @@ -17,7 +19,6 @@ var ( ) errIncorrectVersion = errors.New("format of 'min_version' setting is incorrect") - errUncovered = errors.New("required Lefthook version is higher than current") ) func Version(verbose bool) string { @@ -49,6 +50,12 @@ func CheckCovered(targetVersion string) error { return err } + execPath, err := os.Executable() + if err != nil { + execPath = "" + } + errUncovered := fmt.Errorf("required lefthook version (%s) is higher than current (%s) at %s", targetVersion, version, execPath) + switch { case major > tMajor: return nil diff --git a/testdata/min_version.txt b/testdata/min_version.txt index 015a0cfb..3d79db19 100644 --- a/testdata/min_version.txt +++ b/testdata/min_version.txt @@ -1,6 +1,6 @@ exec git init ! exec lefthook run pre-commit -stdout 'required Lefthook version is higher than current' +stdout 'required lefthook version \(13.1.1\) is higher than current' -- lefthook.yml -- min_version: 13.1.1