From 9c845040ac376a73e5f3e493c66af05d7228aeb3 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Mon, 12 Feb 2018 06:58:33 +0100 Subject: [PATCH] fix: delete gitlab branch first if rebasing --- lib/platform/gitlab/index.js | 3 +++ test/platform/gitlab/index.spec.js | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/platform/gitlab/index.js b/lib/platform/gitlab/index.js index 224a3e52da..37d740beb6 100644 --- a/lib/platform/gitlab/index.js +++ b/lib/platform/gitlab/index.js @@ -538,6 +538,9 @@ async function commitFilesToBranch( action.action = (await getFile(file.name)) ? 'update' : 'create'; opts.body.actions.push(action); } + if (await branchExists(branchName)) { + await deleteBranch(branchName); + } await get.post(`projects/${config.repository}/repository/commits`, opts); } diff --git a/test/platform/gitlab/index.spec.js b/test/platform/gitlab/index.spec.js index 7e837bdfcd..8d5e3e0b8b 100644 --- a/test/platform/gitlab/index.spec.js +++ b/test/platform/gitlab/index.spec.js @@ -641,7 +641,12 @@ describe('platform/gitlab', () => { }); describe('commitFilesToBranch(branchName, files, message, parentBranch)', () => { it('creates file', async () => { - get.mockImplementationOnce(() => Promise.reject({ statusCode: 404 })); + get.mockImplementationOnce(() => Promise.reject({ statusCode: 404 })); // file exists + get.mockImplementationOnce(() => + Promise.reject({ + statusCode: 404, + }) + ); // branch exists const file = { name: 'some-new-file', contents: 'some new-contents', @@ -655,6 +660,7 @@ describe('platform/gitlab', () => { expect(get.post.mock.calls).toHaveLength(1); }); it('updates multiple files', async () => { + // Two files exist get.mockReturnValueOnce({ body: { content: 'foo', @@ -665,6 +671,8 @@ describe('platform/gitlab', () => { content: 'foo', }, }); + // branch exists + get.mockImplementationOnce(() => ({ statusCode: 200 })); const files = [ { name: 'some-existing-file', -- GitLab