/*
 * Copyright 2017 HM Revenue & Customs
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import path from 'path'
import test from 'tape'
import { execFileSync } from 'child_process'
import suiteName from './utils/suite'
import gitDescribe from '../lib/git-describe'

const suite = suiteName(__filename)

const repoDir = path.join(__dirname, 'test-repo')

test(`${suite} Fail if the given path is not a git repo`, (t) => {
  t.throws(function () {
    gitDescribe(repoDir)
  }, new RegExp(/fatal: Not a git repository:/))

  t.end()
})

test(`${suite} Return the sha of the parent repo if not given a path`, (t) => {
  const execArgs = [
    'describe',
    '--long',
    '--always'
  ]

  const parentSha = execFileSync('git', execArgs)
  const sha = gitDescribe()

  t.equal(parentSha.toString('utf-8').trim(), sha)
  t.end()
})

@@ -655,24 +655,21 @@
 mport %7B 
-execFile
+spawn
 Sync %7D f
@@ -1134,25 +1134,38 @@
 nst 
-execArgs = %5B%0A    
+parentSha = spawnSync('git', %5B
 'des
@@ -1171,20 +1171,16 @@
 scribe',
-%0A   
  '--long
@@ -1181,20 +1181,16 @@
 --long',
-%0A   
  '--alwa
@@ -1196,62 +1196,9 @@
 ays'
-%0A  %5D%0A%0A  const parentSha = execFileSync('git', execArgs
+%5D
 )%0A  
@@ -1224,16 +1224,16 @@
 ribe()%0A%0A
-
   t.equa
@@ -1244,16 +1244,23 @@
 rentSha.
+stdout.
 toString

Switch execFile out for spawn and flatten args in tests