fix: use authenticated URL to check if local branch is up to date
This commit is contained in:
		
							parent
							
								
									9eaf9552c1
								
							
						
					
					
						commit
						7a939a8970
					
				
							
								
								
									
										2
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								index.js
									
									
									
									
									
								
							| @ -65,7 +65,7 @@ async function run(context, plugins) { | |||||||
|     try { |     try { | ||||||
|       await verifyAuth(options.repositoryUrl, options.branch, {cwd, env}); |       await verifyAuth(options.repositoryUrl, options.branch, {cwd, env}); | ||||||
|     } catch (error) { |     } catch (error) { | ||||||
|       if (!(await isBranchUpToDate(options.branch, {cwd, env}))) { |       if (!(await isBranchUpToDate(options.repositoryUrl, options.branch, {cwd, env}))) { | ||||||
|         logger.log( |         logger.log( | ||||||
|           `The local branch ${options.branch} is behind the remote one, therefore a new version won't be published.` |           `The local branch ${options.branch} is behind the remote one, therefore a new version won't be published.` | ||||||
|         ); |         ); | ||||||
|  | |||||||
| @ -170,13 +170,14 @@ async function verifyTagName(tagName, execaOpts) { | |||||||
| /** | /** | ||||||
|  * Verify the local branch is up to date with the remote one. |  * Verify the local branch is up to date with the remote one. | ||||||
|  * |  * | ||||||
|  |  * @param {String} repositoryUrl The remote repository URL. | ||||||
|  * @param {String} branch The repository branch for which to verify status. |  * @param {String} branch The repository branch for which to verify status. | ||||||
|  * @param {Object} [execaOpts] Options to pass to `execa`. |  * @param {Object} [execaOpts] Options to pass to `execa`. | ||||||
|  * |  * | ||||||
|  * @return {Boolean} `true` is the HEAD of the current local branch is the same as the HEAD of the remote branch, falsy otherwise. |  * @return {Boolean} `true` is the HEAD of the current local branch is the same as the HEAD of the remote branch, falsy otherwise. | ||||||
|  */ |  */ | ||||||
| async function isBranchUpToDate(branch, execaOpts) { | async function isBranchUpToDate(repositoryUrl, branch, execaOpts) { | ||||||
|   const {stdout: remoteHead} = await execa('git', ['ls-remote', '--heads', 'origin', branch], execaOpts); |   const {stdout: remoteHead} = await execa('git', ['ls-remote', '--heads', repositoryUrl, branch], execaOpts); | ||||||
|   try { |   try { | ||||||
|     return await isRefInHistory(remoteHead.match(/^(\w+)?/)[1], execaOpts); |     return await isRefInHistory(remoteHead.match(/^(\w+)?/)[1], execaOpts); | ||||||
|   } catch (error) { |   } catch (error) { | ||||||
|  | |||||||
| @ -214,7 +214,7 @@ test('Return "true" if repository is up to date', async t => { | |||||||
|   await gitCommits(['First'], {cwd}); |   await gitCommits(['First'], {cwd}); | ||||||
|   await gitPush(repositoryUrl, 'master', {cwd}); |   await gitPush(repositoryUrl, 'master', {cwd}); | ||||||
| 
 | 
 | ||||||
|   t.true(await isBranchUpToDate('master', {cwd})); |   t.true(await isBranchUpToDate(repositoryUrl, 'master', {cwd})); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test('Return falsy if repository is not up to date', async t => { | test('Return falsy if repository is not up to date', async t => { | ||||||
| @ -223,13 +223,13 @@ test('Return falsy if repository is not up to date', async t => { | |||||||
|   await gitCommits(['Second'], {cwd}); |   await gitCommits(['Second'], {cwd}); | ||||||
|   await gitPush(repositoryUrl, 'master', {cwd}); |   await gitPush(repositoryUrl, 'master', {cwd}); | ||||||
| 
 | 
 | ||||||
|   t.true(await isBranchUpToDate('master', {cwd})); |   t.true(await isBranchUpToDate(repositoryUrl, 'master', {cwd})); | ||||||
| 
 | 
 | ||||||
|   const tmpRepo = await gitShallowClone(repositoryUrl); |   const tmpRepo = await gitShallowClone(repositoryUrl); | ||||||
|   await gitCommits(['Third'], {cwd: tmpRepo}); |   await gitCommits(['Third'], {cwd: tmpRepo}); | ||||||
|   await gitPush('origin', 'master', {cwd: tmpRepo}); |   await gitPush('origin', 'master', {cwd: tmpRepo}); | ||||||
| 
 | 
 | ||||||
|   t.falsy(await isBranchUpToDate('master', {cwd})); |   t.falsy(await isBranchUpToDate(repositoryUrl, 'master', {cwd})); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test('Return "true" if local repository is ahead', async t => { | test('Return "true" if local repository is ahead', async t => { | ||||||
| @ -238,5 +238,5 @@ test('Return "true" if local repository is ahead', async t => { | |||||||
|   await gitPush(repositoryUrl, 'master', {cwd}); |   await gitPush(repositoryUrl, 'master', {cwd}); | ||||||
|   await gitCommits(['Second'], {cwd}); |   await gitCommits(['Second'], {cwd}); | ||||||
| 
 | 
 | ||||||
|   t.true(await isBranchUpToDate('master', {cwd})); |   t.true(await isBranchUpToDate(repositoryUrl, 'master', {cwd})); | ||||||
| }); | }); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user