Fixed corner case of determineWebAssetModifications step

git log would return empty line for files with no git history.

Added a check that uses current time instead of git log if file is not in git history.
This commit is contained in:
Risto Lahtela 2021-09-26 14:00:54 +03:00
parent dc8b1c5a3a
commit 4258e27a66
1 changed files with 2 additions and 1 deletions

View File

@ -43,8 +43,9 @@ task determineWebAssetModifications {
commandLine 'git', 'log', '-1', '--pretty=%ct', f.toString()
standardOutput = gitModified
}
def gitModifiedAsString = gitModified.toString().strip()
// git returns UNIX time in seconds, but most things in Java use UNIX time in milliseconds
def modified = Long.parseLong(gitModified.toString().strip()) * 1000
def modified = gitModifiedAsString.isEmpty() ? System.currentTimeMillis() : Long.parseLong(gitModifiedAsString) * 1000
def relativePath = tree.getDir().toPath().relativize(f.toPath()) // File path relative to the tree
versionFile.text += String.format( // writing YAML as raw text probably isn't the best idea
"%s: %s\n", relativePath.toString().replace('.', ','), modified