Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branch list is not updated after a branch is deleted #1096

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/BranchMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ export class BranchMenu extends React.Component<
className={hiddenButtonStyle}
icon={trashIcon}
title={this.props.trans.__('Delete this branch locally')}
onClick={(event: React.MouseEvent) => {
onClick={async (event: React.MouseEvent) => {
event.stopPropagation();
this._onDeleteBranch(branch.name);
await this._onDeleteBranch(branch.name);
}}
/>
<ActionButton
Expand Down
16 changes: 12 additions & 4 deletions src/components/GitPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,11 @@ export class GitPanel extends React.Component<IGitPanelProps, IGitPanelState> {
nCommitsBehind: model.status.behind
});
}, this);
model.branchesChanged.connect(async () => {
await this.refreshBranches();
}, this);
model.headChanged.connect(async () => {
await this.refreshBranch();
await this.refreshCurrentBranch();
if (this.state.tab === 1) {
this.refreshHistory();
}
Expand Down Expand Up @@ -215,11 +218,16 @@ export class GitPanel extends React.Component<IGitPanelProps, IGitPanelState> {
Signal.clearData(this);
}

refreshBranch = async (): Promise<void> => {
refreshBranches = async (): Promise<void> => {
this.setState({
branches: this.props.model.branches
});
};

refreshCurrentBranch = async (): Promise<void> => {
const { currentBranch } = this.props.model;

this.setState({
branches: this.props.model.branches,
currentBranch: currentBranch ? currentBranch.name : 'master'
});
};
Expand All @@ -246,7 +254,7 @@ export class GitPanel extends React.Component<IGitPanelProps, IGitPanelState> {
*/
refreshView = async (): Promise<void> => {
if (this.props.model.pathRepository !== null) {
await this.refreshBranch();
await this.refreshBranches();
await this.refreshHistory();
}
};
Expand Down
24 changes: 22 additions & 2 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IChangedArgs, PathExt, URLExt } from '@jupyterlab/coreutils';
import { IDocumentManager } from '@jupyterlab/docmanager';
import { DocumentRegistry } from '@jupyterlab/docregistry';
import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { JSONObject } from '@lumino/coreutils';
import { JSONExt, JSONObject } from '@lumino/coreutils';
import { Poll } from '@lumino/polling';
import { ISignal, Signal } from '@lumino/signaling';
import { requestAPI } from './git';
Expand Down Expand Up @@ -206,6 +206,13 @@ export class GitExtension implements IGitExtension {
return this._status;
}

/**
* A signal emitted when the branches of the Git repository changes.
*/
get branchesChanged(): ISignal<IGitExtension, void> {
return this._branchesChanged;
}

/**
* A signal emitted when the `HEAD` of the Git repository changes.
*/
Expand Down Expand Up @@ -912,7 +919,12 @@ export class GitExtension implements IGitExtension {
this._currentBranch.top_commit !== data.current_branch.top_commit;
}

this._branches = data.branches;
const branchesChanged = !JSONExt.deepEqual(
this._branches as any,
(data.branches ?? []) as any
);

this._branches = data.branches ?? [];
this._currentBranch = data.current_branch;
if (this._currentBranch) {
// Set up the marker obj for the current (valid) repo/branch combination
Expand All @@ -921,6 +933,9 @@ export class GitExtension implements IGitExtension {
if (headChanged) {
this._headChanged.emit();
}
if (branchesChanged) {
this._branchesChanged.emit();
}

// Start fetch remotes if the repository has remote branches
const hasRemote = this._branches.some(branch => branch.is_remote_branch);
Expand All @@ -930,13 +945,17 @@ export class GitExtension implements IGitExtension {
this._fetchPoll.stop();
}
} catch (error) {
const branchesChanged = this._branches.length > 0;
const headChanged = this._currentBranch !== null;
this._branches = [];
this._currentBranch = null;
this._fetchPoll.stop();
if (headChanged) {
this._headChanged.emit();
}
if (branchesChanged) {
this._branchesChanged.emit();
}

if (!(error instanceof Git.NotInRepository)) {
throw error;
Expand Down Expand Up @@ -1610,6 +1629,7 @@ export class GitExtension implements IGitExtension {
private _selectedHistoryFile: Git.IStatusFile | null = null;
private _hasDirtyStagedFiles = false;

private _branchesChanged = new Signal<IGitExtension, void>(this);
private _headChanged = new Signal<IGitExtension, void>(this);
private _markChanged = new Signal<IGitExtension, void>(this);
private _selectedHistoryFileChanged = new Signal<
Expand Down
5 changes: 5 additions & 0 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export interface IGitExtension extends IDisposable {
*/
currentBranch: Git.IBranch;

/**
* A signal emitted when the branches of the Git repository changes.
*/
readonly branchesChanged: ISignal<IGitExtension, void>;

/**
* A signal emitted when the `HEAD` of the Git repository changes.
*/
Expand Down
3 changes: 3 additions & 0 deletions tests/test-components/GitPanel.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ describe('GitPanel', () => {
} as any;
props.model = {
branches: [],
branchesChanged: {
connect: jest.fn()
},
headChanged: {
connect: jest.fn()
},
Expand Down