Disable branch rename when it has integrated commits

This commit is contained in:
Mattias Granlund 2024-01-07 13:25:07 +01:00
parent 4381bdc196
commit f7c062eb7d
6 changed files with 24 additions and 20 deletions

View File

@ -70,6 +70,8 @@ export class Branch {
updatedAt!: Date;
}
export type CommitStatus = 'local' | 'remote' | 'integrated';
export class Commit {
id!: string;
author!: Author;
@ -87,6 +89,16 @@ export class Commit {
return !this.isRemote && !this.isIntegrated;
}
get status() {
if (!this.isIntegrated && !this.isRemote) {
return 'local';
} else if (!this.isIntegrated && this.isRemote) {
return 'remote';
} else if (this.isIntegrated) {
return 'integrated';
}
}
isParentOf(possibleChild: Commit) {
return possibleChild.parentIds.includes(this.id);
}

View File

@ -24,6 +24,10 @@
}>();
const aiGenEnabled = projectAiGenEnabled(projectId);
$: commits = branch.commits;
$: hasIntegratedCommits =
commits.length > 0 ? commits.some((c) => c.status == 'integrated') : false;
</script>
{#if visible}
@ -54,6 +58,7 @@
<ContextMenuSection>
<ContextMenuItem
label="Set branch name"
disabled={hasIntegratedCommits}
on:click={() => {
newRemoteName = branch.upstreamName || '';
visible = false;

View File

@ -1,10 +1,9 @@
<script lang="ts">
import type { BaseBranch, Branch } from '$lib/vbranches/types';
import type { BaseBranch, Branch, CommitStatus } from '$lib/vbranches/types';
import type { BranchController } from '$lib/vbranches/branchController';
import CommitListItem from './CommitListItem.svelte';
import type { GitHubService } from '$lib/github/service';
import CommitListHeader from './CommitListHeader.svelte';
import type { CommitType } from './commitList';
import CommitListFooter from './CommitListFooter.svelte';
import type { Project } from '$lib/backend/projects';
@ -12,23 +11,14 @@
export let base: BaseBranch | undefined | null;
export let project: Project;
export let branchController: BranchController;
export let type: CommitType;
export let type: CommitStatus;
export let githubService: GitHubService;
export let readonly: boolean;
let headerHeight: number;
$: headCommit = branch.commits[0];
$: commits = branch.commits.filter((c) => {
switch (type) {
case 'local':
return !c.isIntegrated && !c.isRemote;
case 'remote':
return !c.isIntegrated && c.isRemote;
case 'integrated':
return c.isIntegrated;
}
});
$: commits = branch.commits.filter((c) => c.status == type);
let expanded = true;
</script>

View File

@ -1,15 +1,14 @@
<script lang="ts">
import Button from '$lib/components/Button.svelte';
import type { BranchController } from '$lib/vbranches/branchController';
import type { BaseBranch, Branch } from '$lib/vbranches/types';
import type { BaseBranch, Branch, CommitStatus } from '$lib/vbranches/types';
import PushButton from './PushButton.svelte';
import type { CommitType } from './commitList';
import type { PullRequest } from '$lib/github/types';
import type { GitHubService } from '$lib/github/service';
import toast from 'svelte-french-toast';
export let branch: Branch;
export let type: CommitType;
export let type: CommitStatus;
export let readonly: boolean;
export let branchController: BranchController;
export let githubService: GitHubService;

View File

@ -1,10 +1,10 @@
<script lang="ts">
import Icon from '$lib/icons/Icon.svelte';
import type { CommitStatus } from '$lib/vbranches/types';
import { onMount } from 'svelte';
import type { CommitType } from './commitList';
export let expanded: boolean;
export let type: CommitType;
export let type: CommitStatus;
export let height: number | undefined;
let element: HTMLButtonElement | undefined = undefined;

View File

@ -1,7 +1,5 @@
import type { BaseBranch } from '$lib/vbranches/types';
export type CommitType = 'local' | 'remote' | 'integrated';
export function branchUrl(
target: BaseBranch | undefined | null,
upstreamBranchName: string | undefined