diff --git a/lib/manager/gomod/artifacts.js b/lib/manager/gomod/artifacts.js index 1398f261b2e506d2e260f14ddebefea63e882956..03acded1b878bb9f4d21c4f108df12168ba00b07 100644 --- a/lib/manager/gomod/artifacts.js +++ b/lib/manager/gomod/artifacts.js @@ -29,7 +29,14 @@ async function getArtifacts( let stderr; try { const localGoModFileName = upath.join(config.localDir, goModFileName); - await fs.outputFile(localGoModFileName, newGoModContent); + const massagedGoMod = newGoModContent.replace( + /\nreplace\s+[^\s]+\s+=>\s+\.\.\/.*/g, + '' + ); + if (massagedGoMod !== newGoModContent) { + logger.debug('Removed some relative replace statements from go.mod'); + } + await fs.outputFile(localGoModFileName, massagedGoMod); const localGoSumFileName = upath.join(config.localDir, sumFileName); if (!config.gitFs) { await fs.outputFile(localGoSumFileName, existingGoSumContent); diff --git a/test/_fixtures/go/1/go.mod b/test/_fixtures/go/1/go.mod index 3b1e1abf53e4df8e9e12bcddaa5f31e876f39b34..61e316ad7ad40f49dc3e7dba83a2b196d82fb4b3 100644 --- a/test/_fixtures/go/1/go.mod +++ b/test/_fixtures/go/1/go.mod @@ -6,3 +6,5 @@ require github.com/davecgh/go-spew v1.0.0 require golang.org/x/foo v1.0.0 require github.com/rarkins/foo abcdef1 require gopkg.in/russross/blackfriday.v1 v1.0.0 + +replace github.com/pkg/errors => ../errors diff --git a/test/manager/gomod/__snapshots__/update.spec.js.snap b/test/manager/gomod/__snapshots__/update.spec.js.snap index 405829a75a978b5a7e220521ed35a84659a32b71..8528f18f3741a6174d00cf352910e072c21019e6 100644 --- a/test/manager/gomod/__snapshots__/update.spec.js.snap +++ b/test/manager/gomod/__snapshots__/update.spec.js.snap @@ -9,6 +9,8 @@ require github.com/davecgh/go-spew v1.0.0 require golang.org/x/foo v1.0.0 require github.com/rarkins/foo abcdef1 require gopkg.in/russross/blackfriday.v2 v2.0.0 + +replace github.com/pkg/errors => ../errors " `; @@ -88,5 +90,7 @@ require github.com/davecgh/go-spew v1.0.0 require golang.org/x/foo v1.0.0 require github.com/rarkins/foo abcdef1 require gopkg.in/russross/blackfriday.v1 v1.0.0 + +replace github.com/pkg/errors => ../errors " `; diff --git a/test/manager/gomod/artifacts.spec.js b/test/manager/gomod/artifacts.spec.js index 22c13bee33fdfd550b9e42236e815609bfd09f77..5357c8ffcf26dc76ab24178d746d9dd51c4fb19a 100644 --- a/test/manager/gomod/artifacts.spec.js +++ b/test/manager/gomod/artifacts.spec.js @@ -5,6 +5,18 @@ const fs = require('fs-extra'); const { exec } = require('child-process-promise'); const gomod = require('../../../lib/manager/gomod/artifacts'); +const gomod1 = `module github.com/renovate-tests/gomod1 + +require github.com/pkg/errors v0.7.0 +require github.com/aws/aws-sdk-go v1.15.21 +require github.com/davecgh/go-spew v1.0.0 +require golang.org/x/foo v1.0.0 +require github.com/rarkins/foo abcdef1 +require gopkg.in/russross/blackfriday.v1 v1.0.0 + +replace github.com/pkg/errors => ../errors +`; + const config = { localDir: '/tmp/github/some/repo', }; @@ -14,7 +26,7 @@ describe('.getArtifacts()', () => { jest.resetAllMocks(); }); it('returns if no go.sum found', async () => { - expect(await gomod.getArtifacts('go.mod', [], '{}', config)).toBeNull(); + expect(await gomod.getArtifacts('go.mod', [], gomod1, config)).toBeNull(); }); it('returns null if unchanged', async () => { platform.getFile.mockReturnValueOnce('Current go.sum'); @@ -23,7 +35,7 @@ describe('.getArtifacts()', () => { stderror: '', }); fs.readFile = jest.fn(() => 'Current go.sum'); - expect(await gomod.getArtifacts('go.mod', [], '{}', config)).toBeNull(); + expect(await gomod.getArtifacts('go.mod', [], gomod1, config)).toBeNull(); }); it('returns updated go.sum', async () => { platform.getFile.mockReturnValueOnce('Current go.sum'); @@ -32,7 +44,9 @@ describe('.getArtifacts()', () => { stderror: '', }); fs.readFile = jest.fn(() => 'New go.sum'); - expect(await gomod.getArtifacts('go.mod', [], '{}', config)).not.toBeNull(); + expect( + await gomod.getArtifacts('go.mod', [], gomod1, config) + ).not.toBeNull(); }); it('supports docker mode', async () => { platform.getFile.mockReturnValueOnce('Current go.sum'); @@ -42,7 +56,7 @@ describe('.getArtifacts()', () => { }); fs.readFile = jest.fn(() => 'New go.sum'); expect( - await gomod.getArtifacts('go.mod', [], '{}', { + await gomod.getArtifacts('go.mod', [], gomod1, { ...config, binarySource: 'docker', }) @@ -54,7 +68,7 @@ describe('.getArtifacts()', () => { throw new Error('This update totally doesnt work'); }); expect( - await gomod.getArtifacts('go.mod', [], '{}', config) + await gomod.getArtifacts('go.mod', [], gomod1, config) ).toMatchSnapshot(); }); });