Skip to content

followup #450: fixes behavior when "disableBranchWithChanges": true #477

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

Merged
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
7 changes: 5 additions & 2 deletions src/components/BranchHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import {
import { Git, IGitExtension } from '../tokens';
import { NewBranchBox } from './NewBranchBox';

const CHANGES_ERR_MSG =
'You have files with changes in current branch. Please commit or discard changed files before';

export interface IBranchHeaderState {
dropdownOpen: boolean;
showNewBranchBox: boolean;
Expand Down Expand Up @@ -79,7 +82,7 @@ export class BranchHeader extends React.Component<
} else {
showErrorMessage(
'Switching branch disabled',
'You have staged changes in current branch. Please commit / discard them before switching to another branch.'
CHANGES_ERR_MSG + 'switching to another branch.'
);
}
}
Expand All @@ -102,7 +105,7 @@ export class BranchHeader extends React.Component<
} else {
showErrorMessage(
'Creating new branch disabled',
'You have staged changes in current branch. Please commit / discard them before creating a new branch.'
CHANGES_ERR_MSG + 'creating a new branch.'
);
}
};
Expand Down
13 changes: 7 additions & 6 deletions src/components/GitPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ export class GitPanel extends React.Component<
}

if (this.state.inGitRepository) {
const disableBranchOps = Boolean(
this.props.settings.composite['disableBranchWithChanges'] &&
((this.state.unstagedFiles && this.state.unstagedFiles.length) ||
(this.state.stagedFiles && this.state.stagedFiles.length))
);

main = (
<React.Fragment>
<BranchHeader
Expand All @@ -197,12 +203,7 @@ export class GitPanel extends React.Component<
upstreamBranch={this.state.upstreamBranch}
stagedFiles={this.state.stagedFiles}
data={this.state.branches}
disabled={
this.state.pastCommits.length === 0 ||
(this.props.settings.composite[
'disableBranchWithChanges'
] as boolean)
}
disabled={disableBranchOps}
toggleSidebar={this.toggleSidebar}
sideBarExpanded={this.state.isHistoryVisible}
/>
Expand Down