Explorar el Código

Added git pull command when initializing repository.

Szymon Kupś hace 10 años
padre
commit
697ffca563
Se han modificado 2 ficheros con 28 adiciones y 24 borrados
  1. 17 13
      dev/tasks/tests/dev-init.js
  2. 11 11
      dev/tasks/utils/dev-init.js

+ 17 - 13
dev/tasks/tests/dev-init.js

@@ -27,6 +27,20 @@ describe( 'dev-tasks', () => {
 		beforeEach( () => createSpies() );
 		afterEach( () => restoreSpies() );
 
+		function createSpies() {
+			spies = {
+				getDependencies: sinon.spy( tools, 'getCKEditorDependencies' ),
+				getDirectories: sinon.stub( tools, 'getCKE5Directories', () => [] ),
+				parseRepositoryUrl: sinon.spy( git, 'parseRepositoryUrl' ),
+				cloneRepository: sinon.stub( git, 'cloneRepository' ),
+				linkDirectories: sinon.stub( tools, 'linkDirectories' ),
+				pull: sinon.stub( git, 'pull' ),
+				checkout: sinon.stub( git, 'checkout' ),
+				npmInstall: sinon.stub( tools, 'npmInstall' ),
+				installGitHooks: sinon.stub( tools, 'installGitHooks' )
+			};
+		}
+
 		function restoreSpies() {
 			for ( let spy in spies ) {
 				spies[ spy ].restore();
@@ -49,6 +63,7 @@ describe( 'dev-tasks', () => {
 			expect( spies.parseRepositoryUrl.called ).to.equal( false );
 			expect( spies.cloneRepository.called ).to.equal( false );
 			expect( spies.checkout.called ).to.equal( false );
+			expect( spies.pull.called ).to.equal( false );
 			expect( spies.npmInstall.called ).to.equal( false );
 			expect( spies.installGitHooks.called ).to.equal( false );
 		} );
@@ -74,6 +89,7 @@ describe( 'dev-tasks', () => {
 			expect( spies.cloneRepository.secondCall.args[ 0 ] ).to.equal( spies.parseRepositoryUrl.secondCall.returnValue );
 			expect( spies.cloneRepository.secondCall.args[ 1 ] ).to.equal( workspacePath );
 			expect( spies.checkout.calledTwice ).to.equal( true );
+			expect( spies.pull.calledTwice ).to.equal( true );
 			expect( spies.linkDirectories.calledTwice ).to.equal( true );
 			expect( spies.npmInstall.calledTwice ).to.equal( true );
 			expect( spies.installGitHooks.calledTwice ).to.equal( true );
@@ -99,22 +115,10 @@ describe( 'dev-tasks', () => {
 			expect( spies.parseRepositoryUrl.calledTwice ).to.equal( true );
 			expect( spies.cloneRepository.called ).to.equal( false );
 			expect( spies.checkout.calledTwice ).to.equal( true );
+			expect( spies.pull.calledTwice ).to.equal( true );
 			expect( spies.linkDirectories.calledTwice ).to.equal( true );
 			expect( spies.npmInstall.calledTwice ).to.equal( true );
 			expect( spies.installGitHooks.calledTwice ).to.equal( true );
 		} );
 	} );
-
-	function createSpies() {
-		spies = {
-			getDependencies: sinon.spy( tools, 'getCKEditorDependencies' ),
-			getDirectories: sinon.stub( tools, 'getCKE5Directories', () => [] ),
-			parseRepositoryUrl: sinon.spy( git, 'parseRepositoryUrl' ),
-			cloneRepository: sinon.stub( git, 'cloneRepository' ),
-			linkDirectories: sinon.stub( tools, 'linkDirectories' ),
-			checkout: sinon.stub( git, 'checkout' ),
-			npmInstall: sinon.stub( tools, 'npmInstall' ),
-			installGitHooks: sinon.stub( tools, 'installGitHooks' )
-		};
-	}
 } );

+ 11 - 11
dev/tasks/utils/dev-init.js

@@ -14,9 +14,10 @@ const path = require( 'path' );
  * 2. Check if any of the repositories are already present in the workspace.
  * 		2.1. If repository is present in the workspace, check it out to desired branch if one is provided.
  * 		2.2. If repository is not present in the workspace, clone it and checkout to desired branch if one is provided.
- * 3. Link each new repository to node_modules. (do not use npm link, use standard linking instead)
- * 4. Run `npm install` in each repository.
- * 5. Install Git hooks in each repository.
+ * 3. Pull changes from remote branch.
+ * 4. Link each new repository to node_modules. (do not use npm link, use standard linking instead)
+ * 5. Run `npm install` in each repository.
+ * 6. Install Git hooks in each repository.
  *
  * @param {String} ckeditor5Path Path to main CKEditor5 repository.
  * @param {Object} packageJSON Parsed package.json file from CKEditor5 repository.
@@ -39,27 +40,26 @@ module.exports = ( ckeditor5Path, packageJSON, options, writeln, writeError ) =>
 			const repositoryAbsolutePath = path.join( workspaceAbsolutePath, dependency );
 
 			// Check if repository's directory already exists.
-			if ( directories.indexOf( dependency ) === -1 ) {
-				try {
+			try {
+				if ( directories.indexOf( dependency ) === -1 ) {
 					writeln( `Clonning ${ repositoryURL }...` );
 					git.cloneRepository( urlInfo, workspaceAbsolutePath );
-				} catch ( error ) {
-					writeError( error );
 				}
-			}
 
-			// Check out proper branch.
-			try {
+				// Check out proper branch.
 				writeln( `Checking out ${ repositoryURL } to ${ urlInfo.branch }...` );
 				git.checkout( repositoryAbsolutePath, urlInfo.branch );
 
+				writeln( `Pulling changes to ${ repositoryURL } ${ urlInfo.branch }...` );
+				git.pull( repositoryAbsolutePath, urlInfo.branch );
+
 				writeln( `Linking ${ repositoryURL }...` );
 				tools.linkDirectories( repositoryAbsolutePath, path.join( ckeditor5Path, 'node_modules' , dependency ) );
 
 				writeln( `Running npm install in ${ repositoryURL }.` );
 				tools.npmInstall( repositoryAbsolutePath );
 
-				writeln( `Installing GIT hooks in ${ repositoryURL }.` );
+				writeln( `Installing Git hooks in ${ repositoryURL }.` );
 				tools.installGitHooks( repositoryAbsolutePath );
 			} catch ( error ) {
 				writeError( error );