From b525ed3b5c593eaf10045c92e2b38d98f07c3963 Mon Sep 17 00:00:00 2001 From: Tom Ice Date: Sat, 20 Apr 2024 17:31:12 -0400 Subject: [PATCH] Create new repo if running tests in non-git area * When running "make test" in the root directory of this codebase, an error will occur as this shell script requires a repo to be initialized before it can properly execute. This was done in the past, but at some point, it was removed. This adds the feature back, tests if we are in a git directory by using a built-in git command, and only performs this action if a git repo doesn't already exist. All actions are sent to /dev/null so the testing should look opaque to the end user. Note that tests will still fail if a user is missing a required utility to perform the functionality of git-quick-stats. * Fixed a typo in the man page Fixes #162 --- git-quick-stats.1 | 4 ++-- tests/commands_test.sh | 8 ++++++++ tests/test-git/resetgit | 29 ++++++++++++++--------------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/git-quick-stats.1 b/git-quick-stats.1 index 417432e..55a05f6 100644 --- a/git-quick-stats.1 +++ b/git-quick-stats.1 @@ -1,4 +1,4 @@ -.TH git-quick-stats "1" "June 2021" "git-quick-stats" "User Commands" +.TH git-quick-stats "1" "April 2024" "git-quick-stats" "User Commands" .SH NAME .B git\-quick\-stats \- Simple and efficient way to access various stats in a git repository. @@ -95,7 +95,7 @@ displays a list of commits per year displays a list of commits per weekday .HP .PP -\fB\-W\fR, \fB\-\-commits\-by\author\-by\-weekday\fR +\fB\-W\fR, \fB\-\-commits\-by\-author\-by\-weekday\fR .IP displays a list of commits per weekday by author .HP diff --git a/tests/commands_test.sh b/tests/commands_test.sh index 456698e..bd55765 100755 --- a/tests/commands_test.sh +++ b/tests/commands_test.sh @@ -1,5 +1,13 @@ #!/bin/bash +# Verify we are in a git repo. Create one if not +# FIXME: All the paths are hardcoded currently and will break if anything +# in this chain moves or gets executed elsewhere. Adjust all of these so +# pathing does not matter as much such as creating a TOP variable that +# does something like TOP=$(cd "$(dirname "$0")" || exit ; pwd -P) +# or maybe leverages Make to handle these as test targets +./tests/test-git/resetgit + . tests/assert.sh -v src="./git-quick-stats" diff --git a/tests/test-git/resetgit b/tests/test-git/resetgit index 1a1da35..3e13b0a 100755 --- a/tests/test-git/resetgit +++ b/tests/test-git/resetgit @@ -1,17 +1,16 @@ #!/bin/sh -# Initialises a new local Git repo for test purpose. -if test -d ../test-git/.git; then rm -Rf ../test-git/.git; fi -#mkdir test-git -cd ../test-git -git init -git config user.name "$(printf %s 'Test Git,\nfor test purpose')" -git config user.email "TestGit\o/@example.org" +# Initialises a new local Git repo for test purpose if one does not exist already +if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then + { + git init + git config user.name "$(printf %s 'Test Git,\nfor test purpose')" + git config user.email "TestGit\o/@example.org" -#printf '\n[user]\nname = test-git\nemail = test-git@example.org\n'> .git/config -printf 'test-git\n========\n' > README.md -git add README.md -git commit -m 'added readme (o\w/o)' -m 'in markdown, no \r\n, only \n' -m 'a very "simple" readme' -testChars="$(printf 'tab [%b] form feed [%b] line feed [%b] carriage return [%b]' '\x09' '\x0C' '\x0A' '\x0D')" -#printf '# testChars [%s]\n' "$testChars">&2 -git notes add -m 'Some notes' -m 'out of ascii: été au cœur' -m "$testChars" -git log + printf 'test-git\n========\n' > README.md + git add README.md + git commit -m 'added readme (o\w/o)' -m 'in markdown, no \r\n, only \n' -m 'a very "simple" readme' + testChars="$(printf 'tab [%b] form feed [%b] line feed [%b] carriage return [%b]' '\x09' '\x0C' '\x0A' '\x0D')" + git notes add -m 'Some notes' -m 'out of ascii: été au cœur' -m "$testChars" + git log + } >/dev/null 2>&1 +fi