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

Strip origin/* prefix from branch name #301

Merged
merged 4 commits into from Mar 11, 2021
Merged
Changes from 2 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
7 changes: 7 additions & 0 deletions bin/git/getCommitAndBranch.js
Expand Up @@ -6,6 +6,7 @@ import missingTravisInfo from '../ui/messages/errors/missingTravisInfo';
import travisInternalBuild from '../ui/messages/warnings/travisInternalBuild';
import { getBranch, getCommit, hasPreviousCommit } from './git';

const ORIGIN_PREFIX_REGEXP = /^origin\//;
const notHead = (branch) => (branch && branch !== 'HEAD' ? branch : false);

export async function getCommitAndBranch({ branchName, patchBaseRef, ci, log } = {}) {
Expand Down Expand Up @@ -85,6 +86,12 @@ export async function getCommitAndBranch({ branchName, patchBaseRef, ci, log } =
!!process.env.REPOSITORY_URL || // https://www.netlify.com/docs/continuous-deployment/
!!process.env.GITHUB_REPOSITORY;

// Strip off any `origin/` prefix that's added sometimes.
if (!branchName && !isFromEnvVariable && ORIGIN_PREFIX_REGEXP.test(branch)) {
log.warn(`Ignoring 'origin/' prefix in branch name.`);
branch = branch.replace(ORIGIN_PREFIX_REGEXP, '');
}

log.debug(
`git info: ${JSON.stringify({
commit,
Expand Down