From 44aa1f273d07d7c2f0e24e5246e9cef81169867a Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Tue, 9 Mar 2021 16:09:25 +0100 Subject: [PATCH 1/2] Strip off origin/* prefix --- bin/git/getCommitAndBranch.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/git/getCommitAndBranch.js b/bin/git/getCommitAndBranch.js index 8862680e1..0a54ddbe3 100644 --- a/bin/git/getCommitAndBranch.js +++ b/bin/git/getCommitAndBranch.js @@ -85,6 +85,9 @@ 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) branch = branch.replace(/^origin\//, ''); + log.debug( `git info: ${JSON.stringify({ commit, From dd7ab5da4649b7fb8dade0e2f464543a454f0ac0 Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Tue, 9 Mar 2021 16:22:45 +0100 Subject: [PATCH 2/2] Warn when origin prefix is stripped --- bin/git/getCommitAndBranch.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/git/getCommitAndBranch.js b/bin/git/getCommitAndBranch.js index 0a54ddbe3..55b64afd0 100644 --- a/bin/git/getCommitAndBranch.js +++ b/bin/git/getCommitAndBranch.js @@ -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 } = {}) { @@ -86,7 +87,10 @@ export async function getCommitAndBranch({ branchName, patchBaseRef, ci, log } = !!process.env.GITHUB_REPOSITORY; // Strip off any `origin/` prefix that's added sometimes. - if (!branchName && !isFromEnvVariable) branch = branch.replace(/^origin\//, ''); + 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({