Skip to content

Commit 0c7477f

Browse files
committed
Adds publish branch button to graph actions
- Displays a "Publish Branch" action in the graph header when the active branch has no upstream - Scales button layouts gracefully during resizing by collapsing the publish label sequentially before the fetch label - Falls back to publishing the current branch when the command is triggered in the header without custom branch context - Improves fetch button layout styling and adds an accessible label Closes #5327
1 parent 842a9c7 commit 0c7477f

3 files changed

Lines changed: 95 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
2929
- Adds the ability to drop multiple commits from the _Commit Graph_ — select commits on the current branch, right-click, and choose _Drop Commits_ to remove them ([#5161](https://github.com/gitkraken/vscode-gitlens/issues/5161))
3030
- Adds the ability to reword a commit's message from the _Commit Graph_ — right-click a commit on the current branch and choose _Reword Commit_ ([#5161](https://github.com/gitkraken/vscode-gitlens/issues/5161))
3131
- Adds a _Modify Commits (Interactive Rebase)_ action to the _Commit Graph_ that opens the interactive rebase editor scoped from the selected commit(s) for squashing, rewording, reordering, dropping, and editing ([#5161](https://github.com/gitkraken/vscode-gitlens/issues/5161))
32+
- Adds a _Publish Branch_ action to the _Commit Graph_ header that appears when the current branch has no upstream — publishes (pushes and sets the upstream of) the current branch in one click, sitting just left of _Fetch_ and collapsing to its icon when the header is too narrow ([#5327](https://github.com/gitkraken/vscode-gitlens/issues/5327))
3233

3334
### Changed
3435

src/webviews/apps/plus/graph/actions/gitActionsButtons.ts

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,16 @@ export class GitActionsButtons extends LitElement {
3939
}
4040
4141
gl-fetch-button {
42-
flex-shrink: 1;
43-
min-width: 3.2rem;
42+
flex: 0 1 max-content;
43+
min-width: 3.1rem;
44+
}
45+
46+
/* Publish yields its label before Fetch loses a pixel, so the two collapse
47+
sequentially (publish → icon, then fetch → icon) instead of both shrinking
48+
halfway together and neither reaching its icon-only floor. */
49+
gl-publish-button {
50+
flex: 0 1000 max-content;
51+
min-width: 3.1rem;
4452
}
4553
4654
.wip-button {
@@ -142,6 +150,7 @@ export class GitActionsButtons extends LitElement {
142150
.fetchedText=${this.fetchedText}
143151
.branchName=${this.branchName}
144152
></gl-push-pull-button>
153+
<gl-publish-button .branchState=${this.branchState} .branchName=${this.branchName}></gl-publish-button>
145154
<gl-fetch-button
146155
.branchState=${this.branchState}
147156
.fetchedText=${this.fetchedText}
@@ -198,7 +207,9 @@ export class GlFetchButton extends LitElement {
198207
gl-popover.fetch-popover {
199208
display: block;
200209
min-width: 0;
210+
width: 100%;
201211
max-width: 100%;
212+
--gl-popover-anchor-width: 100%;
202213
}
203214
/* Use CSS Grid so the text column's min-content is 0,
204215
allowing the text to shrink and ellipsize without expanding
@@ -207,6 +218,8 @@ export class GlFetchButton extends LitElement {
207218
display: grid;
208219
grid-template-columns: auto minmax(0, 1fr);
209220
align-items: center;
221+
overflow: hidden;
222+
width: 100%;
210223
max-width: 100%;
211224
}
212225
.action-button__text {
@@ -336,7 +349,12 @@ export class GlFetchButton extends LitElement {
336349
override render() {
337350
return html`
338351
<gl-popover class="fetch-popover" placement="bottom" ?arrow=${false} distance=${4}>
339-
<a slot="anchor" href=${this._webview.createCommandLink('gitlens.fetch:')} class="action-button">
352+
<a
353+
slot="anchor"
354+
href=${this._webview.createCommandLink('gitlens.fetch:')}
355+
class="action-button"
356+
aria-label="Fetch"
357+
>
340358
<code-icon class="action-button__icon" icon="repo-fetch"></code-icon>
341359
<span class="action-button__text"
342360
><span class="action-button__label">Fetch</span>${this.fetchedTextShort
@@ -574,10 +592,77 @@ export class PushPullButton extends LitElement {
574592
}
575593
}
576594

595+
@customElement('gl-publish-button')
596+
export class GlPublishButton extends LitElement {
597+
static override styles = [
598+
linkBase,
599+
actionButton,
600+
css`
601+
:host {
602+
display: inline-flex;
603+
min-width: 0;
604+
max-width: 100%;
605+
}
606+
gl-tooltip {
607+
display: block;
608+
min-width: 0;
609+
width: 100%;
610+
max-width: 100%;
611+
}
612+
.action-button {
613+
display: grid;
614+
grid-template-columns: auto minmax(0, 1fr);
615+
align-items: center;
616+
overflow: hidden;
617+
width: 100%;
618+
max-width: 100%;
619+
}
620+
.publish-button__text {
621+
display: block;
622+
overflow: hidden;
623+
text-overflow: ellipsis;
624+
white-space: nowrap;
625+
}
626+
`,
627+
];
628+
629+
@consume({ context: webviewContext })
630+
private _webview!: WebviewContext;
631+
632+
@property({ type: Object })
633+
branchState?: BranchState;
634+
635+
@property({ type: String })
636+
branchName?: string;
637+
638+
override render() {
639+
// Only when the current branch has no upstream (unpublished)
640+
if (this.branchState == null || this.branchState.upstream != null) return nothing;
641+
642+
return html`
643+
<gl-tooltip placement="bottom">
644+
<a
645+
href=${this._webview.createCommandLink('gitlens.publishBranch:')}
646+
class="action-button"
647+
aria-label="Publish Branch"
648+
>
649+
<code-icon class="action-button__icon" icon="cloud-upload"></code-icon>
650+
<span class="publish-button__text">Publish Branch</span>
651+
</a>
652+
<span slot="content">
653+
Publish (push) ${this.branchName ? html`<strong>${this.branchName}</strong>` : 'this branch'} to a
654+
remote
655+
</span>
656+
</gl-tooltip>
657+
`;
658+
}
659+
}
660+
577661
declare global {
578662
interface HTMLElementTagNameMap {
579663
'gl-git-actions-buttons': GitActionsButtons;
580664
'gl-fetch-button': GlFetchButton;
665+
'gl-publish-button': GlPublishButton;
581666
'gl-push-pull-button': PushPullButton;
582667
}
583668
}

src/webviews/plus/graph/graphWebview.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8701,7 +8701,12 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
87018701
@command('gitlens.publishBranch:graph')
87028702
@debug()
87038703
private async publishBranch(item?: GraphItemContext | BranchRef) {
8704-
const ref = await this.resolveBranchRef(item);
8704+
let ref = await this.resolveBranchRef(item);
8705+
if (ref == null) {
8706+
// Header publish button passes no branch context — fall back to the current branch
8707+
const branch = await this.repository?.git.branches.getBranch();
8708+
ref = branch != null ? getReferenceFromBranch(branch) : undefined;
8709+
}
87058710
if (ref == null) return;
87068711

87078712
await RepoActions.push(ref.repoPath, undefined, ref);

0 commit comments

Comments
 (0)