diff --git a/netlify/netlify-plugin-branch-sync/index.js b/netlify/netlify-plugin-branch-sync/index.js index 5f3948142..09bb238d1 100644 --- a/netlify/netlify-plugin-branch-sync/index.js +++ b/netlify/netlify-plugin-branch-sync/index.js @@ -98,19 +98,7 @@ export const onPreBuild = async function ({ utils }) { } } - if (existsSync(CLONE_DIR)) { - // Fetch if already cloned. - logger.debug(`Fetching from origin`) - - await run("git", [ - "-C", - CLONE_DIR, - "fetch", - "--no-tags", - "origin", - SYNC_SOURCE, - ]) - } else { + if (!existsSync(CLONE_DIR)) { // Clone if there is no clone. const token = process.env.BITBUCKET_ACCESS_TOKEN ?? "" const cloneURL = `https://x-token-auth:${token}@bitbucket.org/scandic-swap/web.git` @@ -118,16 +106,14 @@ export const onPreBuild = async function ({ utils }) { logger.debug(`Cloning from ${cloneURL.replace(token, "****")}`) logger.debug(`Cloning to ${CLONE_DIR}`) - await run("git", [ - "clone", - "--bare", - "--branch", - SYNC_SOURCE, - cloneURL, - CLONE_DIR, - ]) + await run("git", ["clone", "--bare", "--branch", SYNC_SOURCE, cloneURL, CLONE_DIR]) } + // Always fetch to ensure FETCH_HEAD is available + logger.debug(`Fetching from origin`) + + await run("git", ["-C", CLONE_DIR, "fetch", "--no-tags", "origin", SYNC_SOURCE]) + logger.debug(`Attempting to sync: ${SYNC_DEST.join(", ")}`) for (let i = 0; i < SYNC_DEST.length; ++i) {