Skip to content

Commit

Permalink
#429 New extension and repository settings to control whether stashes…
Browse files Browse the repository at this point in the history
… are shown in the Git Graph View.
  • Loading branch information
mhutchie committed Dec 8, 2020
1 parent f62dce5 commit 82e475b
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 29 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,11 @@
"default": true,
"description": "Show Remote HEAD Symbolic References in Git Graph (e.g. \"origin/HEAD\")."
},
"git-graph.repository.showStashes": {
"type": "boolean",
"default": true,
"description": "Show Stashes in Git Graph by default. This can be overridden per repository in the Git Graph View's Repository Settings Widget."
},
"git-graph.repository.showTags": {
"type": "boolean",
"default": true,
Expand Down
7 changes: 7 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,13 @@ class Config {
return !!this.config.get('repository.showRemoteHeads', true);
}

/**
* Get the value of the `git-graph.repository.showStashes` Extension Setting.
*/
get showStashes() {
return !!this.config.get('repository.showStashes', true);
}

/**
* Get the value of the `git-graph.repository.showTags` Extension Setting.
*/
Expand Down
5 changes: 3 additions & 2 deletions src/dataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,15 @@ export class DataSource extends Disposable {
* Get the high-level information of a repository.
* @param repo The path of the repository.
* @param showRemoteBranches Are remote branches shown.
* @param showStashes Are stashes shown.
* @param hideRemotes An array of hidden remotes.
* @returns The repositories information.
*/
public getRepoInfo(repo: string, showRemoteBranches: boolean, hideRemotes: ReadonlyArray<string>): Promise<GitRepoInfo> {
public getRepoInfo(repo: string, showRemoteBranches: boolean, showStashes: boolean, hideRemotes: ReadonlyArray<string>): Promise<GitRepoInfo> {
return Promise.all([
this.getBranches(repo, showRemoteBranches, hideRemotes),
this.getRemotes(repo),
this.getStashes(repo)
showStashes ? this.getStashes(repo) : Promise.resolve([])
]).then((results) => {
return { branches: results[0].branches, head: results[0].head, remotes: results[1], stashes: results[2], error: null };
}).catch((errorMessage) => {
Expand Down
1 change: 1 addition & 0 deletions src/extensionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const DEFAULT_REPO_STATE: GitRepoState = {
pullRequestConfig: null,
showRemoteBranches: true,
showRemoteBranchesV2: BooleanOverride.Default,
showStashes: BooleanOverride.Default,
showTags: BooleanOverride.Default
};

Expand Down
3 changes: 2 additions & 1 deletion src/gitGraphView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ export class GitGraphView extends Disposable {
break;
case 'loadRepoInfo':
this.loadRepoInfoRefreshId = msg.refreshId;
let repoInfo = await this.dataSource.getRepoInfo(msg.repo, msg.showRemoteBranches, msg.hideRemotes), isRepo = true;
let repoInfo = await this.dataSource.getRepoInfo(msg.repo, msg.showRemoteBranches, msg.showStashes, msg.hideRemotes), isRepo = true;
if (repoInfo.error) {
// If an error occurred, check to make sure the repo still exists
isRepo = (await this.dataSource.repoRoot(msg.repo)) !== null;
Expand Down Expand Up @@ -647,6 +647,7 @@ export class GitGraphView extends Disposable {
referenceLabels: config.referenceLabels,
repoDropdownOrder: config.repoDropdownOrder,
showRemoteBranches: config.showRemoteBranches,
showStashes: config.showStashes,
showTags: config.showTags
},
lastActiveRepo: this.extensionState.getLastActiveRepo(),
Expand Down
10 changes: 10 additions & 0 deletions src/repoManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ export namespace ExternalRepoConfig {
onRepoLoadShowSpecificBranches?: string[];
pullRequestConfig?: PullRequestConfig;
showRemoteBranches?: boolean;
showStashes?: boolean;
showTags?: boolean;
exportedAt?: number;
}
Expand Down Expand Up @@ -849,6 +850,9 @@ function generateExternalConfigFile(state: GitRepoState): Readonly<ExternalRepoC
if (state.showRemoteBranchesV2 !== BooleanOverride.Default) {
file.showRemoteBranches = state.showRemoteBranchesV2 === BooleanOverride.Enabled;
}
if (state.showStashes !== BooleanOverride.Default) {
file.showStashes = state.showStashes === BooleanOverride.Enabled;
}
if (state.showTags !== BooleanOverride.Default) {
file.showTags = state.showTags === BooleanOverride.Enabled;
}
Expand Down Expand Up @@ -913,6 +917,9 @@ function validateExternalConfigFile(file: Readonly<ExternalRepoConfig.File>) {
if (typeof file.showRemoteBranches !== 'undefined' && typeof file.showRemoteBranches !== 'boolean') {
return 'showRemoteBranches';
}
if (typeof file.showStashes !== 'undefined' && typeof file.showStashes !== 'boolean') {
return 'showStashes';
}
if (typeof file.showTags !== 'undefined' && typeof file.showTags !== 'boolean') {
return 'showTags';
}
Expand Down Expand Up @@ -1000,6 +1007,9 @@ function applyExternalConfigFile(file: Readonly<ExternalRepoConfig.File>, state:
if (typeof file.showRemoteBranches !== 'undefined') {
state.showRemoteBranchesV2 = file.showRemoteBranches ? BooleanOverride.Enabled : BooleanOverride.Disabled;
}
if (typeof file.showStashes !== 'undefined') {
state.showStashes = file.showStashes ? BooleanOverride.Enabled : BooleanOverride.Disabled;
}
if (typeof file.showTags !== 'undefined') {
state.showTags = file.showTags ? BooleanOverride.Enabled : BooleanOverride.Disabled;
}
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export interface GitRepoState {
pullRequestConfig: PullRequestConfig | null;
showRemoteBranches: boolean;
showRemoteBranchesV2: BooleanOverride;
showStashes: BooleanOverride;
showTags: BooleanOverride;
}

Expand Down Expand Up @@ -241,6 +242,7 @@ export interface GitGraphViewConfig {
readonly referenceLabels: ReferenceLabelsConfig;
readonly repoDropdownOrder: RepoDropdownOrder;
readonly showRemoteBranches: boolean;
readonly showStashes: boolean;
readonly showTags: boolean;
}

Expand Down Expand Up @@ -888,6 +890,7 @@ export interface RequestLoadRepoInfo extends RepoRequest {
readonly command: 'loadRepoInfo';
readonly refreshId: number;
readonly showRemoteBranches: boolean;
readonly showStashes: boolean;
readonly hideRemotes: ReadonlyArray<string>;
}
export interface ResponseLoadRepoInfo extends ResponseWithErrorInfo {
Expand Down
2 changes: 2 additions & 0 deletions tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2610,6 +2610,8 @@ describe('Config', () => {

describe('showRemoteHeads', testBooleanExtensionSetting('showRemoteHeads', 'repository.showRemoteHeads', true));

describe('showStashes', testBooleanExtensionSetting('showStashes', 'repository.showStashes', true));

describe('showTags', testRenamedBooleanExtensionSetting('showTags', 'repository.showTags', 'showTags', true));

describe('showUncommittedChanges', testRenamedBooleanExtensionSetting('showUncommittedChanges', 'repository.showUncommittedChanges', 'showUncommittedChanges', true));
Expand Down
48 changes: 36 additions & 12 deletions tests/dataSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('DataSource', () => {
vscode.mockExtensionSettingReturnValue('repository.showRemoteHeads', true);

// Run
const result = await dataSource.getRepoInfo('/path/to/repo', true, []);
const result = await dataSource.getRepoInfo('/path/to/repo', true, true, []);

// Assert
expect(result).toStrictEqual({
Expand Down Expand Up @@ -162,7 +162,7 @@ describe('DataSource', () => {
expect(spyOnSpawn).toBeCalledWith('/path/to/git', ['reflog', '--format=%HXX7Nal-YARtTpjCikii9nJxER19D6diSyk-AWkPb%PXX7Nal-YARtTpjCikii9nJxER19D6diSyk-AWkPb%gDXX7Nal-YARtTpjCikii9nJxER19D6diSyk-AWkPb%anXX7Nal-YARtTpjCikii9nJxER19D6diSyk-AWkPb%aeXX7Nal-YARtTpjCikii9nJxER19D6diSyk-AWkPb%atXX7Nal-YARtTpjCikii9nJxER19D6diSyk-AWkPb%s', 'refs/stash', '--'], expect.objectContaining({ cwd: '/path/to/repo' }));
});

it('Should return the repository info (when show remote branches is FALSE)', async () => {
it('Should return the repository info (when showRemoteBranches is FALSE)', async () => {
// Setup
mockGitSuccessOnce(
'* develop\n' +
Expand All @@ -173,7 +173,7 @@ describe('DataSource', () => {
vscode.mockExtensionSettingReturnValue('repository.showRemoteHeads', true);

// Run
const result = await dataSource.getRepoInfo('/path/to/repo', false, []);
const result = await dataSource.getRepoInfo('/path/to/repo', false, true, []);

// Assert
expect(result).toStrictEqual({
Expand Down Expand Up @@ -205,7 +205,7 @@ describe('DataSource', () => {
onDidChangeConfiguration.emit({
affectsConfiguration: (section) => section === 'git-graph.date.type'
});
const result = await dataSource.getRepoInfo('/path/to/repo', false, []);
const result = await dataSource.getRepoInfo('/path/to/repo', false, true, []);

// Assert
expect(result).toStrictEqual({
Expand Down Expand Up @@ -237,7 +237,7 @@ describe('DataSource', () => {
onDidChangeConfiguration.emit({
affectsConfiguration: (section) => section === 'git-graph.dateType'
});
const result = await dataSource.getRepoInfo('/path/to/repo', false, []);
const result = await dataSource.getRepoInfo('/path/to/repo', false, true, []);

// Assert
expect(result).toStrictEqual({
Expand Down Expand Up @@ -269,7 +269,7 @@ describe('DataSource', () => {
onDidChangeConfiguration.emit({
affectsConfiguration: (section) => section === 'git-graph.repository.useMailmap'
});
const result = await dataSource.getRepoInfo('/path/to/repo', false, []);
const result = await dataSource.getRepoInfo('/path/to/repo', false, true, []);

// Assert
expect(result).toStrictEqual({
Expand Down Expand Up @@ -301,7 +301,7 @@ describe('DataSource', () => {
onDidChangeConfiguration.emit({
affectsConfiguration: (section) => section === 'git-graph.useMailmap'
});
const result = await dataSource.getRepoInfo('/path/to/repo', false, []);
const result = await dataSource.getRepoInfo('/path/to/repo', false, true, []);

// Assert
expect(result).toStrictEqual({
Expand All @@ -316,6 +316,30 @@ describe('DataSource', () => {
expect(spyOnSpawn).toBeCalledWith('/path/to/git', ['reflog', '--format=%HXX7Nal-YARtTpjCikii9nJxER19D6diSyk-AWkPb%PXX7Nal-YARtTpjCikii9nJxER19D6diSyk-AWkPb%gDXX7Nal-YARtTpjCikii9nJxER19D6diSyk-AWkPb%aNXX7Nal-YARtTpjCikii9nJxER19D6diSyk-AWkPb%aEXX7Nal-YARtTpjCikii9nJxER19D6diSyk-AWkPb%atXX7Nal-YARtTpjCikii9nJxER19D6diSyk-AWkPb%s', 'refs/stash', '--'], expect.objectContaining({ cwd: '/path/to/repo' }));
});

it('Should return the repository info (showStashes is FALSE)', async () => {
// Setup
mockGitSuccessOnce(
'* develop\n' +
' master\n'
);
mockGitSuccessOnce('origin\n');

// Run
const result = await dataSource.getRepoInfo('/path/to/repo', true, false, []);

// Assert
expect(result).toStrictEqual({
branches: ['develop', 'master'],
head: 'develop',
remotes: ['origin'],
stashes: [],
error: null
});
expect(spyOnSpawn).toBeCalledWith('/path/to/git', ['branch', '-a', '--no-color'], expect.objectContaining({ cwd: '/path/to/repo' }));
expect(spyOnSpawn).toBeCalledWith('/path/to/git', ['remote'], expect.objectContaining({ cwd: '/path/to/repo' }));
expect(spyOnSpawn).toHaveBeenCalledTimes(2);
});

it('Should return the repository info (hidden remote and an invalid branch)', async () => {
// Setup
mockGitSuccessOnce(
Expand All @@ -330,7 +354,7 @@ describe('DataSource', () => {
vscode.mockExtensionSettingReturnValue('repository.showRemoteHeads', true);

// Run
const result = await dataSource.getRepoInfo('/path/to/repo', true, ['origin']);
const result = await dataSource.getRepoInfo('/path/to/repo', true, true, ['origin']);

// Assert
expect(result).toStrictEqual({
Expand Down Expand Up @@ -359,7 +383,7 @@ describe('DataSource', () => {
vscode.mockExtensionSettingReturnValue('repository.showRemoteHeads', false);

// Run
const result = await dataSource.getRepoInfo('/path/to/repo', true, []);
const result = await dataSource.getRepoInfo('/path/to/repo', true, true, []);

// Assert
expect(result).toStrictEqual({
Expand All @@ -382,7 +406,7 @@ describe('DataSource', () => {
vscode.mockExtensionSettingReturnValue('repository.showRemoteHeads', true);

// Run
const result = await dataSource.getRepoInfo('/path/to/repo', true, []);
const result = await dataSource.getRepoInfo('/path/to/repo', true, true, []);

// Assert
expect(result).toStrictEqual({
Expand All @@ -405,7 +429,7 @@ describe('DataSource', () => {
vscode.mockExtensionSettingReturnValue('repository.showRemoteHeads', true);

// Run
const result = await dataSource.getRepoInfo('/path/to/repo', true, []);
const result = await dataSource.getRepoInfo('/path/to/repo', true, true, []);

// Assert
expect(result).toStrictEqual({
Expand All @@ -428,7 +452,7 @@ describe('DataSource', () => {
vscode.mockExtensionSettingReturnValue('repository.showRemoteHeads', true);

// Run
const result = await dataSource.getRepoInfo('/path/to/repo', true, []);
const result = await dataSource.getRepoInfo('/path/to/repo', true, true, []);

// Assert
expect(result).toStrictEqual({
Expand Down
8 changes: 8 additions & 0 deletions tests/extensionState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ describe('ExtensionState', () => {
pullRequestConfig: null,
showRemoteBranches: true,
showRemoteBranchesV2: BooleanOverride.Enabled,
showStashes: BooleanOverride.Enabled,
showTags: BooleanOverride.Enabled
};
extensionContext.workspaceState.get.mockReturnValueOnce({
Expand Down Expand Up @@ -119,6 +120,7 @@ describe('ExtensionState', () => {
pullRequestConfig: null,
showRemoteBranches: true,
showRemoteBranchesV2: BooleanOverride.Default,
showStashes: BooleanOverride.Default,
showTags: BooleanOverride.Default
}
});
Expand Down Expand Up @@ -155,6 +157,7 @@ describe('ExtensionState', () => {
pullRequestConfig: null,
showRemoteBranches: true,
showRemoteBranchesV2: BooleanOverride.Default,
showStashes: BooleanOverride.Default,
showTags: BooleanOverride.Default
}
});
Expand Down Expand Up @@ -191,6 +194,7 @@ describe('ExtensionState', () => {
pullRequestConfig: null,
showRemoteBranches: false,
showRemoteBranchesV2: BooleanOverride.Disabled,
showStashes: BooleanOverride.Default,
showTags: BooleanOverride.Default
}
});
Expand Down Expand Up @@ -227,6 +231,7 @@ describe('ExtensionState', () => {
pullRequestConfig: null,
showRemoteBranches: false,
showRemoteBranchesV2: BooleanOverride.Default,
showStashes: BooleanOverride.Default,
showTags: BooleanOverride.Default
}
});
Expand Down Expand Up @@ -263,6 +268,7 @@ describe('ExtensionState', () => {
pullRequestConfig: null,
showRemoteBranches: true,
showRemoteBranchesV2: BooleanOverride.Enabled,
showStashes: BooleanOverride.Default,
showTags: BooleanOverride.Default
}
});
Expand Down Expand Up @@ -302,6 +308,7 @@ describe('ExtensionState', () => {
pullRequestConfig: null,
showRemoteBranches: true,
showRemoteBranchesV2: BooleanOverride.Default,
showStashes: BooleanOverride.Default,
showTags: BooleanOverride.Default
},
'/path/to/repo-2': {
Expand All @@ -321,6 +328,7 @@ describe('ExtensionState', () => {
pullRequestConfig: null,
showRemoteBranches: false,
showRemoteBranchesV2: BooleanOverride.Disabled,
showStashes: BooleanOverride.Default,
showTags: BooleanOverride.Default
}
});
Expand Down
Loading

0 comments on commit 82e475b

Please sign in to comment.