From c596673da1b494513720c8d1786d3b286ff8fae6 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@keylocation.sg>
Date: Fri, 16 Jun 2017 11:57:04 +0200
Subject: [PATCH] Fix check for yarn.lock maintenance existing (#314)

* Fix check for yarn.lock maintenance existing

Closes #313

* Fix test

* Fix lint
---
 lib/helpers/yarn.js       | 8 ++++++--
 test/helpers/yarn.spec.js | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/helpers/yarn.js b/lib/helpers/yarn.js
index 254ed8ce7d..1dfc24f75c 100644
--- a/lib/helpers/yarn.js
+++ b/lib/helpers/yarn.js
@@ -89,9 +89,13 @@ async function maintainLockFile(inputConfig) {
     'yarn.lock'
   );
   logger.debug(`Checking for ${yarnLockFileName}`);
-  const existingYarnLock = await inputConfig.api.getFileContent(
-    yarnLockFileName
+  let existingYarnLock = await inputConfig.api.getFileContent(
+    yarnLockFileName,
+    inputConfig.branchName
   );
+  if (!existingYarnLock) {
+    existingYarnLock = await inputConfig.api.getFileContent(yarnLockFileName);
+  }
   logger.silly(`existingYarnLock:\n${existingYarnLock}`);
   if (!existingYarnLock) {
     return null;
diff --git a/test/helpers/yarn.spec.js b/test/helpers/yarn.spec.js
index 8ba85f918c..7fc737a440 100644
--- a/test/helpers/yarn.spec.js
+++ b/test/helpers/yarn.spec.js
@@ -69,7 +69,7 @@ describe('maintainLockFile(inputConfig)', () => {
   });
   it('returns null if no file to maintain', async () => {
     const yarnLock = await yarnHelper.maintainLockFile(config);
-    expect(config.api.getFileContent.mock.calls.length).toBe(2);
+    expect(config.api.getFileContent.mock.calls.length).toBe(3);
     expect(yarnLock).toEqual(null);
   });
   it('returns null if contents match', async () => {
-- 
GitLab