From d4e6e22e932832260459e972c83fa76adca04a5c Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sat, 5 Aug 2023 00:26:02 -0600 Subject: [PATCH] feat: improve checking local branch history (#1436) Co-authored-by: GitHub Action --- dist/index.js | Bin 1688569 -> 1689532 bytes dist/index.js.map | Bin 1693342 -> 1694485 bytes src/utils.ts | 58 ++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/dist/index.js b/dist/index.js index 84f31c3b5216d88ce9af494e3c870bbf1b79c6bc..d38ab5699e45468aa232f1389cd3f72906c64263 100644 GIT binary patch delta 672 zcmey_p1!9)y6%(OHGTU%QNbv-@3=@;kn3%lp07Nw^;B^IYD*eXz*92QFgjzDkJxFxhzKW>DE~+ z+|wWI0df_#3UN(e5Dg@}{TTVDM_MpyO@9}|$fmEZtDBZzl$%&$tLmYyqmZCd4L7V- zPfw*9XsJkcne@f$k zFT_2)-dBic`Uw+J;pqyEqHIVGw$5bak}fRGOf3Pr6cHNqb{y~Y>MTZ68F=gfqYOQQ zCQp=in4V+DC^Y?e45PX@I7oGqfYFQM@aYHb7;B~{Br&p2k9#O6Fxgg>efo!qjBL~A z$1}3CSaa2CwlB?M1Y#y2W(HywAZ7((HXvpPVh$kY1Y#~A<_2OOAm#;PJ|N}?VgVo) c1Y#i|76xJwAQlB;F(4KPVu|fbvm`?z0mJ3tsQ>@~ delta 198 zcmdnfpZ>EwyN*PQy1IFZxv9GOc{!EpI@9;~F-lKo^kh!)$MvLip_X@F3U*NG}U_gtsF-4=^+J-LhY@2 zj6lo;#LPg<0>rF9%m&2lK+FNeoIuP4#N0s41H`;Q%m>8$Kr8^nfHAK1EDOvj$QV2T7Ufk20no|BoE(wpOsbP;dA5Z z_UWbkqviaV@o7o%Ike@wM7nc>6MHmf1wfESH(4X)L8EN(vjF zVfaFg+XkO0HaXMSyveI2W^m_n|KWswtCVKVN-=wQKXWQ~rOtj{y@|*BpW_!V$moUz zQJk$8=c=4J7Cv@C#kSWU!h9%YP)h^Px9;PYmHZWmLwyyKpJdxM6aK zV*PI5YML$l=m0$(%Jv^)J==r`%3YXB{MrvK?cWt)V;ypMeS@0$^a3X3!#Xo_wBf)0 z1Cy^n$Er)UxvNqDx1Y#S48MUveDDpzi)t5$K>Q>?fmZq+wpsuT%mzbNXo1d3csjf5K_Y8|PlS0Du4d+rE5m zV9~UW$(#On28-l$qt7f-?K{7)05K~NvjH(X5OV-AClGT1F*gwN05LBR^8qnG5DNgY bAP@@yu`m#e0I?_#ivh9t_MKlOVx9p2aF1%R diff --git a/src/utils.ts b/src/utils.ts index c57ba838..477e5a44 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -786,9 +786,58 @@ export const canDiffCommits = async ({ sha2: string diff: string }): Promise => { - const {exitCode, stderr} = await exec.getExecOutput( + 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( + 'git', + ['log', '--format=%H', `${mergeBase}..${sha2}`], + { + cwd, + ignoreReturnCode: true, + silent: !core.isDebug() + } + ) + + if (exitCode !== 0) { + core.warning(stderr || `Error checking commit history`) + return false + } + + 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 => { + const {exitCode, stdout} = await exec.getExecOutput( 'git', - ['diff', '--name-only', '--ignore-submodules=all', `${sha1}${diff}${sha2}`], + ['merge-base', sha1, sha2], { cwd, ignoreReturnCode: true, @@ -797,11 +846,10 @@ export const canDiffCommits = async ({ ) if (exitCode !== 0) { - core.warning(stderr || `Unable find merge base between ${sha1} and ${sha2}`) - return false + return null } - return true + return stdout.trim() } export const getDirnameMaxDepth = ({