diff --git a/script/lib/update-dependency/fetch-outdated-dependencies.js b/script/lib/update-dependency/fetch-outdated-dependencies.js index 7678784f712..54cddd922c0 100644 --- a/script/lib/update-dependency/fetch-outdated-dependencies.js +++ b/script/lib/update-dependency/fetch-outdated-dependencies.js @@ -44,13 +44,14 @@ const apm = async function({ dependencies, packageDependencies }) { const npm = async function(cwd) { try { - console.log('Checking npm registry...'); + console.log('Checking npm registry...', cwd); const currentState = await npmCheck({ cwd, ignoreDev: true, skipUnused: true }); + const outdatedPackages = currentState .get('packages') .filter(p => { diff --git a/script/lib/update-dependency/git.js b/script/lib/update-dependency/git.js index bfcf9b1e22a..53bfe41e463 100644 --- a/script/lib/update-dependency/git.js +++ b/script/lib/update-dependency/git.js @@ -17,24 +17,32 @@ const git = (git, repositoryRootPath) => { } catch (ex) { console.log(ex.message); } + + async function createOrCheckoutBranch(newBranch) { + const { branches } = await git.branch(); + const found = Object.keys(branches).find( + branch => branch.indexOf(newBranch) > -1 + ); + found + ? await git.checkout(found) + : await git.checkoutLocalBranch(newBranch); + + return { found, newBranch }; + } + return { - switchToMaster: async function() { - await git.checkout('origin/master'); + switchToCleanBranch: async function() { + const cleanBranch = 'clean-branch'; + const { current } = await git.branch(); + if (current !== cleanBranch) createOrCheckoutBranch(cleanBranch); }, makeBranch: async function(dependency) { const newBranch = `${dependency.moduleName}-${dependency.latest}`; - const { branches } = await git.branch(); const { files } = await git.status(); if (files.length > 0) { await git.reset('hard'); } - const found = Object.keys(branches).find( - branch => branch.indexOf(newBranch) > -1 - ); - found - ? await git.checkout(found) - : await git.checkoutLocalBranch(newBranch); - return { found, newBranch }; + return createOrCheckoutBranch(newBranch); }, createCommit: async function({ moduleName, latest }) { try { diff --git a/script/lib/update-dependency/main.js b/script/lib/update-dependency/main.js index 733108203fc..bd6781c10bc 100644 --- a/script/lib/update-dependency/main.js +++ b/script/lib/update-dependency/main.js @@ -17,7 +17,7 @@ const runApmInstall = require('../run-apm-install'); const { makeBranch, createCommit, - switchToMaster, + switchToCleanBranch, publishBranch, deleteBranch } = require('./git')(git, repositoryRootPath); @@ -27,7 +27,7 @@ const fetchOutdatedDependencies = require('./fetch-outdated-dependencies'); module.exports = async function() { try { // ensure we are on master - await switchToMaster(); + await switchToCleanBranch(); const failedBumps = []; const successfullBumps = []; const outdateDependencies = [ @@ -69,7 +69,7 @@ module.exports = async function() { }); } - await switchToMaster(); + await switchToCleanBranch(); } // create PRs here for (const { dependency, branch, branchIsRemote } of pendingPRs) { diff --git a/script/lib/update-dependency/spec/git-spec.js b/script/lib/update-dependency/spec/git-spec.js index fca2ca76508..ed11c46b1c7 100644 --- a/script/lib/update-dependency/spec/git-spec.js +++ b/script/lib/update-dependency/spec/git-spec.js @@ -4,7 +4,7 @@ const repositoryRootPath = path.resolve('.', 'fixtures', 'dummy'); const git = simpleGit(repositoryRootPath); const { - switchToMaster, + switchToCleanBranch, makeBranch, publishBranch, createCommit, @@ -23,7 +23,7 @@ describe('GIT', () => { const branch = `${dependency.moduleName}-${dependency.latest}`; beforeEach(async () => { - await git.checkout('master'); + await git.checkout('clean-branch'); }); it('remotes should include ATOM', async () => { @@ -31,14 +31,14 @@ describe('GIT', () => { expect(remotes.map(({ name }) => name).includes('ATOM')).toBeTruthy(); }); - it('current branch should be master', async () => { + it('current branch should be clean-branch', async () => { const testBranchExists = await findBranch('test'); testBranchExists ? await git.checkout('test') : await git.checkoutLocalBranch('test'); expect((await git.branch()).current).toBe('test'); - await switchToMaster(); - expect((await git.branch()).current).toBe('master'); + await switchToCleanBranch(); + expect((await git.branch()).current).toBe('clean-branch'); await git.deleteLocalBranch('test', true); }); @@ -47,7 +47,7 @@ describe('GIT', () => { expect(found).toBe(undefined); expect(newBranch).toBe(branch); expect((await git.branch()).current).toBe(branch); - await git.checkout('master'); + await git.checkout('clean-branch'); await git.deleteLocalBranch(branch, true); }); @@ -56,7 +56,7 @@ describe('GIT', () => { const { found } = await makeBranch(dependency); expect(found).not.toBe(undefined); expect((await git.branch()).current).toBe(found); - await git.checkout('master'); + await git.checkout('clean-branch'); await git.deleteLocalBranch(branch, true); }); @@ -86,7 +86,7 @@ describe('GIT', () => { it('should delete an existing branch', async () => { await git.checkoutLocalBranch(branch); - await git.checkout('master'); + await git.checkout('clean-branch'); expect(await findBranch(branch)).not.toBe(undefined); await deleteBranch(branch); expect(await findBranch(branch)).toBe(undefined);