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
This commit is contained in:
Tom Ice
2024-04-20 17:31:12 -04:00
parent 41a8542aaa
commit b525ed3b5c
3 changed files with 24 additions and 17 deletions

View File

@@ -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

View File

@@ -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"

View File

@@ -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