Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect handling of Unicode characters in exec() #162

Merged
merged 1 commit into from Oct 11, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -26,7 +26,7 @@
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.4",
"@actions/exec": "^1.0.4",
"@actions/exec": "^1.1.1",
"@actions/github": "^2.2.0",
"@octokit/webhooks": "^7.6.2",
"picomatch": "^2.2.2"
Expand Down
21 changes: 0 additions & 21 deletions src/exec.ts

This file was deleted.

41 changes: 21 additions & 20 deletions src/git.ts
@@ -1,4 +1,4 @@
import exec from './exec'
import {getExecOutput} from '@actions/exec'
import * as core from '@actions/core'
import {File, ChangeStatus} from './file'

Expand All @@ -9,7 +9,7 @@ export async function getChangesInLastCommit(): Promise<File[]> {
core.startGroup(`Change detection in last commit`)
let output = ''
try {
output = (await exec('git', ['log', '--format=', '--no-renames', '--name-status', '-z', '-n', '1'])).stdout
output = (await getExecOutput('git', ['log', '--format=', '--no-renames', '--name-status', '-z', '-n', '1'])).stdout
} finally {
fixStdOutNullTermination()
core.endGroup()
Expand All @@ -27,7 +27,8 @@ export async function getChanges(base: string, head: string): Promise<File[]> {
let output = ''
try {
// Two dots '..' change detection - directly compares two versions
output = (await exec('git', ['diff', '--no-renames', '--name-status', '-z', `${baseRef}..${headRef}`])).stdout
output = (await getExecOutput('git', ['diff', '--no-renames', '--name-status', '-z', `${baseRef}..${headRef}`]))
.stdout
} finally {
fixStdOutNullTermination()
core.endGroup()
Expand All @@ -41,7 +42,7 @@ export async function getChangesOnHead(): Promise<File[]> {
core.startGroup(`Change detection on HEAD`)
let output = ''
try {
output = (await exec('git', ['diff', '--no-renames', '--name-status', '-z', 'HEAD'])).stdout
output = (await getExecOutput('git', ['diff', '--no-renames', '--name-status', '-z', 'HEAD'])).stdout
} finally {
fixStdOutNullTermination()
core.endGroup()
Expand All @@ -57,7 +58,7 @@ export async function getChangesSinceMergeBase(base: string, head: string, initi
if (baseRef === undefined || headRef === undefined) {
return false
}
return (await exec('git', ['merge-base', baseRef, headRef], {ignoreReturnCode: true})).code === 0
return (await getExecOutput('git', ['merge-base', baseRef, headRef], {ignoreReturnCode: true})).exitCode === 0
}

let noMergeBase = false
Expand All @@ -66,12 +67,12 @@ export async function getChangesSinceMergeBase(base: string, head: string, initi
baseRef = await getLocalRef(base)
headRef = await getLocalRef(head)
if (!(await hasMergeBase())) {
await exec('git', ['fetch', '--no-tags', `--depth=${initialFetchDepth}`, 'origin', base, head])
await getExecOutput('git', ['fetch', '--no-tags', `--depth=${initialFetchDepth}`, 'origin', base, head])
if (baseRef === undefined || headRef === undefined) {
baseRef = baseRef ?? (await getLocalRef(base))
headRef = headRef ?? (await getLocalRef(head))
if (baseRef === undefined || headRef === undefined) {
await exec('git', ['fetch', '--tags', '--depth=1', 'origin', base, head], {
await getExecOutput('git', ['fetch', '--tags', '--depth=1', 'origin', base, head], {
ignoreReturnCode: true // returns exit code 1 if tags on remote were updated - we can safely ignore it
})
baseRef = baseRef ?? (await getLocalRef(base))
Expand All @@ -93,12 +94,12 @@ export async function getChangesSinceMergeBase(base: string, head: string, initi
let lastCommitCount = await getCommitCount()
while (!(await hasMergeBase())) {
depth = Math.min(depth * 2, Number.MAX_SAFE_INTEGER)
await exec('git', ['fetch', `--deepen=${depth}`, 'origin', base, head])
await getExecOutput('git', ['fetch', `--deepen=${depth}`, 'origin', base, head])
const commitCount = await getCommitCount()
if (commitCount === lastCommitCount) {
core.info('No more commits were fetched')
core.info('Last attempt will be to fetch full history')
await exec('git', ['fetch'])
await getExecOutput('git', ['fetch'])
if (!(await hasMergeBase())) {
noMergeBase = true
}
Expand All @@ -122,7 +123,7 @@ export async function getChangesSinceMergeBase(base: string, head: string, initi
core.startGroup(`Change detection ${diffArg}`)
let output = ''
try {
output = (await exec('git', ['diff', '--no-renames', '--name-status', '-z', diffArg])).stdout
output = (await getExecOutput('git', ['diff', '--no-renames', '--name-status', '-z', diffArg])).stdout
} finally {
fixStdOutNullTermination()
core.endGroup()
Expand All @@ -147,7 +148,7 @@ export async function listAllFilesAsAdded(): Promise<File[]> {
core.startGroup('Listing all files tracked by git')
let output = ''
try {
output = (await exec('git', ['ls-files', '-z'])).stdout
output = (await getExecOutput('git', ['ls-files', '-z'])).stdout
} finally {
fixStdOutNullTermination()
core.endGroup()
Expand All @@ -165,17 +166,17 @@ export async function listAllFilesAsAdded(): Promise<File[]> {
export async function getCurrentRef(): Promise<string> {
core.startGroup(`Get current git ref`)
try {
const branch = (await exec('git', ['branch', '--show-current'])).stdout.trim()
const branch = (await getExecOutput('git', ['branch', '--show-current'])).stdout.trim()
if (branch) {
return branch
}

const describe = await exec('git', ['describe', '--tags', '--exact-match'], {ignoreReturnCode: true})
if (describe.code === 0) {
const describe = await getExecOutput('git', ['describe', '--tags', '--exact-match'], {ignoreReturnCode: true})
if (describe.exitCode === 0) {
return describe.stdout.trim()
}

return (await exec('git', ['rev-parse', HEAD])).stdout.trim()
return (await getExecOutput('git', ['rev-parse', HEAD])).stdout.trim()
} finally {
core.endGroup()
}
Expand All @@ -198,11 +199,11 @@ export function isGitSha(ref: string): boolean {
}

async function hasCommit(ref: string): Promise<boolean> {
return (await exec('git', ['cat-file', '-e', `${ref}^{commit}`], {ignoreReturnCode: true})).code === 0
return (await getExecOutput('git', ['cat-file', '-e', `${ref}^{commit}`], {ignoreReturnCode: true})).exitCode === 0
}

async function getCommitCount(): Promise<number> {
const output = (await exec('git', ['rev-list', '--count', '--all'])).stdout
const output = (await getExecOutput('git', ['rev-list', '--count', '--all'])).stdout
const count = parseInt(output)
return isNaN(count) ? 0 : count
}
Expand All @@ -212,7 +213,7 @@ async function getLocalRef(shortName: string): Promise<string | undefined> {
return (await hasCommit(shortName)) ? shortName : undefined
}

const output = (await exec('git', ['show-ref', shortName], {ignoreReturnCode: true})).stdout
const output = (await getExecOutput('git', ['show-ref', shortName], {ignoreReturnCode: true})).stdout
const refs = output
.split(/\r?\n/g)
.map(l => l.match(/refs\/(?:(?:heads)|(?:tags)|(?:remotes\/origin))\/(.*)$/))
Expand All @@ -236,10 +237,10 @@ async function ensureRefAvailable(name: string): Promise<string> {
try {
let ref = await getLocalRef(name)
if (ref === undefined) {
await exec('git', ['fetch', '--depth=1', '--no-tags', 'origin', name])
await getExecOutput('git', ['fetch', '--depth=1', '--no-tags', 'origin', name])
ref = await getLocalRef(name)
if (ref === undefined) {
await exec('git', ['fetch', '--depth=1', '--tags', 'origin', name])
await getExecOutput('git', ['fetch', '--depth=1', '--tags', 'origin', name])
ref = await getLocalRef(name)
if (ref === undefined) {
throw new Error(`Could not determine what is ${name} - fetch works but it's not a branch, tag or commit SHA`)
Expand Down