mirror of
				https://github.com/actions/checkout.git
				synced 2025-10-31 16:13:36 +00:00 
			
		
		
		
	linting
This commit is contained in:
		
							parent
							
								
									6503dcd44c
								
							
						
					
					
						commit
						630cdb3874
					
				| @ -209,7 +209,7 @@ class GitCommandManager { | |||||||
|     options: string[] = [] |     options: string[] = [] | ||||||
|   ): Promise<void> { |   ): Promise<void> { | ||||||
|     const args = ['checkout', '--progress'] |     const args = ['checkout', '--progress'] | ||||||
|      | 
 | ||||||
|     // Add custom options (like --merge) if provided
 |     // Add custom options (like --merge) if provided
 | ||||||
|     if (options.length > 0) { |     if (options.length > 0) { | ||||||
|       args.push(...options) |       args.push(...options) | ||||||
| @ -217,7 +217,7 @@ class GitCommandManager { | |||||||
|       // Default behavior - use force
 |       // Default behavior - use force
 | ||||||
|       args.push('--force') |       args.push('--force') | ||||||
|     } |     } | ||||||
|      | 
 | ||||||
|     if (startPoint) { |     if (startPoint) { | ||||||
|       args.push('-B', ref, startPoint) |       args.push('-B', ref, startPoint) | ||||||
|     } else { |     } else { | ||||||
|  | |||||||
| @ -19,10 +19,12 @@ export async function prepareExistingDirectory( | |||||||
| 
 | 
 | ||||||
|   // Indicates whether to delete the directory contents
 |   // Indicates whether to delete the directory contents
 | ||||||
|   let remove = false |   let remove = false | ||||||
|    | 
 | ||||||
|   // If preserveLocalChanges is true, log it
 |   // If preserveLocalChanges is true, log it
 | ||||||
|   if (preserveLocalChanges) { |   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
 |   // Check whether using git or REST API
 | ||||||
| @ -132,11 +134,17 @@ export async function prepareExistingDirectory( | |||||||
|       await io.rmRF(path.join(repositoryPath, file)) |       await io.rmRF(path.join(repositoryPath, file)) | ||||||
|     } |     } | ||||||
|   } else if (remove && preserveLocalChanges) { |   } 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
 |     // We still need to make sure we have a git repository to work with
 | ||||||
|     if (!git) { |     if (!git) { | ||||||
|       core.info(`Initializing git repository to prepare for checkout with preserved changes`) |       core.info( | ||||||
|       await fs.promises.mkdir(path.join(repositoryPath, '.git'), { recursive: true }) |         `Initializing git repository to prepare for checkout with preserved changes` | ||||||
|  |       ) | ||||||
|  |       await fs.promises.mkdir(path.join(repositoryPath, '.git'), { | ||||||
|  |         recursive: true | ||||||
|  |       }) | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -232,17 +232,17 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> { | |||||||
|     core.startGroup('Checking out the ref') |     core.startGroup('Checking out the ref') | ||||||
|     if (settings.preserveLocalChanges) { |     if (settings.preserveLocalChanges) { | ||||||
|       core.info('Attempting to preserve local changes during checkout') |       core.info('Attempting to preserve local changes during checkout') | ||||||
|        | 
 | ||||||
|       // List and store local files before checkout
 |       // List and store local files before checkout
 | ||||||
|       const fs = require('fs') |       const fs = require('fs') | ||||||
|       const path = require('path') |       const path = require('path') | ||||||
|       const localFiles = new Map() |       const localFiles = new Map() | ||||||
|        | 
 | ||||||
|       try { |       try { | ||||||
|         // Get all files in the workspace that aren't in the .git directory
 |         // Get all files in the workspace that aren't in the .git directory
 | ||||||
|         const workspacePath = process.cwd() |         const workspacePath = process.cwd() | ||||||
|         core.info(`Current workspace path: ${workspacePath}`) |         core.info(`Current workspace path: ${workspacePath}`) | ||||||
|          | 
 | ||||||
|         // List all files in the current directory using fs
 |         // List all files in the current directory using fs
 | ||||||
|         const listFilesRecursively = (dir: string): string[] => { |         const listFilesRecursively = (dir: string): string[] => { | ||||||
|           let results: string[] = [] |           let results: string[] = [] | ||||||
| @ -252,7 +252,7 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> { | |||||||
|             const relativePath = path.relative(workspacePath, fullPath) |             const relativePath = path.relative(workspacePath, fullPath) | ||||||
|             // Skip .git directory
 |             // Skip .git directory
 | ||||||
|             if (relativePath.startsWith('.git')) return |             if (relativePath.startsWith('.git')) return | ||||||
|              | 
 | ||||||
|             const stat = fs.statSync(fullPath) |             const stat = fs.statSync(fullPath) | ||||||
|             if (stat && stat.isDirectory()) { |             if (stat && stat.isDirectory()) { | ||||||
|               // Recursively explore subdirectories
 |               // Recursively explore subdirectories
 | ||||||
| @ -270,17 +270,17 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> { | |||||||
|           }) |           }) | ||||||
|           return results |           return results | ||||||
|         } |         } | ||||||
|          | 
 | ||||||
|         const localFilesList = listFilesRecursively(workspacePath) |         const localFilesList = listFilesRecursively(workspacePath) | ||||||
|         core.info(`Found ${localFilesList.length} local files to preserve:`) |         core.info(`Found ${localFilesList.length} local files to preserve:`) | ||||||
|         localFilesList.forEach(file => core.info(`  - ${file}`)) |         localFilesList.forEach(file => core.info(`  - ${file}`)) | ||||||
|       } catch (error) { |       } catch (error) { | ||||||
|         core.warning(`Failed to list local files: ${error}`) |         core.warning(`Failed to list local files: ${error}`) | ||||||
|       } |       } | ||||||
|        | 
 | ||||||
|       // Perform normal checkout
 |       // Perform normal checkout
 | ||||||
|       await git.checkout(checkoutInfo.ref, checkoutInfo.startPoint) |       await git.checkout(checkoutInfo.ref, checkoutInfo.startPoint) | ||||||
|        | 
 | ||||||
|       // Restore local files that were not tracked by git
 |       // Restore local files that were not tracked by git
 | ||||||
|       core.info('Restoring local files after checkout') |       core.info('Restoring local files after checkout') | ||||||
|       try { |       try { | ||||||
| @ -290,16 +290,16 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> { | |||||||
|           silent: true, |           silent: true, | ||||||
|           ignoreReturnCode: true |           ignoreReturnCode: true | ||||||
|         } |         } | ||||||
|          | 
 | ||||||
|         for (const [filePath, content] of localFiles.entries()) { |         for (const [filePath, content] of localFiles.entries()) { | ||||||
|           // Check if file exists in git using a child process instead of git.execGit
 |           // 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 |           let exitCode = 0 | ||||||
|           const output = { |           const output = { | ||||||
|             stdout: '', |             stdout: '', | ||||||
|             stderr: '' |             stderr: '' | ||||||
|           } |           } | ||||||
|            | 
 | ||||||
|           // Capture output
 |           // Capture output
 | ||||||
|           const options = { |           const options = { | ||||||
|             ...execOptions, |             ...execOptions, | ||||||
| @ -312,14 +312,18 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> { | |||||||
|               } |               } | ||||||
|             } |             } | ||||||
|           } |           } | ||||||
|            | 
 | ||||||
|           exitCode = await exec('git', ['ls-files', '--error-unmatch', filePath], options) |           exitCode = await exec( | ||||||
|            |             'git', | ||||||
|  |             ['ls-files', '--error-unmatch', filePath], | ||||||
|  |             options | ||||||
|  |           ) | ||||||
|  | 
 | ||||||
|           if (exitCode !== 0) { |           if (exitCode !== 0) { | ||||||
|             // File is not tracked by git, safe to restore
 |             // File is not tracked by git, safe to restore
 | ||||||
|             const fullPath = path.join(process.cwd(), filePath) |             const fullPath = path.join(process.cwd(), filePath) | ||||||
|             // Ensure directory exists
 |             // Ensure directory exists
 | ||||||
|             fs.mkdirSync(path.dirname(fullPath), { recursive: true }) |             fs.mkdirSync(path.dirname(fullPath), {recursive: true}) | ||||||
|             fs.writeFileSync(fullPath, content) |             fs.writeFileSync(fullPath, content) | ||||||
|             core.info(`Restored local file: ${filePath}`) |             core.info(`Restored local file: ${filePath}`) | ||||||
|             restoredCount++ |             restoredCount++ | ||||||
|  | |||||||
| @ -83,7 +83,9 @@ export async function getInputs(): Promise<IGitSourceSettings> { | |||||||
|   core.debug(`clean = ${result.clean}`) |   core.debug(`clean = ${result.clean}`) | ||||||
| 
 | 
 | ||||||
|   // Preserve local changes
 |   // 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}`) |   core.debug(`preserveLocalChanges = ${result.preserveLocalChanges}`) | ||||||
| 
 | 
 | ||||||
|   // Filter
 |   // Filter
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user