Skip to content

Commit db47230

Browse files
authored
Merge pull request #477 from telamonian/fix-disabling-branch-with-changes
followup #450: fixes behavior when `"disableBranchWithChanges": true`
2 parents b2f6ff8 + 099775d commit db47230

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/components/BranchHeader.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import {
1919
import { Git, IGitExtension } from '../tokens';
2020
import { NewBranchBox } from './NewBranchBox';
2121

22+
const CHANGES_ERR_MSG =
23+
'You have files with changes in current branch. Please commit or discard changed files before';
24+
2225
export interface IBranchHeaderState {
2326
dropdownOpen: boolean;
2427
showNewBranchBox: boolean;
@@ -79,7 +82,7 @@ export class BranchHeader extends React.Component<
7982
} else {
8083
showErrorMessage(
8184
'Switching branch disabled',
82-
'You have staged changes in current branch. Please commit / discard them before switching to another branch.'
85+
CHANGES_ERR_MSG + 'switching to another branch.'
8386
);
8487
}
8588
}
@@ -102,7 +105,7 @@ export class BranchHeader extends React.Component<
102105
} else {
103106
showErrorMessage(
104107
'Creating new branch disabled',
105-
'You have staged changes in current branch. Please commit / discard them before creating a new branch.'
108+
CHANGES_ERR_MSG + 'creating a new branch.'
106109
);
107110
}
108111
};

src/components/GitPanel.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ export class GitPanel extends React.Component<
188188
}
189189

190190
if (this.state.inGitRepository) {
191+
const disableBranchOps = Boolean(
192+
this.props.settings.composite['disableBranchWithChanges'] &&
193+
((this.state.unstagedFiles && this.state.unstagedFiles.length) ||
194+
(this.state.stagedFiles && this.state.stagedFiles.length))
195+
);
196+
191197
main = (
192198
<React.Fragment>
193199
<BranchHeader
@@ -197,12 +203,7 @@ export class GitPanel extends React.Component<
197203
upstreamBranch={this.state.upstreamBranch}
198204
stagedFiles={this.state.stagedFiles}
199205
data={this.state.branches}
200-
disabled={
201-
this.state.pastCommits.length === 0 ||
202-
(this.props.settings.composite[
203-
'disableBranchWithChanges'
204-
] as boolean)
205-
}
206+
disabled={disableBranchOps}
206207
toggleSidebar={this.toggleSidebar}
207208
sideBarExpanded={this.state.isHistoryVisible}
208209
/>

0 commit comments

Comments
 (0)