From 630cdb38746cb306174af730f36f5d4cb9bc51ba Mon Sep 17 00:00:00 2001 From: Salman Muin Kayser Chishti Date: Mon, 11 Aug 2025 12:47:29 +0100 Subject: [PATCH] linting --- src/git-command-manager.ts | 4 ++-- src/git-directory-helper.ts | 18 +++++++++++++----- src/git-source-provider.ts | 32 ++++++++++++++++++-------------- src/input-helper.ts | 4 +++- 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index 26e4102..580d9f2 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -209,7 +209,7 @@ class GitCommandManager { options: string[] = [] ): Promise { const args = ['checkout', '--progress'] - + // Add custom options (like --merge) if provided if (options.length > 0) { args.push(...options) @@ -217,7 +217,7 @@ class GitCommandManager { // Default behavior - use force args.push('--force') } - + if (startPoint) { args.push('-B', ref, startPoint) } else { diff --git a/src/git-directory-helper.ts b/src/git-directory-helper.ts index c72f08e..2d255b2 100644 --- a/src/git-directory-helper.ts +++ b/src/git-directory-helper.ts @@ -19,10 +19,12 @@ export async function prepareExistingDirectory( // Indicates whether to delete the directory contents let remove = false - + // If preserveLocalChanges is true, log it if (preserveLocalChanges) { - core.info(`Preserve local changes is enabled, will attempt to keep local files`) + core.info( + `Preserve local changes is enabled, will attempt to keep local files` + ) } // Check whether using git or REST API @@ -132,11 +134,17 @@ export async function prepareExistingDirectory( await io.rmRF(path.join(repositoryPath, file)) } } else if (remove && preserveLocalChanges) { - core.info(`Skipping deletion of directory contents due to preserve-local-changes setting`) + core.info( + `Skipping deletion of directory contents due to preserve-local-changes setting` + ) // We still need to make sure we have a git repository to work with if (!git) { - core.info(`Initializing git repository to prepare for checkout with preserved changes`) - await fs.promises.mkdir(path.join(repositoryPath, '.git'), { recursive: true }) + core.info( + `Initializing git repository to prepare for checkout with preserved changes` + ) + await fs.promises.mkdir(path.join(repositoryPath, '.git'), { + recursive: true + }) } } } diff --git a/src/git-source-provider.ts b/src/git-source-provider.ts index 3403292..c484f97 100644 --- a/src/git-source-provider.ts +++ b/src/git-source-provider.ts @@ -232,17 +232,17 @@ export async function getSource(settings: IGitSourceSettings): Promise { core.startGroup('Checking out the ref') if (settings.preserveLocalChanges) { core.info('Attempting to preserve local changes during checkout') - + // List and store local files before checkout const fs = require('fs') const path = require('path') const localFiles = new Map() - + try { // Get all files in the workspace that aren't in the .git directory const workspacePath = process.cwd() core.info(`Current workspace path: ${workspacePath}`) - + // List all files in the current directory using fs const listFilesRecursively = (dir: string): string[] => { let results: string[] = [] @@ -252,7 +252,7 @@ export async function getSource(settings: IGitSourceSettings): Promise { const relativePath = path.relative(workspacePath, fullPath) // Skip .git directory if (relativePath.startsWith('.git')) return - + const stat = fs.statSync(fullPath) if (stat && stat.isDirectory()) { // Recursively explore subdirectories @@ -270,17 +270,17 @@ export async function getSource(settings: IGitSourceSettings): Promise { }) return results } - + const localFilesList = listFilesRecursively(workspacePath) core.info(`Found ${localFilesList.length} local files to preserve:`) localFilesList.forEach(file => core.info(` - ${file}`)) } catch (error) { core.warning(`Failed to list local files: ${error}`) } - + // Perform normal checkout await git.checkout(checkoutInfo.ref, checkoutInfo.startPoint) - + // Restore local files that were not tracked by git core.info('Restoring local files after checkout') try { @@ -290,16 +290,16 @@ export async function getSource(settings: IGitSourceSettings): Promise { silent: true, ignoreReturnCode: true } - + for (const [filePath, content] of localFiles.entries()) { // Check if file exists in git using a child process instead of git.execGit - const { exec } = require('@actions/exec') + const {exec} = require('@actions/exec') let exitCode = 0 const output = { stdout: '', stderr: '' } - + // Capture output const options = { ...execOptions, @@ -312,14 +312,18 @@ export async function getSource(settings: IGitSourceSettings): Promise { } } } - - exitCode = await exec('git', ['ls-files', '--error-unmatch', filePath], options) - + + exitCode = await exec( + 'git', + ['ls-files', '--error-unmatch', filePath], + options + ) + if (exitCode !== 0) { // File is not tracked by git, safe to restore const fullPath = path.join(process.cwd(), filePath) // Ensure directory exists - fs.mkdirSync(path.dirname(fullPath), { recursive: true }) + fs.mkdirSync(path.dirname(fullPath), {recursive: true}) fs.writeFileSync(fullPath, content) core.info(`Restored local file: ${filePath}`) restoredCount++ diff --git a/src/input-helper.ts b/src/input-helper.ts index 49eafc7..c4f29f1 100644 --- a/src/input-helper.ts +++ b/src/input-helper.ts @@ -83,7 +83,9 @@ export async function getInputs(): Promise { core.debug(`clean = ${result.clean}`) // Preserve local changes - result.preserveLocalChanges = (core.getInput('preserve-local-changes') || 'false').toUpperCase() === 'TRUE' + result.preserveLocalChanges = + (core.getInput('preserve-local-changes') || 'false').toUpperCase() === + 'TRUE' core.debug(`preserveLocalChanges = ${result.preserveLocalChanges}`) // Filter