浏览代码

Merge pull request #158 from ckeditor/t/153

Added fetching of branches from main repository during update task.
Szymon Kupś 9 年之前
父节点
当前提交
2596ddebaa
共有 4 个文件被更改,包括 73 次插入13 次删除
  1. 18 9
      dev/tasks/dev/tasks/update.js
  2. 15 2
      dev/tasks/dev/utils/git.js
  3. 19 1
      dev/tests/dev/git.js
  4. 21 1
      dev/tests/dev/update.js

+ 18 - 9
dev/tasks/dev/tasks/update.js

@@ -11,15 +11,17 @@ const path = require( 'path' );
 const log = require( '../utils/log' );
 
 /**
- * 1. Get CKEditor 5 dependencies from package.json in main CKEditor 5 repository.
- * 2. If dependency's repository is already cloned in workspace:
- *		2.1. Fetch and checkout to specified branch.
- *		2.2. Pull changes to that branch.
- *		2.3. if --npm-update was specified run npm update --dev in that repository.
- *		2.4. Recreate symbolic link between repo and main node_modules.
- * 3. If dependency's repository is not cloned yet - run gulp install on this dependency.
- * 4. Remove symbolic links to dependencies that are not used in current package.json configuration.
- * 5. if --npm-update was specified run npm update --dev in main CKeditor 5 repository.
+ * 1. Fetch all branches from each origin in main CKEditor 5 repository.
+ * 2. Get CKEditor 5 dependencies from package.json in main CKEditor 5 repository.
+ * 3. If dependency's repository is already cloned in workspace:
+ *		3.1. Fetch all branches from each origin.
+ *		3.2. Checkout to specified branch.
+ *		3.3. Pull changes to that branch.
+ *		3.4. if --npm-update was specified run npm update --dev in that repository.
+ *		3.5. Recreate symbolic link between repo and main node_modules.
+ * 4. If dependency's repository is not cloned yet - run gulp install on this dependency.
+ * 5. Remove symbolic links to dependencies that are not used in current package.json configuration.
+ * 6. if --npm-update was specified run npm update --dev in main CKEditor 5 repository.
  *
  * @param {Function} installTask Install task to use on each dependency that is missing from workspace.
  * @param {String} ckeditor5Path Path to main CKEditor5 repository.
@@ -31,6 +33,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 );
 
@@ -44,6 +50,9 @@ module.exports = ( installTask, ckeditor5Path, packageJSON, workspaceRoot, runNp
 
 			// Check if repository's directory already exists.
 			if ( directories.indexOf( urlInfo.name ) > -1 ) {
+				log.out( `Fetching branches from ${ urlInfo.name }...` );
+				git.fetchAll( repositoryAbsolutePath );
+
 				log.out( `Checking out ${ urlInfo.name } to ${ urlInfo.branch }...` );
 				git.checkout( repositoryAbsolutePath, urlInfo.branch );
 

+ 15 - 2
dev/tasks/dev/utils/git.js

@@ -66,7 +66,7 @@ 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.
@@ -74,7 +74,6 @@ module.exports = {
 	checkout( repositoryLocation, branchName ) {
 		const checkoutCommands = [
 			`cd ${ repositoryLocation }`,
-			`git fetch --all`,
 			`git checkout ${ branchName }`
 		];
 
@@ -97,6 +96,20 @@ module.exports = {
 	},
 
 	/**
+	 * 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.
 	 *
 	 * @param {String} repositoryPath Absolute path where repository should be created.

+ 19 - 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( ' && ' );
 
@@ -164,6 +163,7 @@ describe( 'utils', () => {
 
 		describe( 'pull', () => {
 			it( 'should be defined', () => expect( git.pull ).to.be.a( 'function' ) );
+
 			it( 'should call pull commands', () => {
 				const shExecStub = sandbox.stub( tools, 'shExec' );
 				const repositoryLocation = 'path/to/repository';
@@ -177,8 +177,24 @@ describe( 'utils', () => {
 			} );
 		} );
 
+		describe( 'fetchAll', () => {
+			it( 'should be defined', () => expect( git.fetchAll ).to.be.a( 'function' ) );
+
+			it( 'should call fetch commands', () => {
+				const shExecStub = sandbox.stub( tools, 'shExec' );
+				const repositoryLocation = 'path/to/repository';
+				const fetchCommands = `cd ${ repositoryLocation } && git fetch --all`;
+
+				git.fetchAll( repositoryLocation );
+
+				expect( shExecStub.calledOnce ).to.be.equal( true );
+				expect( shExecStub.firstCall.args[ 0 ] ).to.be.equal( fetchCommands );
+			} );
+		} );
+
 		describe( 'initializeRepository', () => {
 			it( 'should be defined', () => expect( git.initializeRepository ).to.be.a( 'function' ) );
+
 			it( 'should call initialize commands', () => {
 				const shExecStub = sandbox.stub( tools, 'shExec' );
 				const repositoryLocation = 'path/to/repository';
@@ -195,6 +211,7 @@ describe( 'utils', () => {
 
 		describe( 'getStatus', () => {
 			it( 'should be defined', () => expect( git.getStatus ).to.be.a( 'function' ) );
+
 			it( 'should call status command', () => {
 				const shExecStub = sandbox.stub( tools, 'shExec' );
 				const repositoryLocation = 'path/to/repository';
@@ -209,6 +226,7 @@ describe( 'utils', () => {
 
 		describe( 'initialCommit', () => {
 			it( 'should be defined', () => expect( git.initialCommit ).to.be.a( 'function' ) );
+
 			it( 'should execute commit commands', () => {
 				const shExecStub = sandbox.stub( tools, 'shExec' );
 				const pluginName = 'ckeditor5-plugin-name';

+ 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' );
@@ -51,6 +52,10 @@ describe( 'dev-update', () => {
 		const repoPath1 = path.join( workspaceAbsolutePath, dirs[ 0 ] );
 		const repoPath2 = path.join( workspaceAbsolutePath, dirs[ 1 ] );
 
+		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.calledTwice( spies.checkout );
 		sinon.assert.calledWithExactly( spies.checkout.firstCall, repoPath1, 'master' );
 		sinon.assert.calledWithExactly( spies.checkout.secondCall, repoPath2, 'new-branch' );
@@ -88,6 +93,10 @@ describe( 'dev-update', () => {
 		const repoPath1 = path.join( workspaceAbsolutePath, dirs[ 0 ] );
 		const repoPath2 = path.join( workspaceAbsolutePath, dirs[ 1 ] );
 
+		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.calledTwice( spies.checkout );
 		sinon.assert.calledWithExactly( spies.checkout.firstCall, repoPath1, 'master' );
 		sinon.assert.calledWithExactly( spies.checkout.secondCall, repoPath2, 'new-branch' );
@@ -126,6 +135,10 @@ describe( 'dev-update', () => {
 		const repoPath1 = path.join( workspaceAbsolutePath, dirs[ 0 ] );
 		const repoPath2 = path.join( workspaceAbsolutePath, dirs[ 1 ] );
 
+		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.calledTwice( spies.checkout );
 		sinon.assert.calledWithExactly( spies.checkout.firstCall, repoPath1, 'master' );
 		sinon.assert.calledWithExactly( spies.checkout.secondCall, repoPath2, 'new-branch' );
@@ -170,6 +183,10 @@ describe( 'dev-update', () => {
 		const repoPath1 = path.join( workspaceAbsolutePath, dirs[ 0 ] );
 		const repoPath2 = path.join( workspaceAbsolutePath, dirs[ 1 ] );
 
+		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.calledTwice( spies.checkout );
 		sinon.assert.calledWithExactly( spies.checkout.firstCall, repoPath1, 'master' );
 		sinon.assert.calledWithExactly( spies.checkout.secondCall, repoPath2, 'new-branch' );
@@ -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 );