fix: cli: updates hledger-git record command to use plain git

This fixes the issue in https://github.com/simonmichael/hledger/issues/1942.
Instead of relying on a `git record` alias being present `hledger git record`
uses only vanilla git.

The expected alias for record is:
```
record = ! sh -c '(git add -p -- $@ && git commit) || git reset' --
```

The removed `git record` is in the script is implemented using:
- `git commit` with the given messages (and additional arguments if given)
- `git reset` if the commit fails

`git add -p` isn't needed because the files are added already above. Also
this would be interactive which isn't the goal for this call.

The message still defaults to the date if not given, however I had to add
a check to only shift if arguments were passed in, otherwise shift fails.
This commit is contained in:
Patrick Fiaux 2022-11-13 16:21:12 +01:00 committed by Simon Michael
parent 74f9cd866c
commit b3de7e59af

View File

@ -74,8 +74,11 @@ record() {
ensure_git_repo
cd "$DIR"
for F in $FILES; do $GIT add -f "$F"; done
MSG=${1:-$(date +'%Y-%m-%d %H:%M:%S %Z')}; shift
$GIT record -m "$MSG" "$@" -- "$FILES"
MSG=${1:-$(date +'%Y-%m-%d %H:%M:%S %Z')}
if [ $# -ge 1 ]; then
shift
fi
$GIT commit -m "$MSG" "$@" || $GIT reset
}
status() {