Aim
I would like to know the amount of lines changed in a particular repository over a period of time and print this into a simple text file. However, when I run the code below I receive an error that I'm not sure how to solve.
The code
git log --stat --since="2015-01-01" --until="2015-11-16" `find . \( ! -path "*[PATH]*" -a ! -path "*[PATH2]*" \)` | awk -F',' "/files? changed/ {
files += \$1
insertions += \$2
deletions += \$3
destination = \"$DESTINATION\"}
END {
print \"Files Changed: \" files > destination
print \"Insertions: \" insertions > destination
print \"Deletions: \" deletions > destination
print \"Lines changed: \" insertions + deletions > destination}"
The error
fatal: ambiguous argument '[PATH]': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
awk: cmd. line:7: fatal: expression for `>' redirection has null string value
Other useful information
Question
Could someone please help me understand what I've done wrong or provide a better way of excluding multiple directories?
Any help would be much appreciated.
The error message written by git tells how to fix the error. The problem is that, sometimes, git is unable to tell if the first argument it is given is a path or a revision. The --
can be used to disambiguate arguments.
Asides from this, there is a few other minor problems in your code. The shell also understands simple quotes, where variables are not expanded. You definitely should write your awk script in simple quotes, as it prevents clumsy escape sequences to spam your code.
git log --stat --since='2015-01-01' --until='2015-11-16' $(find . \( ! -path '*[PATH]*' -a ! -path '*[PATH2]*' \)) | awk -F',' '
/files? changed/ {
files += $1
insertions += $2
deletions += $3
}
END {
print "Files Changed: " files
print "Insertions: " insertions
print "Deletions: " deletions
print "Lines changed: " insertions + deletions
}' > "${DESTINATION}"
Also, if you are writing output to only one file, it is easier to let awk write its report to stdout and redirect it to the file you want, rather than doing output redirections in awk itself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.