Merge pull request #3609 from gitbutlerapp/Fix-bug-where-sometimes-lock-commit-info-is-unavailable

Look up locked commit from remote commits as well
This commit is contained in:
Mattias Granlund 2024-04-25 19:22:11 +02:00 committed by GitHub
commit cac2b6a80b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 3 deletions

View File

@ -4,7 +4,7 @@
import LargeDiffMessage from './LargeDiffMessage.svelte'; import LargeDiffMessage from './LargeDiffMessage.svelte';
import { computeAddedRemovedByHunk } from '$lib/utils/metrics'; import { computeAddedRemovedByHunk } from '$lib/utils/metrics';
import { tooltip } from '$lib/utils/tooltip'; import { tooltip } from '$lib/utils/tooltip';
import { getLocalCommits } from '$lib/vbranches/contexts'; import { getLocalCommits, getRemoteCommits } from '$lib/vbranches/contexts';
import { getLockText } from '$lib/vbranches/tooltip'; import { getLockText } from '$lib/vbranches/tooltip';
import type { HunkSection, ContentSection } from '$lib/utils/fileSections'; import type { HunkSection, ContentSection } from '$lib/utils/fileSections';
@ -21,6 +21,9 @@
$: minWidth = getGutterMinWidth(maxLineNumber); $: minWidth = getGutterMinWidth(maxLineNumber);
const localCommits = isFileLocked ? getLocalCommits() : undefined; const localCommits = isFileLocked ? getLocalCommits() : undefined;
const remoteCommits = isFileLocked ? getRemoteCommits() : undefined;
const commits = isFileLocked ? ($localCommits || []).concat($remoteCommits || []) : undefined;
let alwaysShow = false; let alwaysShow = false;
function getGutterMinWidth(max: number) { function getGutterMinWidth(max: number) {
@ -52,10 +55,10 @@
<div class="indicators text-base-11"> <div class="indicators text-base-11">
<span class="added">+{added}</span> <span class="added">+{added}</span>
<span class="removed">-{removed}</span> <span class="removed">-{removed}</span>
{#if section.hunk.lockedTo && $localCommits} {#if section.hunk.lockedTo && commits}
<div <div
use:tooltip={{ use:tooltip={{
text: getLockText(section.hunk.lockedTo, $localCommits), text: getLockText(section.hunk.lockedTo, commits),
delay: 500 delay: 500
}} }}
> >

View File

@ -0,0 +1,4 @@
// If a value occurs > 1 times then all but one will fail this condition.
export function unique(value: any, index: number, array: any[]) {
return array.indexOf(value) === index;
}

View File

@ -1,3 +1,4 @@
import { unique } from '$lib/utils/filters';
import type { Commit } from './types'; import type { Commit } from './types';
export function getLockText(commitId: string[] | string, commits: Commit[]): string { export function getLockText(commitId: string[] | string, commits: Commit[]): string {
@ -6,6 +7,7 @@ export function getLockText(commitId: string[] | string, commits: Commit[]): str
const lockedIds = typeof commitId == 'string' ? [commitId] : (commitId as string[]); const lockedIds = typeof commitId == 'string' ? [commitId] : (commitId as string[]);
const descriptions = lockedIds const descriptions = lockedIds
.filter(unique)
.map((id) => { .map((id) => {
const commit = commits.find((commit) => commit.id == id); const commit = commits.find((commit) => commit.id == id);
const shortCommitId = commit?.id.slice(0, 7); const shortCommitId = commit?.id.slice(0, 7);