Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More fixes for git baseline selection in pr-check #20216

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 33 additions & 23 deletions build-system/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,55 +24,45 @@ const {getStdout} = require('./exec');

const commitLogMaxCount = 100;

/**
* Returns the merge base of the current branch off of master when running on
* a local workspace.
* @return {string}
*/
exports.gitMergeBaseLocalMaster = function() {
return getStdout('git merge-base master HEAD').trim();
};

/**
* Returns the merge base of the current branch off of master, regardless of
* the running environment.
* @return {string}
*/
exports.gitMergeBaseMaster = function() {
if (process.env.TRAVIS) {
const commitRange = process.env.TRAVIS_COMMIT_RANGE.split('...');
return getStdout(`git merge-base ${commitRange[0]} ${commitRange[1]}`)
.trim();
return getStdout(
`git merge-base master ${process.env.TRAVIS_PULL_REQUEST_SHA}`).trim();
danielrozenberg marked this conversation as resolved.
Show resolved Hide resolved
}
return exports.gitMergeBaseLocalMaster();
return gitMergeBaseLocalMaster();
};

/**
* Returns the `master` parent of the merge commit (current HEAD) on Travis.
* @return {string}
*/
exports.gitTravisMasterBaseline = function() {
return process.env.TRAVIS_COMMIT_RANGE.split('...')[0];
return getStdout('git rev-parse origin/master').trim();
danielrozenberg marked this conversation as resolved.
Show resolved Hide resolved
};

/**
* Returns the list of files changed on the local branch relative to the branch
* point off of master, one on each line.
* Returns the list of files changed relative to the branch point off of master,
* one on each line.
* @return {!Array<string>}
*/
exports.gitDiffNameOnlyMaster = function() {
const branchPoint = exports.gitMergeBaseLocalMaster();
return getStdout(`git diff --name-only ${branchPoint}`).trim().split('\n');
const masterBaseline = gitMasterBaseline();
danielrozenberg marked this conversation as resolved.
Show resolved Hide resolved
return getStdout(`git diff --name-only ${masterBaseline}`).trim().split('\n');
};

/**
* Returns the list of files changed on the local branch relative to the branch
* point off of master, in diffstat format.
* Returns the list of files changed relative to the branch point off of master,
* in diffstat format.
* @return {string}
*/
exports.gitDiffStatMaster = function() {
const branchPoint = exports.gitMergeBaseLocalMaster();
return getStdout(`git -c color.ui=always diff --stat ${branchPoint}`);
const masterBaseline = gitMasterBaseline();
danielrozenberg marked this conversation as resolved.
Show resolved Hide resolved
return getStdout(`git -c color.ui=always diff --stat ${masterBaseline}`);
};

/**
Expand Down Expand Up @@ -107,7 +97,7 @@ for how to fix this.`;
* @return {!Array<string>}
*/
exports.gitDiffAddedNameOnlyMaster = function() {
const branchPoint = exports.gitMergeBaseLocalMaster();
const branchPoint = gitMergeBaseLocalMaster();
danielrozenberg marked this conversation as resolved.
Show resolved Hide resolved
return getStdout(`git diff --name-only --diff-filter=ARC ${branchPoint}`)
.trim().split('\n');
};
Expand Down Expand Up @@ -168,3 +158,23 @@ exports.gitCommitFormattedTime = function() {
exports.gitStatusPorcelain = function() {
return getStdout('git status --porcelain').trim();
};

/**
* Returns the merge base of the current branch off of master when running on
* a local workspace.
* @return {string}
*/
function gitMergeBaseLocalMaster() {
return getStdout('git merge-base master HEAD').trim();
}
danielrozenberg marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns the master baseline commit, regardless of running environment.
* @return {string}
*/
function gitMasterBaseline() {
if (process.env.TRAVIS) {
return exports.gitTravisMasterBaseline();
}
return gitMergeBaseLocalMaster();
}
8 changes: 8 additions & 0 deletions build-system/pr-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const {
gitDiffNameOnlyMaster,
gitDiffStatMaster,
gitMergeBaseMaster,
gitTravisMasterBaseline,
} = require('./git');
const {execOrDie, exec, getStderr, getStdout} = require('./exec');

Expand Down Expand Up @@ -97,6 +98,13 @@ function timedExecOrDie(cmd) {
* Prints a summary of files changed by, and commits included in the PR.
*/
function printChangeSummary() {
if (process.env.TRAVIS) {
console.log('Travis', colors.green('origin/master'), 'baseline:',
colors.cyan(gitTravisMasterBaseline()));
}
danielrozenberg marked this conversation as resolved.
Show resolved Hide resolved
console.log(colors.green('master'), 'merge-base:',
colors.cyan(gitMergeBaseMaster()));
danielrozenberg marked this conversation as resolved.
Show resolved Hide resolved

const filesChanged = gitDiffStatMaster();
console.log(fileLogPrefix,
'Testing the following changes at commit',
Expand Down