fix: fetch all tags even if the repo is not shallow
This commit is contained in:
		
							parent
							
								
									2d3a5e53e9
								
							
						
					
					
						commit
						45eee4acdd
					
				
							
								
								
									
										5
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								index.js
									
									
									
									
									
								
							| @ -13,7 +13,7 @@ const getLastRelease = require('./lib/get-last-release'); | |||||||
| const {extractErrors} = require('./lib/utils'); | const {extractErrors} = require('./lib/utils'); | ||||||
| const getGitAuthUrl = require('./lib/get-git-auth-url'); | const getGitAuthUrl = require('./lib/get-git-auth-url'); | ||||||
| const logger = require('./lib/logger'); | const logger = require('./lib/logger'); | ||||||
| const {unshallow, verifyAuth, isBranchUpToDate, gitHead: getGitHead, tag, push} = require('./lib/git'); | const {fetch, verifyAuth, isBranchUpToDate, gitHead: getGitHead, tag, push} = require('./lib/git'); | ||||||
| const getError = require('./lib/get-error'); | const getError = require('./lib/get-error'); | ||||||
| const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants'); | const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants'); | ||||||
| 
 | 
 | ||||||
| @ -75,8 +75,7 @@ async function run(options, plugins) { | |||||||
|   logger.log('Call plugin %s', 'verify-conditions'); |   logger.log('Call plugin %s', 'verify-conditions'); | ||||||
|   await plugins.verifyConditions({options, logger}, {settleAll: true}); |   await plugins.verifyConditions({options, logger}, {settleAll: true}); | ||||||
| 
 | 
 | ||||||
|   // Unshallow the repo in order to get all the tags
 |   await fetch(options.repositoryUrl); | ||||||
|   await unshallow(options.repositoryUrl); |  | ||||||
| 
 | 
 | ||||||
|   const lastRelease = await getLastRelease(options.tagFormat, logger); |   const lastRelease = await getLastRelease(options.tagFormat, logger); | ||||||
|   const commits = await getCommits(lastRelease.gitHead, options.branch, logger); |   const commits = await getCommits(lastRelease.gitHead, options.branch, logger); | ||||||
|  | |||||||
| @ -49,15 +49,15 @@ async function isRefInHistory(ref) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Unshallow the git repository (retriving every commits and tags). |  * Unshallow the git repository if necessary and fetch all the tags. | ||||||
|  * |  * | ||||||
|  * @param {String} repositoryUrl The remote repository URL. |  * @param {String} repositoryUrl The remote repository URL. | ||||||
|  */ |  */ | ||||||
| async function unshallow(repositoryUrl) { | async function fetch(repositoryUrl) { | ||||||
|   try { |   try { | ||||||
|     await execa('git', ['fetch', '--unshallow', '--tags', repositoryUrl]); |     await execa('git', ['fetch', '--unshallow', '--tags', repositoryUrl]); | ||||||
|   } catch (err) { |   } catch (err) { | ||||||
|     debug(err); |     await execa('git', ['fetch', '--tags', repositoryUrl]); | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -164,7 +164,7 @@ module.exports = { | |||||||
|   gitTagHead, |   gitTagHead, | ||||||
|   gitTags, |   gitTags, | ||||||
|   isRefInHistory, |   isRefInHistory, | ||||||
|   unshallow, |   fetch, | ||||||
|   gitHead, |   gitHead, | ||||||
|   repoUrl, |   repoUrl, | ||||||
|   isGitRepo, |   isGitRepo, | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ import tempy from 'tempy'; | |||||||
| import { | import { | ||||||
|   gitTagHead, |   gitTagHead, | ||||||
|   isRefInHistory, |   isRefInHistory, | ||||||
|   unshallow, |   fetch, | ||||||
|   gitHead, |   gitHead, | ||||||
|   repoUrl, |   repoUrl, | ||||||
|   tag, |   tag, | ||||||
| @ -24,6 +24,7 @@ import { | |||||||
|   gitCommitTag, |   gitCommitTag, | ||||||
|   gitRemoteTagHead, |   gitRemoteTagHead, | ||||||
|   gitPush, |   gitPush, | ||||||
|  |   gitDetachedHead, | ||||||
| } from './helpers/git-utils'; | } from './helpers/git-utils'; | ||||||
| 
 | 
 | ||||||
| // Save the current working diretory
 | // Save the current working diretory
 | ||||||
| @ -52,7 +53,7 @@ test.serial('Throw error if the last commit sha cannot be found', async t => { | |||||||
|   await t.throws(gitHead(), Error); |   await t.throws(gitHead(), Error); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Unshallow repository', async t => { | test.serial('Unshallow and fetch repository', async t => { | ||||||
|   // Create a git repository, set the current working directory at the root of the repo
 |   // Create a git repository, set the current working directory at the root of the repo
 | ||||||
|   const repo = await gitRepo(); |   const repo = await gitRepo(); | ||||||
|   // Add commits to the master branch
 |   // Add commits to the master branch
 | ||||||
| @ -63,7 +64,7 @@ test.serial('Unshallow repository', async t => { | |||||||
|   // Verify the shallow clone contains only one commit
 |   // Verify the shallow clone contains only one commit
 | ||||||
|   t.is((await gitGetCommits()).length, 1); |   t.is((await gitGetCommits()).length, 1); | ||||||
| 
 | 
 | ||||||
|   await unshallow(repo); |   await fetch(repo); | ||||||
| 
 | 
 | ||||||
|   // Verify the shallow clone contains all the commits
 |   // Verify the shallow clone contains all the commits
 | ||||||
|   t.is((await gitGetCommits()).length, 2); |   t.is((await gitGetCommits()).length, 2); | ||||||
| @ -74,7 +75,24 @@ test.serial('Do not throw error when unshallow a complete repository', async t = | |||||||
|   const repo = await gitRepo(); |   const repo = await gitRepo(); | ||||||
|   // Add commits to the master branch
 |   // Add commits to the master branch
 | ||||||
|   await gitCommits(['First']); |   await gitCommits(['First']); | ||||||
|   await t.notThrows(unshallow(repo)); |   await t.notThrows(fetch(repo)); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
|  | test.serial('Fetch all tags on a detached head repository', async t => { | ||||||
|  |   const repo = await gitRepo(true); | ||||||
|  | 
 | ||||||
|  |   await gitCommits(['First']); | ||||||
|  |   await gitTagVersion('v1.0.0'); | ||||||
|  |   await gitCommits(['Second']); | ||||||
|  |   await gitTagVersion('v1.0.1'); | ||||||
|  |   const [commit] = await gitCommits(['Third']); | ||||||
|  |   await gitTagVersion('v1.1.0'); | ||||||
|  |   await gitPush(); | ||||||
|  |   await gitDetachedHead(repo, commit.hash); | ||||||
|  | 
 | ||||||
|  |   await fetch(repo); | ||||||
|  | 
 | ||||||
|  |   t.deepEqual((await gitTags()).sort(), ['v1.0.0', 'v1.0.1', 'v1.1.0'].sort()); | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| test.serial('Verify if the commit `sha` is in the direct history of the current branch', async t => { | test.serial('Verify if the commit `sha` is in the direct history of the current branch', async t => { | ||||||
|  | |||||||
| @ -151,7 +151,7 @@ export async function gitDetachedHead(repositoryUrl, head) { | |||||||
|   process.chdir(dir); |   process.chdir(dir); | ||||||
|   await execa('git', ['init']); |   await execa('git', ['init']); | ||||||
|   await execa('git', ['remote', 'add', 'origin', repositoryUrl]); |   await execa('git', ['remote', 'add', 'origin', repositoryUrl]); | ||||||
|   await execa('git', ['fetch']); |   await execa('git', ['fetch', repositoryUrl]); | ||||||
|   await execa('git', ['checkout', head]); |   await execa('git', ['checkout', head]); | ||||||
|   return dir; |   return dir; | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user