feat: improve checking local branch history (#1436)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
		
							parent
							
								
									1e9cd5f299
								
							
						
					
					
						commit
						d4e6e22e93
					
				
							
								
								
									
										34
									
								
								dist/index.js
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										34
									
								
								dist/index.js
									
									
									
										generated
									
									
										vendored
									
									
								
							| @ -2198,18 +2198,48 @@ const getPreviousGitTag = ({ cwd }) => __awaiter(void 0, void 0, void 0, functio | |||||||
| }); | }); | ||||||
| exports.getPreviousGitTag = getPreviousGitTag; | exports.getPreviousGitTag = getPreviousGitTag; | ||||||
| const canDiffCommits = ({ cwd, sha1, sha2, diff }) => __awaiter(void 0, void 0, void 0, function* () { | const canDiffCommits = ({ cwd, sha1, sha2, diff }) => __awaiter(void 0, void 0, void 0, function* () { | ||||||
|     const { exitCode, stderr } = yield exec.getExecOutput('git', ['diff', '--name-only', '--ignore-submodules=all', `${sha1}${diff}${sha2}`], { |     if (diff === '...') { | ||||||
|  |         const mergeBase = yield getMergeBase(cwd, sha1, sha2); | ||||||
|  |         if (!mergeBase) { | ||||||
|  |             core.warning(`Unable to find merge base between ${sha1} and ${sha2}`); | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |         const { exitCode, stderr } = yield exec.getExecOutput('git', ['log', '--format=%H', `${mergeBase}..${sha2}`], { | ||||||
|             cwd, |             cwd, | ||||||
|             ignoreReturnCode: true, |             ignoreReturnCode: true, | ||||||
|             silent: !core.isDebug() |             silent: !core.isDebug() | ||||||
|         }); |         }); | ||||||
|         if (exitCode !== 0) { |         if (exitCode !== 0) { | ||||||
|         core.warning(stderr || `Unable find merge base between ${sha1} and ${sha2}`); |             core.warning(stderr || `Error checking commit history`); | ||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
|         return true; |         return true; | ||||||
|  |     } | ||||||
|  |     else { | ||||||
|  |         const { exitCode, stderr } = yield exec.getExecOutput('git', ['diff', '--quiet', sha1, sha2], { | ||||||
|  |             cwd, | ||||||
|  |             ignoreReturnCode: true, | ||||||
|  |             silent: !core.isDebug() | ||||||
|  |         }); | ||||||
|  |         if (exitCode !== 0) { | ||||||
|  |             core.warning(stderr || `Error checking commit history`); | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
| }); | }); | ||||||
| exports.canDiffCommits = canDiffCommits; | exports.canDiffCommits = canDiffCommits; | ||||||
|  | const getMergeBase = (cwd, sha1, sha2) => __awaiter(void 0, void 0, void 0, function* () { | ||||||
|  |     const { exitCode, stdout } = yield exec.getExecOutput('git', ['merge-base', sha1, sha2], { | ||||||
|  |         cwd, | ||||||
|  |         ignoreReturnCode: true, | ||||||
|  |         silent: !core.isDebug() | ||||||
|  |     }); | ||||||
|  |     if (exitCode !== 0) { | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |     return stdout.trim(); | ||||||
|  | }); | ||||||
| const getDirnameMaxDepth = ({ relativePath, dirNamesMaxDepth, excludeCurrentDir }) => { | const getDirnameMaxDepth = ({ relativePath, dirNamesMaxDepth, excludeCurrentDir }) => { | ||||||
|     const pathArr = (0, exports.getDirname)(relativePath).split(path.sep); |     const pathArr = (0, exports.getDirname)(relativePath).split(path.sep); | ||||||
|     const maxDepth = Math.min(dirNamesMaxDepth || pathArr.length, pathArr.length); |     const maxDepth = Math.min(dirNamesMaxDepth || pathArr.length, pathArr.length); | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								dist/index.js.map
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/index.js.map
									
									
									
										generated
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										52
									
								
								src/utils.ts
									
									
									
									
									
								
							
							
						
						
									
										52
									
								
								src/utils.ts
									
									
									
									
									
								
							| @ -786,9 +786,17 @@ export const canDiffCommits = async ({ | |||||||
|   sha2: string |   sha2: string | ||||||
|   diff: string |   diff: string | ||||||
| }): Promise<boolean> => { | }): Promise<boolean> => { | ||||||
|  |   if (diff === '...') { | ||||||
|  |     const mergeBase = await getMergeBase(cwd, sha1, sha2) | ||||||
|  | 
 | ||||||
|  |     if (!mergeBase) { | ||||||
|  |       core.warning(`Unable to find merge base between ${sha1} and ${sha2}`) | ||||||
|  |       return false | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     const {exitCode, stderr} = await exec.getExecOutput( |     const {exitCode, stderr} = await exec.getExecOutput( | ||||||
|       'git', |       'git', | ||||||
|     ['diff', '--name-only', '--ignore-submodules=all', `${sha1}${diff}${sha2}`], |       ['log', '--format=%H', `${mergeBase}..${sha2}`], | ||||||
|       { |       { | ||||||
|         cwd, |         cwd, | ||||||
|         ignoreReturnCode: true, |         ignoreReturnCode: true, | ||||||
| @ -797,11 +805,51 @@ export const canDiffCommits = async ({ | |||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
|     if (exitCode !== 0) { |     if (exitCode !== 0) { | ||||||
|     core.warning(stderr || `Unable find merge base between ${sha1} and ${sha2}`) |       core.warning(stderr || `Error checking commit history`) | ||||||
|       return false |       return false | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return true |     return true | ||||||
|  |   } else { | ||||||
|  |     const {exitCode, stderr} = await exec.getExecOutput( | ||||||
|  |       'git', | ||||||
|  |       ['diff', '--quiet', sha1, sha2], | ||||||
|  |       { | ||||||
|  |         cwd, | ||||||
|  |         ignoreReturnCode: true, | ||||||
|  |         silent: !core.isDebug() | ||||||
|  |       } | ||||||
|  |     ) | ||||||
|  | 
 | ||||||
|  |     if (exitCode !== 0) { | ||||||
|  |       core.warning(stderr || `Error checking commit history`) | ||||||
|  |       return false | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return true | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | const getMergeBase = async ( | ||||||
|  |   cwd: string, | ||||||
|  |   sha1: string, | ||||||
|  |   sha2: string | ||||||
|  | ): Promise<string | null> => { | ||||||
|  |   const {exitCode, stdout} = await exec.getExecOutput( | ||||||
|  |     'git', | ||||||
|  |     ['merge-base', sha1, sha2], | ||||||
|  |     { | ||||||
|  |       cwd, | ||||||
|  |       ignoreReturnCode: true, | ||||||
|  |       silent: !core.isDebug() | ||||||
|  |     } | ||||||
|  |   ) | ||||||
|  | 
 | ||||||
|  |   if (exitCode !== 0) { | ||||||
|  |     return null | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   return stdout.trim() | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export const getDirnameMaxDepth = ({ | export const getDirnameMaxDepth = ({ | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tonye Jack
						Tonye Jack