var buildFile = require('./build-file')
var runGitCommand = require('./helpers/run-git-command')

var COMMITHASH_COMMAND = 'rev-parse HEAD'
var VERSION_COMMAND = 'describe --always'
var BRANCH_COMMAND = 'rev-parse --abbrev-ref HEAD'

function GitRevisionPlugin (options) {
  options = options || {}

  this.gitWorkTree = options.gitWorkTree

  this.commithashCommand = options.commithashCommand ||
    COMMITHASH_COMMAND

  this.versionCommand = options.versionCommand ||
    VERSION_COMMAND + (options.lightweightTags ? ' --tags' : '')

  this.createBranchFile = options.branch || false

  this.branchCommand = options.branchCommand ||
    BRANCH_COMMAND

  if (options.versionCommand && options.lightweightTags) {
    throw new Error('lightweightTags can\'t be used together versionCommand')
  }
}

GitRevisionPlugin.prototype.apply = function (compiler) {
  buildFile({
    compiler: compiler,
    gitWorkTree: this.gitWorkTree,
    command: this.commithashCommand,
    replacePattern: /\[git-revision-hash\]/gi,
    asset: 'COMMITHASH'
  })

  buildFile({
    compiler: compiler,
    gitWorkTree: this.gitWorkTree,
    command: this.versionCommand,
    replacePattern: /\[git-revision-version\]/gi,
    asset: 'VERSION'
  })

  if (this.createBranchFile) {
    buildFile({
      compiler: compiler,
      gitWorkTree: this.gitWorkTree,
      command: this.branchCommand,
      replacePattern: /\[git-revision-branch\]/gi,
      asset: 'BRANCH'
    })
  }
}

GitRevisionPlugin.prototype.commithash = function () {
  return runGitCommand(
    this.gitWorkTree,
    this.commithashCommand
  )
}

GitRevisionPlugin.prototype.version = function () {
  return runGitCommand(
    this.gitWorkTree,
    this.versionCommand
  )
}

GitRevisionPlugin.prototype.branch = function () {
  return runGitCommand(
    this.gitWorkTree,
    this.branchCommand
  )
}

module.exports = GitRevisionPlugin

@@ -225,16 +225,71 @@
 ef HEAD'
+%0Avar LASTCOMMITDATETIME_COMMAND = 'log -1 --format=%25cI'
 %0A%0Afuncti
@@ -705,16 +705,120 @@
 OMMAND%0A%0A
+  this.lastCommitDateTimeCommand = options.lastCommitDateTimeCommand %7C%7C%0A    LASTCOMMITDATETIME_COMMAND%0A%0A
   if (op
@@ -1382,16 +1382,235 @@
 '%0A  %7D)%0A%0A
+  buildFile(%7B%0A    compiler: compiler,%0A    gitWorkTree: this.gitWorkTree,%0A    command: this.lastCommitDateTimeCommand,%0A    replacePattern: /%5C%5Bgit-revision-last-commit-datetime%5C%5D/gi,%0A    asset: 'LASTCOMMITDATETIME'%0A  %7D)%0A%0A
   if (th
@@ -2186,32 +2186,32 @@
 is.gitWorkTree,%0A
-
     this.branchC
@@ -2224,16 +2224,167 @@
 %0A  )%0A%7D%0A%0A
+GitRevisionPlugin.prototype.lastcommitdatetime = function () %7B%0A  return runGitCommand(%0A    this.gitWorkTree,%0A    this.lastCommitDateTimeCommand%0A  )%0A%7D%0A%0A
 module.e

Implement last commit date time (tests / docs not done)