UNPKG

grading

Version:

Grading of student submissions, in particular programming tests.

56 lines 3.07 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.gitAddAndCommit = exports.gitApplyPatch = exports.gitCreateAndCheckoutBranch = exports.getPatchFileName = exports.gitDiff = exports.gitBranches = exports.hasLocalGitRepository = void 0; const path_1 = __importDefault(require("path")); const fsUtil_1 = require("./fsUtil"); const cliUtil_1 = require("./cli/cliUtil"); async function hasLocalGitRepository(wsDir) { return await (0, fsUtil_1.folderExists)(path_1.default.join(wsDir, '.git'), 'git repository'); } exports.hasLocalGitRepository = hasLocalGitRepository; async function gitBranches(wsDir) { return (await (0, fsUtil_1.execShellAndRetrieveOutput)('git', ['branch'], { cwd: wsDir })).map(line => line.substring(2).trim()).filter(line => line.length > 0); } exports.gitBranches = gitBranches; async function gitDiff(wsDir, submissionBranch, gradingBranch, patchFolder, name, subId) { const patchFileName = getPatchFileName(patchFolder, name, subId); if (!await (0, fsUtil_1.folderExists)(patchFolder, 'patchFolder')) await (0, fsUtil_1.createDir)(patchFolder); const absPatchFilePath = path_1.default.resolve(patchFileName); if (await (0, fsUtil_1.fileExists)(absPatchFilePath, 'patch file')) { (0, cliUtil_1.warn)(` Patch file ${patchFileName} already exists, will be overwritten.`); } await (0, fsUtil_1.execShell)('git', ['diff', '--no-color', '--binary', '--output', absPatchFilePath, submissionBranch, gradingBranch], { colored: false }, { cwd: wsDir, indent: true, prefix: "git diff:" }); } exports.gitDiff = gitDiff; function getPatchFileName(patchFolder, name, subId) { return path_1.default.join(patchFolder, `${name}_${subId}.patch`); } exports.getPatchFileName = getPatchFileName; /** * `git checkout -b branch` */ async function gitCreateAndCheckoutBranch(wsDir, branch, colorOptions = { colored: false }) { await (0, fsUtil_1.execShell)('git', ['checkout', '-b', branch], colorOptions, { cwd: wsDir, indent: true, prefix: "git: " }); } exports.gitCreateAndCheckoutBranch = gitCreateAndCheckoutBranch; /** * `git apply diff.patch` */ async function gitApplyPatch(wsDir, patchFileName, colorOptions = { colored: false }) { const absPatchFilePath = path_1.default.resolve(patchFileName); await (0, fsUtil_1.execShell)('git', ['apply', absPatchFilePath], colorOptions, { cwd: wsDir, indent: true, prefix: "git: " }); } exports.gitApplyPatch = gitApplyPatch; /** * `git add .` `git commit -m msg` */ async function gitAddAndCommit(wsDir, msg, colorOptions = { colored: false }) { await (0, fsUtil_1.execShell)('git', ['add', '.'], colorOptions, { cwd: wsDir, indent: true, prefix: "git: " }); await (0, fsUtil_1.execShell)('git', ['commit', '-m', msg], colorOptions, { cwd: wsDir, indent: true, prefix: "git: " }); } exports.gitAddAndCommit = gitAddAndCommit; //# sourceMappingURL=gitCommands.js.map