diff --git a/packages/uxpin-merge-cli/CHANGELOG.md b/packages/uxpin-merge-cli/CHANGELOG.md index db5809e3..66b4ffa2 100644 --- a/packages/uxpin-merge-cli/CHANGELOG.md +++ b/packages/uxpin-merge-cli/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [3.4.4] - 2024-08-06 + +- Handles cases when reference logs are empty and we can't determine that given commit is from the master/main or not + ## [3.4.3] - 2024-02-29 ### Added diff --git a/packages/uxpin-merge-cli/package.json b/packages/uxpin-merge-cli/package.json index d9a4b552..075bdb8f 100644 --- a/packages/uxpin-merge-cli/package.json +++ b/packages/uxpin-merge-cli/package.json @@ -1,6 +1,6 @@ { "name": "@uxpin/merge-cli", - "version": "3.4.3", + "version": "3.4.4", "description": "The Command-line tool integrates the Design System repository with: https://www.uxpin.com/merge", "repository": { "type": "git", diff --git a/packages/uxpin-merge-cli/src/steps/serialization/vcs/repositories/git/util/getBranchesAtCommit.ts b/packages/uxpin-merge-cli/src/steps/serialization/vcs/repositories/git/util/getBranchesAtCommit.ts index 1f2f8d64..736ae709 100644 --- a/packages/uxpin-merge-cli/src/steps/serialization/vcs/repositories/git/util/getBranchesAtCommit.ts +++ b/packages/uxpin-merge-cli/src/steps/serialization/vcs/repositories/git/util/getBranchesAtCommit.ts @@ -1,5 +1,10 @@ -import { SHORT_COMMIT_HASH_IDX } from '../../../../../../common/constants'; +import { + ALTERNATIVE_DEFAULT_BRANCH_NAME, + DEFAULT_BRANCH_NAME, + SHORT_COMMIT_HASH_IDX, +} from '../../../../../../common/constants'; import { execAsync } from '../../../../../../utils/child_process/execAsync'; +import { trim } from 'lodash'; const REMOTE_PREFIX_RGX = /^refs\/remotes\/[^\/]+\//; @@ -8,6 +13,7 @@ export async function getBranchesAtCommit(cwd: string, fullCommitHash: string): const currentShortHash: string = fullCommitHash.substring(0, SHORT_COMMIT_HASH_IDX); const rawReflogOutput: string = await execAsync('git reflog --all', { cwd }); + rawReflogOutput .split('\n') // Filter out HEAD, the commit in question, and keep only top-level current commits @@ -28,5 +34,17 @@ export async function getBranchesAtCommit(cwd: string, fullCommitHash: string): branches.add(branchName); }); + //reflog can be empty, we have to be sure that it's really non-master commit + if (!branches.has(DEFAULT_BRANCH_NAME) && !branches.has(ALTERNATIVE_DEFAULT_BRANCH_NAME)) { + const result = await execAsync(`git branch --contains ${fullCommitHash}`, { cwd }); + result.split('\n').forEach((l) => { + if (l.includes(DEFAULT_BRANCH_NAME)) { + branches.add(DEFAULT_BRANCH_NAME); + } else if (l.includes(ALTERNATIVE_DEFAULT_BRANCH_NAME)) { + branches.add(ALTERNATIVE_DEFAULT_BRANCH_NAME); + } + }); + } + return [...branches]; }