mirror of
				https://github.com/actions/checkout.git
				synced 2025-10-31 18:18:37 +08:00 
			
		
		
		
	Use callbacks for all Git command receivers
This commit is contained in:
		
							parent
							
								
									755da8c3cf
								
							
						
					
					
						commit
						d4a3cff00f
					
				
							
								
								
									
										42
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										42
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							|  | @ -7450,8 +7450,31 @@ class GitCommandManager { | |||
|             else { | ||||
|                 args.push('--branches'); | ||||
|             } | ||||
|             const output = yield this.execGit(args); | ||||
|             for (let branch of output.stdout.trim().split('\n')) { | ||||
|             const stderr = []; | ||||
|             const errline = []; | ||||
|             const stdout = []; | ||||
|             const stdline = []; | ||||
|             const listeners = { | ||||
|                 stderr: (data) => { | ||||
|                     stderr.push(data.toString()); | ||||
|                 }, | ||||
|                 errline: (data) => { | ||||
|                     errline.push(data.toString()); | ||||
|                 }, | ||||
|                 stdout: (data) => { | ||||
|                     stdout.push(data.toString()); | ||||
|                 }, | ||||
|                 stdline: (data) => { | ||||
|                     stdline.push(data.toString()); | ||||
|                 } | ||||
|             }; | ||||
|             core.info(`${this.gitPath} ${args.join(' ')}`); | ||||
|             yield this.execGit(args, false, true, listeners); | ||||
|             core.debug(`stderr callback is: ${stderr}`); | ||||
|             core.debug(`errline callback is: ${errline}`); | ||||
|             core.debug(`stdout callback is: ${stdout}`); | ||||
|             core.debug(`stdline callback is: ${stdline}`); | ||||
|             for (let branch of stdline) { | ||||
|                 branch = branch.trim(); | ||||
|                 if (branch) { | ||||
|                     if (branch.startsWith('refs/heads/')) { | ||||
|  | @ -7463,6 +7486,7 @@ class GitCommandManager { | |||
|                     result.push(branch); | ||||
|                 } | ||||
|             } | ||||
|             core.info(result.join('\n')); | ||||
|             return result; | ||||
|         }); | ||||
|     } | ||||
|  | @ -7712,7 +7736,7 @@ class GitCommandManager { | |||
|             return result; | ||||
|         }); | ||||
|     } | ||||
|     execGit(args, allowAllExitCodes = false, silent = false) { | ||||
|     execGit(args, allowAllExitCodes = false, silent = false, customListeners = {}) { | ||||
|         return __awaiter(this, void 0, void 0, function* () { | ||||
|             fshelper.directoryExistsSync(this.workingDirectory, true); | ||||
|             const result = new GitOutput(); | ||||
|  | @ -7723,17 +7747,19 @@ class GitCommandManager { | |||
|             for (const key of Object.keys(this.gitEnv)) { | ||||
|                 env[key] = this.gitEnv[key]; | ||||
|             } | ||||
|             const defaultListener = { | ||||
|                 stdout: (data) => { | ||||
|                     stdout.push(data.toString()); | ||||
|                 } | ||||
|             }; | ||||
|             const mergedListeners = Object.assign(Object.assign({}, defaultListener), customListeners); | ||||
|             const stdout = []; | ||||
|             const options = { | ||||
|                 cwd: this.workingDirectory, | ||||
|                 env, | ||||
|                 silent, | ||||
|                 ignoreReturnCode: allowAllExitCodes, | ||||
|                 listeners: { | ||||
|                     stdout: (data) => { | ||||
|                         stdout.push(data.toString()); | ||||
|                     } | ||||
|                 } | ||||
|                 listeners: mergedListeners | ||||
|             }; | ||||
|             result.exitCode = yield exec.exec(`"${this.gitPath}"`, args, options); | ||||
|             result.stdout = stdout.join(''); | ||||
|  |  | |||
							
								
								
									
										13
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										13
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							|  | @ -23138,6 +23138,11 @@ | |||
|       "integrity": "sha512-M8WEXFuKXMYMVr45fo8mq0wUrrJHheiKZf6BArTKk9ZBYCKJEOU5H8cdWgDT+qCVZf7Na4lVUaZsA+h6uA9+PA==", | ||||
|       "dev": true | ||||
|     }, | ||||
|     "emitter-component": { | ||||
|       "version": "1.1.1", | ||||
|       "resolved": "https://registry.npmjs.org/emitter-component/-/emitter-component-1.1.1.tgz", | ||||
|       "integrity": "sha512-G+mpdiAySMuB7kesVRLuyvYRqDmshB7ReKEVuyBPkzQlmiDiLrt7hHHIy4Aff552bgknVN7B2/d3lzhGO5dvpQ==" | ||||
|     }, | ||||
|     "emittery": { | ||||
|       "version": "0.8.1", | ||||
|       "resolved": "https://registry.npmjs.org/emittery/-/emittery-0.8.1.tgz", | ||||
|  | @ -31781,6 +31786,14 @@ | |||
|         } | ||||
|       } | ||||
|     }, | ||||
|     "stream": { | ||||
|       "version": "0.0.2", | ||||
|       "resolved": "https://registry.npmjs.org/stream/-/stream-0.0.2.tgz", | ||||
|       "integrity": "sha512-gCq3NDI2P35B2n6t76YJuOp7d6cN/C7Rt0577l91wllh0sY9ZBuw9KaSGqH/b0hzn3CWWJbpbW0W0WvQ1H/Q7g==", | ||||
|       "requires": { | ||||
|         "emitter-component": "^1.1.1" | ||||
|       } | ||||
|     }, | ||||
|     "string-length": { | ||||
|       "version": "4.0.2", | ||||
|       "resolved": "https://registry.npmjs.org/string-length/-/string-length-4.0.2.tgz", | ||||
|  |  | |||
|  | @ -33,6 +33,7 @@ | |||
|     "@actions/github": "^2.2.0", | ||||
|     "@actions/io": "^1.1.2", | ||||
|     "@actions/tool-cache": "^1.1.2", | ||||
|     "stream": "0.0.2", | ||||
|     "uuid": "^3.3.3" | ||||
|   }, | ||||
|   "devDependencies": { | ||||
|  |  | |||
|  | @ -7,6 +7,7 @@ import * as refHelper from './ref-helper' | |||
| import * as regexpHelper from './regexp-helper' | ||||
| import * as retryHelper from './retry-helper' | ||||
| import {GitVersion} from './git-version' | ||||
| import stream, {Writable} from 'stream' | ||||
| 
 | ||||
| // Auth header not supported before 2.9
 | ||||
| // Wire protocol v2 not supported before 2.18
 | ||||
|  | @ -94,8 +95,11 @@ class GitCommandManager { | |||
| 
 | ||||
|     // Note, this implementation uses "rev-parse --symbolic-full-name" because the output from
 | ||||
|     // "branch --list" is more difficult when in a detached HEAD state.
 | ||||
|     // Note, this implementation uses "rev-parse --symbolic-full-name" because there is a bug
 | ||||
|     // in Git 2.18 that causes "rev-parse --symbolic" to output symbolic full names.
 | ||||
| 
 | ||||
|     // TODO(https://github.com/actions/checkout/issues/786): this implementation uses
 | ||||
|     // "rev-parse --symbolic-full-name" because there is a bug
 | ||||
|     // in Git 2.18 that causes "rev-parse --symbolic" to output symbolic full names. When
 | ||||
|     // 2.18 is no longer supported, we can switch back to --symbolic.
 | ||||
| 
 | ||||
|     const args = ['rev-parse', '--symbolic-full-name'] | ||||
|     if (remote) { | ||||
|  | @ -104,9 +108,36 @@ class GitCommandManager { | |||
|       args.push('--branches') | ||||
|     } | ||||
| 
 | ||||
|     const output = await this.execGit(args) | ||||
|     const stderr: string[] = [] | ||||
|     const errline: string[] = [] | ||||
|     const stdout: string[] = [] | ||||
|     const stdline: string[] = [] | ||||
| 
 | ||||
|     for (let branch of output.stdout.trim().split('\n')) { | ||||
|     const listeners = { | ||||
|       stderr: (data: Buffer) => { | ||||
|         stderr.push(data.toString()) | ||||
|       }, | ||||
|       errline: (data: Buffer) => { | ||||
|         errline.push(data.toString()) | ||||
|       }, | ||||
|       stdout: (data: Buffer) => { | ||||
|         stdout.push(data.toString()) | ||||
|       }, | ||||
|       stdline: (data: Buffer) => { | ||||
|         stdline.push(data.toString()) | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     core.info(`${this.gitPath} ${args.join(' ')}`) | ||||
| 
 | ||||
|     await this.execGit(args, false, true, listeners) | ||||
| 
 | ||||
|     core.debug(`stderr callback is: ${stderr}`) | ||||
|     core.debug(`errline callback is: ${errline}`) | ||||
|     core.debug(`stdout callback is: ${stdout}`) | ||||
|     core.debug(`stdline callback is: ${stdline}`) | ||||
| 
 | ||||
|     for (let branch of stdline) { | ||||
|       branch = branch.trim() | ||||
|       if (branch) { | ||||
|         if (branch.startsWith('refs/heads/')) { | ||||
|  | @ -119,6 +150,8 @@ class GitCommandManager { | |||
|       } | ||||
|     } | ||||
| 
 | ||||
|     core.info(result.join('\n')) | ||||
| 
 | ||||
|     return result | ||||
|   } | ||||
| 
 | ||||
|  | @ -395,7 +428,8 @@ class GitCommandManager { | |||
|   private async execGit( | ||||
|     args: string[], | ||||
|     allowAllExitCodes = false, | ||||
|     silent = false | ||||
|     silent = false, | ||||
|     customListeners = {} | ||||
|   ): Promise<GitOutput> { | ||||
|     fshelper.directoryExistsSync(this.workingDirectory, true) | ||||
| 
 | ||||
|  | @ -409,18 +443,21 @@ class GitCommandManager { | |||
|       env[key] = this.gitEnv[key] | ||||
|     } | ||||
| 
 | ||||
|     const stdout: string[] = [] | ||||
|     const defaultListener = { | ||||
|       stdout: (data: Buffer) => { | ||||
|         stdout.push(data.toString()) | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     const mergedListeners = {...defaultListener, ...customListeners} | ||||
| 
 | ||||
|     const stdout: string[] = [] | ||||
|     const options = { | ||||
|       cwd: this.workingDirectory, | ||||
|       env, | ||||
|       silent, | ||||
|       ignoreReturnCode: allowAllExitCodes, | ||||
|       listeners: { | ||||
|         stdout: (data: Buffer) => { | ||||
|           stdout.push(data.toString()) | ||||
|         } | ||||
|       } | ||||
|       listeners: mergedListeners | ||||
|     } | ||||
| 
 | ||||
|     result.exitCode = await exec.exec(`"${this.gitPath}"`, args, options) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Vallie Joseph
						Vallie Joseph