8
0
Просмотр исходного кода

Added fetching of branches from main repository during update task.

Oskar Wrobel 9 лет назад
Родитель
Сommit
273d6e4f0c
4 измененных файлов с 45 добавлено и 6 удалено
  1. 7 0
      dev/tasks/dev/tasks/update.js
  2. 17 4
      dev/tasks/dev/utils/git.js
  3. 0 1
      dev/tests/dev/git.js
  4. 21 1
      dev/tests/dev/update.js

+ 7 - 0
dev/tasks/dev/tasks/update.js

@@ -31,6 +31,10 @@ const log = require( '../utils/log' );
 module.exports = ( installTask, ckeditor5Path, packageJSON, workspaceRoot, runNpmUpdate ) => {
 	const workspaceAbsolutePath = path.join( ckeditor5Path, workspaceRoot );
 
+	// Fetch main repository
+	log.out( `Fetching branches from ${ packageJSON.name }...` );
+	git.fetchAll( ckeditor5Path );
+
 	// Get all CKEditor dependencies from package.json.
 	const dependencies = tools.getCKEditorDependencies( packageJSON.dependencies );
 
@@ -47,6 +51,9 @@ module.exports = ( installTask, ckeditor5Path, packageJSON, workspaceRoot, runNp
 				log.out( `Checking out ${ urlInfo.name } to ${ urlInfo.branch }...` );
 				git.checkout( repositoryAbsolutePath, urlInfo.branch );
 
+				log.out( `Fetching branches from ${ urlInfo.name }...` );
+				git.fetchAll( repositoryAbsolutePath );
+
 				log.out( `Pulling changes to ${ urlInfo.name }...` );
 				git.pull( repositoryAbsolutePath, urlInfo.branch );
 

+ 17 - 4
dev/tasks/dev/utils/git.js

@@ -66,19 +66,18 @@ module.exports = {
 	},
 
 	/**
-	 * Fetches all remotes and checks out branch on selected repository.
+	 * Checks out branch on selected repository.
 	 *
 	 * @param {String} repositoryLocation Absolute path to repository.
 	 * @param {String} branchName Name of the branch to checkout.
 	 */
 	checkout( repositoryLocation, branchName ) {
-		const checkoutCommands = [
+		const checkoutCommand = [
 			`cd ${ repositoryLocation }`,
-			`git fetch --all`,
 			`git checkout ${ branchName }`
 		];
 
-		tools.shExec( checkoutCommands.join( ' && ' ) );
+		tools.shExec( checkoutCommand.join( ' && ' ) );
 	},
 
 	/**
@@ -96,6 +95,20 @@ module.exports = {
 		tools.shExec( pullCommands.join( ' && ' ) );
 	},
 
+	/**
+	 * Fetch all branches from each origin on selected repository.
+	 *
+	 * @param {String} repositoryLocation
+     */
+	fetchAll( repositoryLocation ) {
+		const fetchCommands = [
+			`cd ${ repositoryLocation }`,
+			`git fetch --all`
+		];
+
+		tools.shExec( fetchCommands.join( ' && ' ) );
+	},
+
 	/**
 	 * Initializes new repository, adds and merges CKEditor5 boilerplate project.
 	 *

+ 0 - 1
dev/tests/dev/git.js

@@ -151,7 +151,6 @@ describe( 'utils', () => {
 				const branchName = 'branch-to-checkout';
 				const checkoutCommands = [
 					`cd ${ repositoryLocation }`,
-					`git fetch --all`,
 					`git checkout ${ branchName }`
 				].join( ' && ' );
 

+ 21 - 1
dev/tests/dev/update.js

@@ -23,6 +23,7 @@ describe( 'dev-update', () => {
 		spies.getDependencies = sinon.spy( tools, 'getCKEditorDependencies' );
 		spies.checkout = sinon.stub( git, 'checkout' );
 		spies.pull = sinon.stub( git, 'pull' );
+		spies.fetchAll = sinon.stub( git, 'fetchAll' );
 		spies.npmUpdate = sinon.stub( tools, 'npmUpdate' );
 		spies.linkDirectories = sinon.stub( tools, 'linkDirectories' );
 		spies.removeSymlink = sinon.stub( tools, 'removeSymlink' );
@@ -57,6 +58,10 @@ describe( 'dev-update', () => {
 		sinon.assert.calledTwice( spies.pull );
 		sinon.assert.calledWithExactly( spies.pull.firstCall, repoPath1, 'master' );
 		sinon.assert.calledWithExactly( spies.pull.secondCall, repoPath2, 'new-branch' );
+		sinon.assert.calledThrice( spies.fetchAll );
+		sinon.assert.calledWithExactly( spies.fetchAll.firstCall, ckeditor5Path );
+		sinon.assert.calledWithExactly( spies.fetchAll.secondCall, repoPath1 );
+		sinon.assert.calledWithExactly( spies.fetchAll.thirdCall, repoPath2 );
 
 		sinon.assert.calledThrice( spies.npmUpdate );
 		sinon.assert.calledWithExactly( spies.npmUpdate.firstCall, path.join( workspaceAbsolutePath, dirs[ 0 ] ) );
@@ -94,6 +99,10 @@ describe( 'dev-update', () => {
 		sinon.assert.calledTwice( spies.pull );
 		sinon.assert.calledWithExactly( spies.pull.firstCall, repoPath1, 'master' );
 		sinon.assert.calledWithExactly( spies.pull.secondCall, repoPath2, 'new-branch' );
+		sinon.assert.calledThrice( spies.fetchAll );
+		sinon.assert.calledWithExactly( spies.fetchAll.firstCall, ckeditor5Path );
+		sinon.assert.calledWithExactly( spies.fetchAll.secondCall, repoPath1 );
+		sinon.assert.calledWithExactly( spies.fetchAll.thirdCall, repoPath2 );
 
 		sinon.assert.calledThrice( spies.npmUpdate );
 		sinon.assert.calledWithExactly( spies.npmUpdate.firstCall, path.join( workspaceAbsolutePath, dirs[ 0 ] ) );
@@ -132,6 +141,10 @@ describe( 'dev-update', () => {
 		sinon.assert.calledTwice( spies.pull );
 		sinon.assert.calledWithExactly( spies.pull.firstCall, repoPath1, 'master' );
 		sinon.assert.calledWithExactly( spies.pull.secondCall, repoPath2, 'new-branch' );
+		sinon.assert.calledThrice( spies.fetchAll );
+		sinon.assert.calledWithExactly( spies.fetchAll.firstCall, ckeditor5Path );
+		sinon.assert.calledWithExactly( spies.fetchAll.secondCall, repoPath1 );
+		sinon.assert.calledWithExactly( spies.fetchAll.thirdCall, repoPath2 );
 
 		sinon.assert.calledThrice( spies.npmUpdate );
 		sinon.assert.calledWithExactly( spies.npmUpdate.firstCall, path.join( workspaceAbsolutePath, dirs[ 0 ] ) );
@@ -176,6 +189,10 @@ describe( 'dev-update', () => {
 		sinon.assert.calledTwice( spies.pull );
 		sinon.assert.calledWithExactly( spies.pull.firstCall, repoPath1, 'master' );
 		sinon.assert.calledWithExactly( spies.pull.secondCall, repoPath2, 'new-branch' );
+		sinon.assert.calledThrice( spies.fetchAll );
+		sinon.assert.calledWithExactly( spies.fetchAll.firstCall, ckeditor5Path );
+		sinon.assert.calledWithExactly( spies.fetchAll.secondCall, repoPath1 );
+		sinon.assert.calledWithExactly( spies.fetchAll.thirdCall, repoPath2 );
 
 		sinon.assert.notCalled( spies.npmUpdate );
 
@@ -187,7 +204,7 @@ describe( 'dev-update', () => {
 		sinon.assert.calledTwice( errSpy );
 	} );
 
-	it( 'should skip updating if no dependencies found', () => {
+	it( 'should skip updating if no dependencies found and fetch only main repository', () => {
 		spies.getDependencies.restore();
 		spies.getDependencies = sinon.stub( tools, 'getCKEditorDependencies' ).returns( null );
 		const dirs = [ 'ckeditor5-core', 'ckeditor5-devtest' ];
@@ -205,6 +222,9 @@ describe( 'dev-update', () => {
 
 		updateTask( installTask, ckeditor5Path, json, workspaceRoot, false );
 
+		sinon.assert.calledOnce( spies.fetchAll );
+		sinon.assert.calledWithExactly( spies.fetchAll.firstCall, ckeditor5Path );
+
 		sinon.assert.notCalled( spies.checkout );
 		sinon.assert.notCalled( spies.pull );