From eabff37a15375973549dc7ec374d30d77900a3c1 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@keylocation.sg>
Date: Mon, 27 Nov 2017 08:25:07 +0100
Subject: [PATCH] fix: exit gracefully if no files to commit (#1242)

This handles case where checking for lock file maintenance but lock file is up-to-date.
---
 lib/workers/branch/commit.js      | 2 ++
 lib/workers/branch/index.js       | 5 ++++-
 test/workers/branch/index.spec.js | 8 ++++----
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/lib/workers/branch/commit.js b/lib/workers/branch/commit.js
index 1916f10fa3..52000a4888 100644
--- a/lib/workers/branch/commit.js
+++ b/lib/workers/branch/commit.js
@@ -29,5 +29,7 @@ async function commitFilesToBranch(config) {
     );
   } else {
     logger.debug(`No files to commit`);
+    return false;
   }
+  return true;
 }
diff --git a/lib/workers/branch/index.js b/lib/workers/branch/index.js
index 7d4b6c5b8e..80284f482e 100644
--- a/lib/workers/branch/index.js
+++ b/lib/workers/branch/index.js
@@ -100,7 +100,10 @@ async function processBranch(branchConfig) {
     } else {
       logger.debug('No updated lock files in branch');
     }
-    await commitFilesToBranch(config);
+    const committedFiles = await commitFilesToBranch(config);
+    if (!committedFiles) {
+      return 'no-work';
+    }
 
     // Set branch statuses
     await setUnpublishable(config);
diff --git a/test/workers/branch/index.spec.js b/test/workers/branch/index.spec.js
index 0e51473f48..d8d583234a 100644
--- a/test/workers/branch/index.spec.js
+++ b/test/workers/branch/index.spec.js
@@ -16,7 +16,6 @@ jest.mock('../../../lib/workers/branch/schedule');
 jest.mock('../../../lib/workers/branch/check-existing');
 jest.mock('../../../lib/workers/branch/parent');
 jest.mock('../../../lib/workers/branch/lock-files');
-jest.mock('../../../lib/workers/branch/commit');
 jest.mock('../../../lib/workers/branch/status-checks');
 jest.mock('../../../lib/workers/branch/automerge');
 jest.mock('../../../lib/workers/pr');
@@ -34,10 +33,12 @@ describe('workers/branch', () => {
         upgrades: [{ depName: 'some-dep-name' }],
       };
       schedule.isScheduledNow.mockReturnValue(true);
+      commit.commitFilesToBranch = jest.fn(() => true);
     });
     afterEach(() => {
       platform.ensureComment.mockClear();
       platform.ensureCommentRemoval.mockClear();
+      commit.commitFilesToBranch.mockClear();
       jest.resetAllMocks();
     });
     it('skips branch if not scheduled and branch does not exist', async () => {
@@ -81,7 +82,7 @@ describe('workers/branch', () => {
       await branchWorker.processBranch(config);
       expect(parent.getParentBranch.mock.calls.length).toBe(0);
     });
-    it('returns if no branch exists', async () => {
+    it('returns if no work', async () => {
       manager.getUpdatedPackageFiles.mockReturnValueOnce({
         updatedPackageFiles: [],
       });
@@ -90,8 +91,7 @@ describe('workers/branch', () => {
         updatedLockFiles: [],
       });
       platform.branchExists.mockReturnValueOnce(false);
-      await branchWorker.processBranch(config);
-      expect(commit.commitFilesToBranch.mock.calls).toHaveLength(1);
+      expect(await branchWorker.processBranch(config)).toEqual('no-work');
     });
     it('returns if branch automerged', async () => {
       manager.getUpdatedPackageFiles.mockReturnValueOnce({
-- 
GitLab