Skip to content

Commit 75362a6

Browse files
authored
Git - add settings to control the branch protection indicator (microsoft#152469)
* Add settings to control the branch protection indicator * Pull request feedback
1 parent 453ddc2 commit 75362a6

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

extensions/git/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,25 @@
18931893
"default": [],
18941894
"scope": "resource"
18951895
},
1896+
"git.branchProtectionIndicator": {
1897+
"type": "object",
1898+
"additionalProperties": false,
1899+
"description": "%config.branchProtectionIndicator%",
1900+
"properties": {
1901+
"quickOpen": {
1902+
"type": "boolean",
1903+
"description": "%config.branchProtectionIndicator.quickOpen%"
1904+
},
1905+
"statusBar": {
1906+
"type": "boolean",
1907+
"description": "%config.branchProtectionIndicator.statusBar%"
1908+
}
1909+
},
1910+
"default": {
1911+
"quickOpen": true,
1912+
"statusBar": true
1913+
}
1914+
},
18961915
"git.branchProtectionPrompt": {
18971916
"type": "string",
18981917
"description": "%config.branchProtectionPrompt%",

extensions/git/package.nls.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@
122122
"config.checkoutType.remote": "Remote branches",
123123
"config.branchPrefix": "Prefix used when creating a new branch.",
124124
"config.branchProtection": "List of protected branches. By default, a prompt is shown before changes are committed to a protected branch. The prompt can be controlled using the `#git.branchProtectionPrompt#` setting.",
125+
"config.branchProtectionIndicator": "Controls whether an indicator is being displayed for a protected branch.",
126+
"config.branchProtectionIndicator.quickOpen": "Display an indicator in the quick open.",
127+
"config.branchProtectionIndicator.statusBar": "Display an indicator in the status bar.",
125128
"config.branchProtectionPrompt": "Controls whether a prompt is being before changes are committed to a protected branch.",
126129
"config.branchProtectionPrompt.alwaysCommit": "Always commit changes to the protected branch.",
127130
"config.branchProtectionPrompt.alwaysCommitToNewBranch": "Always commit changes to a new branch.",

extensions/git/src/commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const localize = nls.loadMessageBundle();
2626
class CheckoutItem implements QuickPickItem {
2727

2828
protected get shortCommit(): string { return (this.ref.commit || '').substr(0, 8); }
29-
get label(): string { return this.ref.name ? `${this.ref.name}${this.repository.isBranchProtected(this.ref.name) ? ' $(lock-small)' : ''}` : this.shortCommit; }
29+
get label(): string { return this.ref.name ? `${this.ref.name}${this.repository.isBranchProtected(this.ref.name, 'quickOpen') ? ' $(lock-small)' : ''}` : this.shortCommit; }
3030
get description(): string { return this.shortCommit; }
3131

3232
constructor(protected repository: Repository, protected ref: Ref) { }

extensions/git/src/repository.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,9 @@ export class Repository implements Disposable {
941941
}, undefined, this.disposables);
942942

943943
filterEvent(workspace.onDidChangeConfiguration, e =>
944-
e.affectsConfiguration('git.branchSortOrder', root)
944+
e.affectsConfiguration('git.branchProtection', root)
945+
|| e.affectsConfiguration('git.branchProtectionIndicator', root)
946+
|| e.affectsConfiguration('git.branchSortOrder', root)
945947
|| e.affectsConfiguration('git.untrackedChanges', root)
946948
|| e.affectsConfiguration('git.ignoreSubmodules', root)
947949
|| e.affectsConfiguration('git.openDiffOnClick', root)
@@ -2228,7 +2230,17 @@ export class Repository implements Disposable {
22282230
}
22292231
}
22302232

2231-
public isBranchProtected(name: string = this.HEAD?.name ?? ''): boolean {
2233+
public isBranchProtected(name: string = this.HEAD?.name ?? '', indicator?: 'quickOpen' | 'statusBar'): boolean {
2234+
if (indicator) {
2235+
const scopedConfig = workspace.getConfiguration('git', Uri.file(this.repository.root));
2236+
const branchProtectionIndicator = scopedConfig.get<{ quickOpen: boolean; statusBar: boolean }>('branchProtectionIndicator', { quickOpen: true, statusBar: true });
2237+
2238+
if ((indicator === 'quickOpen' && !branchProtectionIndicator.quickOpen) ||
2239+
(indicator === 'statusBar' && !branchProtectionIndicator.statusBar)) {
2240+
return false;
2241+
}
2242+
}
2243+
22322244
return this.isBranchProtectedMatcher ? this.isBranchProtectedMatcher(name) : false;
22332245
}
22342246

extensions/git/src/statusbar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class CheckoutStatusBar {
2424

2525
get command(): Command | undefined {
2626
const rebasing = !!this.repository.rebaseCommit;
27-
const isBranchProtected = this.repository.isBranchProtected();
28-
const title = `$(git-branch) ${this.repository.headLabel}${rebasing ? ` (${localize('rebasing', 'Rebasing')})` : ''}${isBranchProtected ? ' $(lock-small)' : ''}`;
27+
const isBranchProtected = this.repository.isBranchProtected(undefined, 'statusBar');
28+
const title = `${isBranchProtected ? '$(lock)' : '$(git-branch)'} ${this.repository.headLabel}${rebasing ? ` (${localize('rebasing', 'Rebasing')})` : ''}`;
2929

3030
return {
3131
command: 'git.checkout',

0 commit comments

Comments
 (0)