Skip to content

Commit

Permalink
Fix #1935 checkout against custom branch (#1998)
Browse files Browse the repository at this point in the history
* Fix checkoutTargetBranch

* Refactor checkoutTargetBranch function
  • Loading branch information
Vlad Barosan authored Nov 11, 2017
1 parent 749c56e commit 1a54c04
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions test/util/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ exports.parseJsonFromFile = async function parseJsonFromFile(filepath) {
};

/**
* Gets the name of the target branch to which the PR is sent. We are using the environment
* Gets the name of the target branch to which the PR is sent. We are using the environment
* variable provided by travis-ci. It is called TRAVIS_BRANCH. More info can be found here:
* https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
* If the environment variable is undefined then the method returns 'master' as the default value.
Expand All @@ -78,15 +78,20 @@ exports.getTargetBranch = function getTargetBranch() {
*/
exports.checkoutTargetBranch = function checkoutTargetBranch() {
let targetBranch = exports.getTargetBranch();
let cmds = [`git remote -vv`, `git branch --all`,
`git remote set-branches origin --add ${targetBranch}`,
`git fetch origin ${targetBranch}`,
`git diff`,
`git stash`,
`git checkout ${targetBranch}`,
`git log -3`];

console.log(`Changing the branch to ${targetBranch}...`);
execSync(`git remote -vv`, { encoding: 'utf8' });
execSync(`git branch --all`, { encoding: 'utf8' });
execSync(`git fetch origin ${targetBranch}`, { encoding: 'utf8' });
execSync(`git diff`, { encoding: 'utf8' });
execSync(`git stash`, { encoding: 'utf8' });
execSync(`git checkout ${targetBranch}`, { encoding: 'utf8' });
execSync(`git log -3`, { encoding: 'utf8' });
for(let cmd of cmds)
{
console.log(cmd);
execSync(cmd, { encoding: 'utf8', stdio: 'inherit' });
}
}

/**
Expand All @@ -110,7 +115,7 @@ exports.getSourceBranch = function getSourceBranch() {
};

/**
* Gets the PR number. We are using the environment
* Gets the PR number. We are using the environment
* variable provided by travis-ci. It is called TRAVIS_PULL_REQUEST. More info can be found here:
* https://docs.travis-ci.com/user/environment-variables/#Convenience-Variables
* @returns {string} PR number or 'undefined'.
Expand All @@ -127,7 +132,7 @@ exports.getPullRequestNumber = function getPullRequestNumber() {
};

/**
* Gets the Repo name. We are using the environment
* Gets the Repo name. We are using the environment
* variable provided by travis-ci. It is called TRAVIS_REPO_SLUG. More info can be found here:
* https://docs.travis-ci.com/user/environment-variables/#Convenience-Variables
* @returns {string} PR number or 'undefined'.
Expand Down Expand Up @@ -232,7 +237,7 @@ exports.getFilesChangedInPR = function getFilesChangedInPR() {
return true;
});
console.log(`>>>> Number of swaggers found in this PR: ${swaggerFilesInPR.length}`);

var deletedFiles = swaggerFilesInPR.filter(function(swaggerFile){
return !fs.existsSync(swaggerFile);
});
Expand Down

0 comments on commit 1a54c04

Please sign in to comment.