Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 24 additions & 64 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30495,11 +30495,12 @@ const core = __importStar(__nccwpck_require__(2186));
const exec_1 = __nccwpck_require__(1514);
const node_path_1 = __nccwpck_require__(9411);
const cwd_1 = __nccwpck_require__(7119);
function switchBranch(branch) {
function execGit(args) {
return __awaiter(this, void 0, void 0, function* () {
const debugOutput = [];
const warningOutput = [];
yield (0, exec_1.exec)('git', ['checkout', '-b', branch], {
const errorOutput = [];
yield (0, exec_1.exec)('git', args, {
silent: true,
ignoreReturnCode: true,
listeners: {
Expand All @@ -30508,16 +30509,28 @@ function switchBranch(branch) {
},
errline: (error) => {
if (/^(fatal|error):/.test(error))
core.error(error);
errorOutput.push(error);
else
warningOutput.push(error);
},
},
});
if (debugOutput.length > 0)
core.debug(debugOutput.join('\n'));
if (warningOutput.length > 0)
core.warning(warningOutput.join('\n'));
for (const msg of debugOutput)
core.debug(msg);
for (const msg of warningOutput)
core.warning(msg);
for (const msg of errorOutput)
core.error(msg);
return {
debug: debugOutput,
warn: warningOutput,
error: errorOutput,
};
});
}
function switchBranch(branch) {
return __awaiter(this, void 0, void 0, function* () {
yield execGit(['checkout', '-b', branch]);
});
}
function pushCurrentBranch() {
Expand All @@ -30526,75 +30539,22 @@ function pushCurrentBranch() {
if (core.getBooleanInput('branch-push-force')) {
pushArgs.splice(1, 0, '--force');
}
const debugOutput = [];
const warningOutput = [];
yield (0, exec_1.exec)('git', pushArgs, {
silent: true,
ignoreReturnCode: true,
listeners: {
stdline: (data) => {
debugOutput.push(data);
},
errline: (error) => {
if (/^(fatal|error):/.test(error))
core.error(error);
else
warningOutput.push(error);
},
},
});
if (debugOutput.length > 0)
core.debug(debugOutput.join('\n'));
if (warningOutput.length > 0)
core.warning(warningOutput.join('\n'));
yield execGit(pushArgs);
});
}
function addFileChanges(globPatterns) {
return __awaiter(this, void 0, void 0, function* () {
const workspace = (0, cwd_1.getWorkspace)();
const workspacePaths = globPatterns.map((p) => (0, node_path_1.join)(workspace, p));
const debugOutput = [];
const warningOutput = [];
yield (0, exec_1.exec)('git', ['add', '--', ...workspacePaths], {
silent: true,
ignoreReturnCode: true,
listeners: {
stdline: (data) => {
debugOutput.push(data);
},
errline: (error) => {
if (/^(fatal|error):/.test(error))
core.error(error);
else
warningOutput.push(error);
},
},
});
if (debugOutput.length > 0)
core.debug(debugOutput.join('\n'));
if (warningOutput.length > 0)
core.warning(warningOutput.join('\n'));
yield execGit(['add', '--', ...workspacePaths]);
});
}
function getFileChanges() {
return __awaiter(this, void 0, void 0, function* () {
const output = [];
yield (0, exec_1.exec)('git', ['status', '-suall', '--porcelain'], {
listeners: {
stdline: (data) => {
output.push(data);
},
errline: (error) => {
if (/^(fatal|error):/.test(error))
core.error(error);
else
core.warning(error);
},
},
});
const { debug } = yield execGit(['status', '-suall', '--porcelain']);
const additions = [];
const deletions = [];
output.forEach((line) => {
debug.forEach((line) => {
const staged = line.charAt(0);
const filePath = line.slice(3);
switch (staged) {
Expand Down
76 changes: 22 additions & 54 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,38 @@ import {

import { getWorkspace } from './utils/cwd'

export async function switchBranch(branch: string) {
async function execGit(args: string[]) {
const debugOutput: string[] = []
const warningOutput: string[] = []
await exec('git', ['checkout', '-b', branch], {
const errorOutput: string[] = []

await exec('git', args, {
silent: true,
ignoreReturnCode: true,
listeners: {
stdline: (data: string) => {
debugOutput.push(data)
},
errline: (error: string) => {
if (/^(fatal|error):/.test(error)) core.error(error)
if (/^(fatal|error):/.test(error)) errorOutput.push(error)
else warningOutput.push(error)
},
},
})

if (debugOutput.length > 0) core.debug(debugOutput.join('\n'))
if (warningOutput.length > 0) core.warning(warningOutput.join('\n'))
for (const msg of debugOutput) core.debug(msg)
for (const msg of warningOutput) core.warning(msg)
for (const msg of errorOutput) core.error(msg)

return {
debug: debugOutput,
warn: warningOutput,
error: errorOutput,
}
}

export async function switchBranch(branch: string) {
await execGit(['checkout', '-b', branch])
}

export async function pushCurrentBranch() {
Expand All @@ -36,67 +49,22 @@ export async function pushCurrentBranch() {
pushArgs.splice(1, 0, '--force')
}

const debugOutput: string[] = []
const warningOutput: string[] = []
await exec('git', pushArgs, {
silent: true,
ignoreReturnCode: true,
listeners: {
stdline: (data: string) => {
debugOutput.push(data)
},
errline: (error: string) => {
if (/^(fatal|error):/.test(error)) core.error(error)
else warningOutput.push(error)
},
},
})

if (debugOutput.length > 0) core.debug(debugOutput.join('\n'))
if (warningOutput.length > 0) core.warning(warningOutput.join('\n'))
await execGit(pushArgs)
}

export async function addFileChanges(globPatterns: string[]): Promise<void> {
const workspace = getWorkspace()
const workspacePaths = globPatterns.map((p) => join(workspace, p))

const debugOutput: string[] = []
const warningOutput: string[] = []
await exec('git', ['add', '--', ...workspacePaths], {
silent: true,
ignoreReturnCode: true,
listeners: {
stdline: (data: string) => {
debugOutput.push(data)
},
errline: (error: string) => {
if (/^(fatal|error):/.test(error)) core.error(error)
else warningOutput.push(error)
},
},
})

if (debugOutput.length > 0) core.debug(debugOutput.join('\n'))
if (warningOutput.length > 0) core.warning(warningOutput.join('\n'))
await execGit(['add', '--', ...workspacePaths])
}

export async function getFileChanges(): Promise<FileChanges> {
const output: string[] = []
await exec('git', ['status', '-suall', '--porcelain'], {
listeners: {
stdline: (data: string) => {
output.push(data)
},
errline: (error: string) => {
if (/^(fatal|error):/.test(error)) core.error(error)
else core.warning(error)
},
},
})
const { debug } = await execGit(['status', '-suall', '--porcelain'])

const additions: FileAddition[] = []
const deletions: FileDeletion[] = []
output.forEach((line) => {
debug.forEach((line) => {
const staged = line.charAt(0)
const filePath = line.slice(3)
switch (staged) {
Expand Down