Skip to content

Commit

Permalink
Handles cases when reference logs are empty and we can not determine …
Browse files Browse the repository at this point in the history
…that given commit is from the master/main or not (#423)
  • Loading branch information
robhil authored Aug 6, 2024
1 parent 6d62ddd commit 1373890
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/uxpin-merge-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/uxpin-merge-cli/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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\/[^\/]+\//;

Expand All @@ -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
Expand All @@ -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];
}

0 comments on commit 1373890

Please sign in to comment.