From 2952cd51ed03a8b95fbe6a364c1eb1e7b7686784 Mon Sep 17 00:00:00 2001 From: Tronje Krop Date: Wed, 25 Sep 2024 12:30:53 +0200 Subject: [PATCH] feat: improve git-fix and build/requirement notice (#105) Signed-off-by: Tronje Krop --- MANUAL.md | 18 +++++----- Makefile | 2 +- README.md | 43 ++++++++++++++++-------- VERSION | 2 +- config/Makefile | 2 +- config/Makefile.base | 17 ++++++---- internal/make/fixtures/targets/std.out | 5 +++ internal/make/fixtures/targets/trace.out | 5 +++ 8 files changed, 61 insertions(+), 33 deletions(-) diff --git a/MANUAL.md b/MANUAL.md index 0ba5649..85e88be 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -581,15 +581,15 @@ conventional commits, where `*` is a placeholder for the [conventional commit types](#commit-types): ```bash -make git-list # shows the git log as pretty printed list -make git-graph # shows the git log as pretty printed graph -make git-clean [all] # cleans up git history by removing merged branches -make git-reset [all] # checks out default branch and cleans up git history -make git-create(-*) # creates and pushes a branch with the current change set -make git-commit(-*) # commits the current change set to the current branch -make git-fix [...] # pushes the latest changes to the previous commit -make git-push # pushes the current branch to the upstream repository -make git-verify # checks git log to follow commit conventions +make git-list # shows the git log as pretty printed list +make git-graph # shows the git log as pretty printed graph +make git-clean [all] # cleans up git history by removing merged branches +make git-reset [all] # checks out default branch and cleans up git history +make git-create(-*) # creates and pushes a branch with the current changes +make git-commit(-*) # commits the current change set to the current branch +make git-fix(-*) [...] # pushes the latest changes to the previous commit +make git-push # pushes the current branch to the upstream repository +make git-verify # checks git log to follow commit conventions ``` The `git-create(-*)` targets support `` and a `` argument diff --git a/Makefile b/Makefile index e6c892a..5c79baf 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ export GOPATH ?= $(shell $(GO) env GOPATH) export GOBIN ?= $(GOPATH)/bin # Setup go-make version to use desired build and config scripts. -GOMAKE_DEP ?= github.com/tkrop/go-make@v0.0.102 +GOMAKE_DEP ?= github.com/tkrop/go-make@v0.0.103 INSTALL_FLAGS ?= -mod=readonly -buildvcs=auto # Request targets from go-make targets target. TARGETS := $(shell command -v $(GOBIN)/go-make >/dev/null || \ diff --git a/README.md b/README.md index 6982e0d..6195df0 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,6 @@ desireable, e.g. for [`revive`][revive] and [`golangci-lint`][golangci] the default import is version. Other tools can be versioned if needed (see [manual](MANUAL.md) for more information). -[go-make]: [gomock]: [golangci]: [revive]: @@ -163,21 +162,29 @@ Other available [config](config) files can be installed one by one using `go-make init/`. If you use [`go-make`][go-make] in your project, you may want to copy the -following [Project requirement notice](#project-requirement-notice) into your -[README.md]. +following [Project build/requirement notice](#project-buildrequirement-notice) +into your [README.md]. -### Project requirement notice +### Project build/requirement notice -**Note:** This project supports Linux and MacOS Darwin using the standardized -[`Makefile`](Makefile) provided by [`go-make`][go-make]. The project therefore -depends on [`go`][go] for version management, and makes heavy use of GNU tools, -i.e. [`coretils`][core], [`findutils`][find], ['(g)make'][make], -[`(g)awk`][awk], [`(g)sed`][sed], and not the least [`bash`][bash]. For certain -non-core-features it also requires [`docker`][docker]/[`podman`][podman] and -[`curl`][curl]. On MacOS, it uses [brew][brew] to ensure that the latest -versions with the exception [`docker`][docker]/[`podman`][podman] are. +This project is using [go-make][go-make], which provides default targets for +most common tasks, to initialize, build, test, and run the software of this +project. Read the [go-make manual][go-make-man] for more information about +targets and configuration options. +[go-make]: +[go-make-man]: + +The [`Makefile`](Makefile) depends on a preinstalled [`go`][go] for version +management, and makes heavy use of GNU tools, i.e. [`coretils`][core], +[`findutils`][find], ['(g)make'][make], [`(g)awk`][awk], [`(g)sed`][sed], and +not the least [`bash`][bash]. For certain non-core-features it also requires +[`docker`][docker]/[`podman`][podman] and [`curl`][curl]. On MacOS, it uses +[brew][brew] to ensure that the latest versions with the exception +[`docker`][docker]/[`podman`][podman] are. + +[go]: [brew]: [curl]: [docker]: @@ -189,6 +196,16 @@ versions with the exception [`docker`][docker]/[`podman`][podman] are. [awk]: [sed]: +**Not:** [go-make][go-make] automatically installs `pre-commit` and `commit-msg` +[hooks][git-hooks] overwriting and deleting pre-existing hooks (see also +[Customizing Git - Git Hooks][git-hooks]). The `pre-commit` hook calls +`make commit` as an alias for executing `test-go`, `test-unit`, `lint-`, +and `lint-markdown` to enforce successful testing and linting. The `commit-msg` +hook calls `make git-verify message` for validating whether the commit message +is following the [conventional commit][convent-commit] best practice. + +[git-hooks]: +[convent-commit]: ## Shell integration @@ -260,8 +277,6 @@ the [`go`][go]-project automatically, installing the necessary tools - except for the golang compiler and build environment -, and triggering the required targets as necessary. -[go]: - ## Trouble Shooting diff --git a/VERSION b/VERSION index 339aaaf..6fa0800 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.102 +0.0.103 diff --git a/config/Makefile b/config/Makefile index e6c892a..5c79baf 100644 --- a/config/Makefile +++ b/config/Makefile @@ -12,7 +12,7 @@ export GOPATH ?= $(shell $(GO) env GOPATH) export GOBIN ?= $(GOPATH)/bin # Setup go-make version to use desired build and config scripts. -GOMAKE_DEP ?= github.com/tkrop/go-make@v0.0.102 +GOMAKE_DEP ?= github.com/tkrop/go-make@v0.0.103 INSTALL_FLAGS ?= -mod=readonly -buildvcs=auto # Request targets from go-make targets target. TARGETS := $(shell command -v $(GOBIN)/go-make >/dev/null || \ diff --git a/config/Makefile.base b/config/Makefile.base index 79dd6a7..93544a1 100644 --- a/config/Makefile.base +++ b/config/Makefile.base @@ -242,7 +242,7 @@ go-pkg = $(shell awk -v mode="$(2)" -v filter="$(3)" \ # Setup go-make to use desired build and config scripts. -GOMAKE_DEP := github.com/tkrop/go-make@v0.0.102 +GOMAKE_DEP := github.com/tkrop/go-make@v0.0.103 GOMAKE_MAKEFILE := $(realpath $(firstword $(MAKEFILE_LIST))) GOMAKE_MAKEFILES := $(GOMAKE_MAKEFILE) \ $(wildcard Makefile.vars) $(wildcard Makefile.ext) @@ -794,12 +794,15 @@ $(addprefix git-commit-,$(COMMIT_CONVENTION)):: git-commit-%: @MESSAGE="$(ARGS)"; $(call git-message,$*,0); \ ARGS="" $(GIT) commit --signoff --message "$${MESSAGE}"; exit 0; #@ [(no-)edit|(no-)verify] # pushes the latest changes to the previous commit of the origin. -git-fix:: - @GITFIX=($(patsubst %,"%",$(GITFIX))); GITPUSH=($(patsubst %,"%",$(GITPUSH))); \ - if [[ "$(ARGS)" =~ verify ]]; then GITFIX=("$${GITFIX[@]/--no-verify}"); fi; \ - if [[ "$(ARGS)" =~ no-verify ]]; then GITFIX+=("--no-verify"); fi; \ - if [[ "$(ARGS)" =~ edit ]]; then GITFIX=("$${GITFIX[@]/--no-edit}"); fi; \ - if [[ "$(ARGS)" =~ no-edit ]]; then GITFIX+=("--no-edit"); fi; \ +TARGETS_GIT_FIX := git-fix git-fix-all git-fix-edit git-fix-no-edit git-fix-verify git-fix-no-verify +$(TARGETS_GIT_FIX):: git-fix%: + @ARGS=" $(ARGS) $(*:-%=%) "; \ + if [[ "$${ARGS}" =~ " all " ]]; then git add .; fi; \ + GITFIX=($(patsubst %,"%",$(GITFIX))); GITPUSH=($(patsubst %,"%",$(GITPUSH))); \ + if [[ "$${ARGS}" =~ " verify " ]]; then GITFIX=("$${GITFIX[@]/--no-verify}"); fi; \ + if [[ "$${ARGS}" =~ " no-verify " ]]; then GITFIX+=("--no-verify"); fi; \ + if [[ "$${ARGS}" =~ " edit " ]]; then GITFIX=("$${GITFIX[@]/--no-edit}"); fi; \ + if [[ "$${ARGS}" =~ " no-edit " ]]; then GITFIX+=("--no-edit"); fi; \ for KEY in "$${!GITFIX[@]}"; do \ if [ "$${GITFIX[$${KEY}]}" == "" ]; then unset GITFIX[$${KEY}]; fi; \ done; \ diff --git a/internal/make/fixtures/targets/std.out b/internal/make/fixtures/targets/std.out index 1687ea6..b7373e9 100644 --- a/internal/make/fixtures/targets/std.out +++ b/internal/make/fixtures/targets/std.out @@ -44,6 +44,11 @@ git-create-remove git-create-style git-create-test git-fix +git-fix-all +git-fix-edit +git-fix-no-edit +git-fix-no-verify +git-fix-verify git-graph git-log git-push diff --git a/internal/make/fixtures/targets/trace.out b/internal/make/fixtures/targets/trace.out index db6d5e8..12031f4 100644 --- a/internal/make/fixtures/targets/trace.out +++ b/internal/make/fixtures/targets/trace.out @@ -53,6 +53,11 @@ git-create-remove git-create-style git-create-test git-fix +git-fix-all +git-fix-edit +git-fix-no-edit +git-fix-no-verify +git-fix-verify git-graph git-log git-push