Can Git log its command output ? (or do I have to write my own tee
wrapper ?)
A general ability to enable logging for specific commands and subcommands would be handy for debugging purposes. The user should not have to remember to toggle logging after it is configured.
Or other use case: The output of git fetch
can be later retrieved for an high level summary of what changed since the last fetch.
Desired example:
If the following command is executed:
$ git fetch
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.
From /root/tmp/repo1
f1a7f65..c8027d7 branch1 -> origin/branch1
* [new branch] branch2 -> origin/branch2
* [new tag] tag1 -> tag1
$
then log output to file:
$ cat .git/logs/command/fetch
2022-09-10 17:57:45 - git fetch
2022-09-10 17:57:45 - remote: Enumerating objects: 6, done.
2022-09-10 17:57:46 - remote: Counting objects: 100% (6/6), done.
2022-09-10 17:57:47 - remote: Compressing objects: 100% (3/3), done.
2022-09-10 17:57:47 - remote: Total 6 (delta 0), reused 0 (delta 0)
2022-09-10 17:57:48 - Unpacking objects: 100% (6/6), done.
2022-09-10 17:57:48 - From /root/tmp/repo1
2022-09-10 17:57:48 - f1a7f65..c8027d7 branch1 -> origin/branch1
2022-09-10 17:57:48 - * [new branch] branch2 -> origin/branch2
2022-09-10 17:57:48 - * [new tag] tag1 -> tag1
$
Potential dirty workaround:
git() {
logfile=`git rev-parse --git-dir`/git.log
[ -w $logfile ] && command git "$@" 2>&1 | tee -a $logfile
}