Skip to content

Commit

Permalink
Merge pull request #301 from chromaui/strip-branch-prefix
Browse files Browse the repository at this point in the history
Strip `origin/*` prefix from branch name
  • Loading branch information
ghengeveld committed Mar 11, 2021
2 parents 95ec671 + c09eeec commit 4fb5adc
Showing 1 changed file with 7 additions and 0 deletions.
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

0 comments on commit 4fb5adc

Please sign in to comment.