Example #1
0
function pullBranch(remoteName, branch, commitId) {
    tl.debug("Checking if branch " + branch + " exists locally");
    var localBranchExists = false;
    var res = execGit(["branch"]);
    if (res.code !== 0) {
        tl.error("Could not execute [git branch]");
        return false;
    }
    else {
        var branchList = res.stdout.toString('utf-8');
        localBranchExists = branchList.indexOf(branch + "\n") > -1;
    }
    var remoteBranch = remoteName + "/" + branch;
    if (!localBranchExists) {
        // check branch out from origin
        tl.debug("Checking out and tracking remote branch: " + remoteBranch);
        res = execGit(["checkout", "--track", remoteBranch]);
        if (res.code !== 0) {
            tl.error("Could not checkout remote branch " + remoteBranch);
            return false;
        }
        // after pulling the branch, we need to revert to the original commit
        if (commitId) {
            return checkoutCommit(commitId);
        }
    }
    else {
        // if the branch exists locally, then make sure it's up to date
        tl.debug("Resetting branch " + branch);
        return execGit(["reset", "--hard", remoteBranch]).code === 0;
    }
    return true;
}
function execGit(gitArgs) {
    var gitTool = tl.createToolRunner(tl.which("git", true));
    var opts = {
        failOnStdErr: true
    };
    gitTool.arg(gitArgs);
    var res = gitTool.execSync(opts);
    if (res.code !== 0) {
        if (!isEmpty(res.stderr)) {
            tl.error(res.stderr);
        }
        if (typeof res.error !== 'undefined' && typeof res.error.message !== 'undefined' && !isEmpty(res.error.message)) {
            tl.error(res.error.message);
        }
    }
    return res;
}
Example #3
0
function resetHead() {
    tl.debug("Resetting HEAD");
    var res = execGit(["reset", "--hard", "HEAD^"]);
    if (res.code !== 0) {
        tl.error("Could not reset HEAD");
        return false;
    }
    return true;
}
Example #4
0
function checkoutCommit(commitId) {
    tl.debug("Checking out commit " + commitId);
    var res = execGit(["checkout", commitId]);
    if (res.code !== 0) {
        tl.error("Could not checkout " + commitId);
        return false;
    }
    return true;
}
function checkoutBranch(branch) {
    tl.debug("Checkout " + branch);
    var res = execGit(["checkout", branch]);
    if (res.code !== 0) {
        tl.error("Could not checkout " + branch);
        return false;
    }
    return true;
}
function cloneRepo(repoUrl, pat) {
    if (pat === void 0) { pat = ""; }
    var url = getUrlWithToken(repoUrl, pat);
    var res = execGit(["clone", url]);
    if (res.code !== 0) {
        tl.error("Could not clone " + repoUrl);
        return false;
    }
    return true;
}
if (buildRegexObj.test(buildNumber)) {
    var versionNum = buildRegexObj.exec(buildNumber)[buildRegexIndex];
    console.info("Using prefix [" + replacePrefix + "] and version [" + versionNum + "] and postfix [" + replacePostfix + "] in folder [" + sourcePath + "]");
    var filesToReplace = tl.glob("" + sourcePath + separator + filePattern);
    if (filesToReplace === undefined || filesToReplace.length === 0) {
        tl.warning("No files found");
    }
    else {
        for (var i = 0; i < filesToReplace.length; i++) {
            var file = filesToReplace[i];
            console.info("Changing version in " + file);
            var contents = fs.readFileSync(file, 'utf8').toString();
            var checkMatches = new RegExp(replaceRegex).exec(contents);
            if (!checkMatches || checkMatches.length === 0) {
                if (failIfNoMatchFound) {
                    tl.error("No matches for regex [" + replaceRegex + "] found in file " + file);
                    process.exit(1);
                }
                else {
                    tl.warning("No matches for regex [" + replaceRegex + "] found in file " + file);
                }
            }
            else {
                console.info(checkMatches.length + " matches for regex [" + replaceRegex + "] found in file " + file);
                // make the file writable
                sh.chmod(666, file);
                // replace all occurrences by adding g to the pattern
                sh.sed("-i", new RegExp(replaceRegex, "g"), replacePrefix + versionNum + replacePostfix, file);
            }
        }
        console.info("Processed " + filesToReplace.length + " files");
Example #8
0
 // make sure that we're on the repo commit before continuing
 if (!ut.checkoutCommit(commitId)) {
     tl.exit(1);
 }
 // now that all the branches are local, test the merges
 errors = 0;
 for (var i = 0; i < branchesToMerge.length; i++) {
     var branch = branchesToMerge[i].trim();
     if (ut.merge(branch, false)) {
         console.info("No merge conflicts detected when merging " + branch);
         if (testMergeAll) {
             // if we're testing all the merges, then we need to commit before
             // merging the next branch
             if (!ut.commit("Testing merge")) {
                 errors++;
                 tl.error("Commit failed");
                 break;
             }
         }
         else {
             ut.abortMerge();
         }
     }
     else {
         errors++;
         tl.error("Merge " + branch + " operation has conflicts (or failed)");
     }
 }
 // clean up
 ut.checkoutCommit(commitId);
 // fail the task if there were errors