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

New way of checking if boilerplate repository is present.

Szymon Kupś 10 лет назад
Родитель
Сommit
f57077fd67
2 измененных файлов с 25 добавлено и 5 удалено
  1. 21 3
      dev/tasks/tests/git.js
  2. 4 2
      dev/tasks/utils/git.js

+ 21 - 3
dev/tasks/tests/git.js

@@ -178,23 +178,41 @@ describe( 'utils', () => {
 
 		describe( 'updateBoilerplate', () => {
 			it( 'should be defined', () => expect( git.updateBoilerplate ).to.be.a( 'function' ) );
-			it( 'should call update boilerplate commands', () => {
+			it( 'should fetch and merge boilerplate if remote already exists', () => {
 				const shExecStub = sinon.stub( tools, 'shExec' );
 				const repositoryLocation = 'path/to/repository';
-				const addRemoteCommands = `cd ${ repositoryLocation } && git remote add boilerplate ${ git.BOILERPLATE_REPOSITORY }`;
 				const updateCommands = [
 					`cd ${ repositoryLocation }`,
 					`git fetch boilerplate ${ git.BOILERPLATE_BRANCH }`,
 					`git merge boilerplate/${ git.BOILERPLATE_BRANCH }`
 				];
+				shExecStub.onCall( 0 ).returns( 'origin\nboilerplate' );
 				toRestore.push( shExecStub );
 
 				git.updateBoilerplate( repositoryLocation );
 
 				expect( shExecStub.calledTwice ).to.equal( true );
-				expect( shExecStub.firstCall.args[ 0 ] ).to.equal( addRemoteCommands );
 				expect( shExecStub.secondCall.args[ 0 ] ).to.equal( updateCommands.join( ' && ' ) );
 			} );
+
+			it( 'should add boilerplate remote if one not exists', () => {
+				const shExecStub = sinon.stub( tools, 'shExec' );
+				const repositoryLocation = 'path/to/repository';
+				const addRemoteCommands = `cd ${ repositoryLocation } && git remote add boilerplate ${ git.BOILERPLATE_REPOSITORY }`;
+				const updateCommands = [
+					`cd ${ repositoryLocation }`,
+					`git fetch boilerplate ${ git.BOILERPLATE_BRANCH }`,
+					`git merge boilerplate/${ git.BOILERPLATE_BRANCH }`
+				];
+				shExecStub.onCall( 0 ).returns( 'origin\nnew' );
+				toRestore.push( shExecStub );
+
+				git.updateBoilerplate( repositoryLocation );
+
+				expect( shExecStub.calledThrice ).to.equal( true );
+				expect( shExecStub.secondCall.args[ 0 ] ).to.equal( addRemoteCommands );
+				expect( shExecStub.thirdCall.args[ 0 ] ).to.equal( updateCommands.join( ' && ' )  );
+			} );
 		} );
 	} );
 } );

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

@@ -138,10 +138,12 @@ module.exports = {
 	 * @param {String} repositoryPath Absolute path to repository.
 	 */
 	updateBoilerplate( repositoryPath ) {
+		const regexp = /boilerplate(\n|$)/;
+
 		// Try to add boilerplate remote if one is not already added.
-		try {
+		if ( !regexp.test( tools.shExec( `cd ${ repositoryPath } && git remote` ) ) ) {
 			tools.shExec( `cd ${ repositoryPath } && git remote add boilerplate ${ this.BOILERPLATE_REPOSITORY }` );
-		} catch ( error ) { }
+		}
 
 		const updateCommands = [
 			`cd ${ repositoryPath }`,