@@ -5,6 +5,9 @@ import Keys._
5
5
import java .util .{Date , Locale , Properties , TimeZone }
6
6
import java .io .{File , FileInputStream }
7
7
import java .text .SimpleDateFormat
8
+ import java .time .Instant
9
+ import java .time .format .DateTimeFormatter
10
+ import java .time .temporal .{TemporalAccessor , TemporalQueries , TemporalQuery }
8
11
9
12
import scala .collection .JavaConverters ._
10
13
import BuildSettings .autoImport ._
@@ -71,8 +74,21 @@ object VersionUtil {
71
74
val db = new FileRepositoryBuilder ().findGitDir.build
72
75
val head = db.resolve(" HEAD" )
73
76
if (head eq null ) {
74
- log.info(" No git HEAD commit found -- Using current date and 'unknown' SHA" )
75
- (new Date , " unknown" )
77
+ import scala .sys .process ._
78
+ try {
79
+ // Workaround lack of git worktree support in JGit https://bugs.eclipse.org/bugs/show_bug.cgi?id=477475
80
+ val sha = List (" git" , " rev-parse" , " HEAD" ).!! .trim
81
+ val commitDateIso = List (" git" , " log" , " -1" , " --format=%cI" , " HEAD" ).!! .trim
82
+ val date = java.util.Date .from(DateTimeFormatter .ISO_DATE_TIME .parse(commitDateIso, new TemporalQuery [Instant ] {
83
+ override def queryFrom (temporal : TemporalAccessor ): Instant = Instant .from(temporal)
84
+ }))
85
+ (date, sha.substring(0 , 7 ))
86
+ } catch {
87
+ case ex : Exception =>
88
+ ex.printStackTrace()
89
+ log.info(" No git HEAD commit found -- Using current date and 'unknown' SHA" )
90
+ (new Date , " unknown" )
91
+ }
76
92
} else {
77
93
val commit = new RevWalk (db).parseCommit(head)
78
94
(new Date (commit.getCommitTime.toLong * 1000L ), commit.getName.substring(0 , 7 ))
0 commit comments