Skip to content

Commit 5cbb76b

Browse files
nzaytsevd13
authored andcommitted
Adds create branch button to the commit graph
1 parent 7cc3ceb commit 5cbb76b

File tree

8 files changed

+129
-6
lines changed

8 files changed

+129
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1313
- Adds a new `${authorFirst}` and `${authorLast}` commit formatting tokens that can be used in inline blame, commit hovers, etc — closes [#2980](https://github.com/gitkraken/vscode-gitlens/issues/2980)
1414
- Adds a way to force push from the Graph
1515
- Adds a new `gitlens.launchpad.includedOrganizations` setting to specify which organizations to include in _Launchpad_ — closes [#3550](https://github.com/gitkraken/vscode-gitlens/issues/3550)
16+
- Adds create branch button to the commit graph — closes [#3553](https://github.com/gitkraken/vscode-gitlens/issues/3553)
1617

1718
### Changed
1819

src/commands/git/branch.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ export class BranchGitCommand extends QuickCommand {
155155

156156
switch (args?.state.subcommand) {
157157
case 'create':
158+
if (args.state.flags != null) {
159+
counter++;
160+
}
161+
158162
if (args.state.reference != null) {
159163
counter++;
160164
}

src/commands/gitWizard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class GitWizardCommand extends QuickWizardCommandBase {
9393
) {
9494
switch (context.command) {
9595
case Commands.GitCommandsBranch:
96-
return this.execute({ command: 'branch' });
96+
return this.execute({ command: 'branch', ...args });
9797
case Commands.GitCommandsBranchCreate:
9898
return this.execute({ command: 'branch', state: { subcommand: 'create' } });
9999
case Commands.GitCommandsBranchDelete:

src/plus/webviews/graph/graphWebview.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2428,7 +2428,16 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
24282428
selectedRepository: this.repository.path,
24292429
selectedRepositoryVisibility: visibility,
24302430
branchesVisibility: refsVisibility.branchesVisibility,
2431-
branchName: branch?.name,
2431+
branch: branch && {
2432+
name: branch.name,
2433+
ref: branch.ref,
2434+
refType: branch.refType,
2435+
remote: branch.remote,
2436+
repoPath: branch.repoPath,
2437+
sha: branch.sha,
2438+
id: branch.id,
2439+
upstream: branch.upstream,
2440+
},
24322441
branchState: branchState,
24332442
lastFetched: new Date(getSettledValue(lastFetchedResult)!),
24342443
selectedRows: this._selectedRows,

src/plus/webviews/graph/protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export interface State extends WebviewState {
9595
selectedRepository?: string;
9696
selectedRepositoryVisibility?: RepositoryVisibility;
9797
branchesVisibility?: GraphBranchesVisibility;
98-
branchName?: string;
98+
branch?: GitBranchReference;
9999
branchState?: BranchState;
100100
lastFetched?: Date;
101101
selectedRows?: GraphSelectedRows;

src/webviews/apps/plus/graph/GraphWrapper.tsx

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { SlOption, SlSelect } from '@shoelace-style/shoelace/dist/react';
1919
import type { FormEvent, MouseEvent, ReactElement } from 'react';
2020
import React, { createElement, useEffect, useMemo, useRef, useState } from 'react';
2121
import type { ConnectCloudIntegrationsCommandArgs } from '../../../../commands/cloudIntegrations';
22+
import type { BranchGitCommandArgs } from '../../../../commands/git/branch';
2223
import type { DateStyle, GraphBranchesVisibility } from '../../../../config';
2324
import type { Commands } from '../../../../constants.commands';
2425
import type { SearchQuery } from '../../../../constants.search';
@@ -269,7 +270,7 @@ export function GraphWrapper({
269270
const [pagingHasMore, setPagingHasMore] = useState(state.paging?.hasMore ?? false);
270271
const [isLoading, setIsLoading] = useState(state.loading);
271272
const [styleProps, setStyleProps] = useState(state.theming);
272-
const [branchName, setBranchName] = useState(state.branchName);
273+
const [branch, setBranch] = useState(state.branch);
273274
const [lastFetched, setLastFetched] = useState(state.lastFetched);
274275
const [windowFocused, setWindowFocused] = useState(state.windowFocused);
275276
const [allowed, setAllowed] = useState(state.allowed ?? false);
@@ -287,6 +288,7 @@ export function GraphWrapper({
287288
const [workingTreeStats, setWorkingTreeStats] = useState(
288289
state.workingTreeStats ?? { added: 0, modified: 0, deleted: 0 },
289290
);
291+
const branchName = branch?.name;
290292

291293
const minimap = useRef<GlGraphMinimapContainer | undefined>(undefined);
292294
const hover = useRef<GlGraphHover | undefined>(undefined);
@@ -388,7 +390,7 @@ export function GraphWrapper({
388390
if (!themingChanged) {
389391
setStyleProps(state.theming);
390392
}
391-
setBranchName(state.branchName);
393+
setBranch(state.branch);
392394
setLastFetched(state.lastFetched);
393395
setColumns(state.columns);
394396
setRows(state.rows ?? []);
@@ -1144,6 +1146,96 @@ export function GraphWrapper({
11441146
)}
11451147
</div>
11461148
<div className="titlebar__group--last">
1149+
<span className="button-group">
1150+
<GlTooltip placement="bottom">
1151+
<a
1152+
className="action-button"
1153+
href={createCommandLink(Commands.GitCommandsBranch, {
1154+
args: {
1155+
state: { subcommand: 'create', flags: ['--switch'], reference: branch },
1156+
command: 'branch',
1157+
confirm: false,
1158+
} satisfies BranchGitCommandArgs,
1159+
})}
1160+
>
1161+
<span className="codicon codicon-git-branch-create action-button__icon"></span>
1162+
</a>
1163+
<span slot="content">
1164+
Create a branch from <i>{branchName}</i> and switch
1165+
</span>
1166+
</GlTooltip>
1167+
<GlTooltip placement="top" distance={7}>
1168+
<PopMenu position="right">
1169+
<button
1170+
type="button"
1171+
className="action-button"
1172+
slot="trigger"
1173+
aria-label="Minimap Options"
1174+
>
1175+
<span
1176+
className="codicon codicon-chevron-down action-button__more"
1177+
aria-hidden="true"
1178+
></span>
1179+
</button>
1180+
<MenuList slot="content" id="create-branch">
1181+
<MenuLabel>Create branch options</MenuLabel>
1182+
<MenuItem>
1183+
<a href={createCommandLink(Commands.GitCommandsBranchCreate)}>
1184+
Create Branch...
1185+
</a>
1186+
</MenuItem>
1187+
<MenuItem>
1188+
<a
1189+
href={createCommandLink(Commands.GitCommandsBranch, {
1190+
args: {
1191+
command: 'branch',
1192+
confirm: false,
1193+
state: { flags: [], reference: branch, subcommand: 'create' },
1194+
} satisfies BranchGitCommandArgs,
1195+
})}
1196+
>
1197+
Create Branch from <i>{branchName}</i>
1198+
</a>
1199+
</MenuItem>
1200+
<MenuItem>
1201+
<a
1202+
href={createCommandLink(Commands.GitCommandsBranch, {
1203+
args: {
1204+
command: 'branch',
1205+
confirm: false,
1206+
state: {
1207+
flags: ['--switch'],
1208+
reference: branch,
1209+
subcommand: 'create',
1210+
},
1211+
} satisfies BranchGitCommandArgs,
1212+
})}
1213+
>
1214+
Create from <i>{branchName}</i> & Switch to Branch
1215+
</a>
1216+
</MenuItem>
1217+
<MenuItem>
1218+
<a
1219+
href={createCommandLink(Commands.GitCommandsBranch, {
1220+
args: {
1221+
state: {
1222+
subcommand: 'create',
1223+
flags: ['--worktree'],
1224+
reference: branch,
1225+
},
1226+
command: 'branch',
1227+
confirm: false,
1228+
} satisfies BranchGitCommandArgs,
1229+
})}
1230+
>
1231+
Create Branch from <i>{branchName}</i> in New Worktree
1232+
</a>
1233+
</MenuItem>
1234+
</MenuList>
1235+
</PopMenu>
1236+
<span slot="content">Create branch options</span>
1237+
</GlTooltip>
1238+
</span>
11471239
<GlTooltip placement="bottom">
11481240
<a
11491241
href={`command:gitlens.showLaunchpad?${encodeURIComponent(

src/webviews/apps/plus/graph/graph.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ gl-feature-gate gl-feature-badge {
979979
&__header {
980980
flex: none;
981981
z-index: 101;
982-
width: fit-content;
982+
width: --webkit-fill-available;
983983
position: relative;
984984
}
985985

@@ -1197,6 +1197,14 @@ gl-feature-gate gl-feature-badge {
11971197
width: 1px;
11981198
}
11991199

1200+
menu-list#create-branch {
1201+
menu-item > a {
1202+
display: block;
1203+
color: var(--vscode-foreground);
1204+
text-decoration: none;
1205+
}
1206+
}
1207+
12001208
#opts-popover {
12011209
font-size: var(--vscode-font-size);
12021210
font-family: var(--vscode-font-family);

src/webviews/apps/shared/codicons.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@
159159
.codicon-git-branch-create:before {
160160
content: '\ea68';
161161
}
162+
.codicon-git-branch-create:after {
163+
content: '\ea60';
164+
position: absolute;
165+
right: 0;
166+
bottom: 0px;
167+
font-size: 0.6em;
168+
line-height: normal;
169+
transform: translate(-50%, 0%);
170+
}
162171
.codicon-git-branch-delete:before {
163172
content: '\ea68';
164173
}

0 commit comments

Comments
 (0)