Skip to content

Instantly share code, notes, and snippets.

@amitsingh-007
Created July 4, 2020 06:45
Show Gist options
  • Save amitsingh-007/b83297e3d6993cf2a1f907f5396da0aa to your computer and use it in GitHub Desktop.
Save amitsingh-007/b83297e3d6993cf2a1f907f5396da0aa to your computer and use it in GitHub Desktop.
Fetching base branch on CI as well as on local machine
/*
* Need to add refs and then fetch, as Jenkins does not allow to fetch other barnches
*/
async function fetchBaseBranch(baseBranch) {
try {
console.log("Fetching ${baseBranch} from remote");
const addBaseRefs = `git config --add remote.origin.fetch +refs/heads/${baseBranch}:refs/remotes/origin/${baseBranch}`;
const fetchBase = `git fetch --no-tags origin +refs/heads/${baseBranch}:refs/remotes/origin/${baseBranch}`;
const command = `${addBaseRefs} && ${fetchBase}`;
await exec(command);
} catch (ex) {
console.log("Failed in fetching changed files", ex);
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment