Skip to content

Commit 445e890

Browse files
committed
fixes #386: removed overly agressive new/swtich branch disabling
1 parent 98a6cc9 commit 445e890

File tree

4 files changed

+22
-31
lines changed

4 files changed

+22
-31
lines changed

src/components/BranchHeader.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,23 @@ export class BranchHeader extends React.Component<
5050

5151
/** Switch current working branch */
5252
async switchBranch(branchName: string) {
53-
await this.props.model.checkout({ branchname: branchName });
53+
const result = await this.props.model.checkout({ branchname: branchName });
54+
if (result.code !== 0) {
55+
showErrorMessage('Error switching branch', result.message);
56+
}
57+
5458
this.toggleSelect();
5559
}
5660

5761
createNewBranch = async (branchName: string) => {
58-
await this.props.model.checkout({
62+
const result = await this.props.model.checkout({
5963
newBranch: true,
6064
branchname: branchName
6165
});
66+
if (result.code !== 0) {
67+
showErrorMessage('Error creating new branch', result.message);
68+
}
69+
6270
this.toggleNewBranchBox();
6371
};
6472

src/components/GitPanel.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export interface IGitSessionNodeState {
2626
stagedFiles: Git.IStatusFileResult[];
2727
unstagedFiles: Git.IStatusFileResult[];
2828
untrackedFiles: Git.IStatusFileResult[];
29-
hasChangedFiles: boolean;
3029

3130
isHistoryVisible: boolean;
3231
}
@@ -50,7 +49,6 @@ export class GitPanel extends React.Component<
5049
branches: [],
5150
currentBranch: '',
5251
upstreamBranch: '',
53-
hasChangedFiles: false,
5452
pastCommits: [],
5553
stagedFiles: [],
5654
unstagedFiles: [],
@@ -127,14 +125,9 @@ export class GitPanel extends React.Component<
127125
let stagedFiles = new Array<Git.IStatusFileResult>();
128126
let unstagedFiles = new Array<Git.IStatusFileResult>();
129127
let untrackedFiles = new Array<Git.IStatusFileResult>();
130-
let changedFiles = 0;
131128
let statusFiles = this.props.model.status;
132129
if (statusFiles.length > 0) {
133130
for (let i = 0; i < statusFiles.length; i++) {
134-
// If file has been changed
135-
if (statusFiles[i].x !== '?' && statusFiles[i].x !== '!') {
136-
changedFiles++;
137-
}
138131
// If file is untracked
139132
if (statusFiles[i].x === '?' && statusFiles[i].y === '?') {
140133
untrackedFiles.push(statusFiles[i]);
@@ -154,8 +147,7 @@ export class GitPanel extends React.Component<
154147
this.setState({
155148
stagedFiles: stagedFiles,
156149
unstagedFiles: unstagedFiles,
157-
untrackedFiles: untrackedFiles,
158-
hasChangedFiles: changedFiles > 0
150+
untrackedFiles: untrackedFiles
159151
});
160152
}
161153
};
@@ -218,11 +210,7 @@ export class GitPanel extends React.Component<
218210
upstreamBranch={this.state.upstreamBranch}
219211
stagedFiles={this.state.stagedFiles}
220212
data={this.state.branches}
221-
// No uncommitted changed files, allow switching branches
222-
// No committed files ever, disable switching branches
223-
disabled={
224-
this.state.hasChangedFiles || this.state.pastCommits.length === 0
225-
}
213+
disabled={this.state.pastCommits.length === 0}
226214
toggleSidebar={this.toggleSidebar}
227215
sideBarExpanded={this.state.isHistoryVisible}
228216
/>

src/model.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -539,19 +539,15 @@ export class GitExtension implements IGitExtension, IDisposable {
539539
* If a filename is provided, check the file out
540540
* If nothing is provided, check all files out
541541
*/
542-
async checkout(options?: Git.ICheckoutOptions): Promise<Response> {
542+
async checkout(options?: Git.ICheckoutOptions): Promise<Git.ICheckoutResult> {
543543
await this.ready;
544544
const path = this.pathRepository;
545545

546546
if (path === null) {
547-
return Promise.resolve(
548-
new Response(
549-
JSON.stringify({
550-
code: -1,
551-
message: 'Not in a git repository.'
552-
})
553-
)
554-
);
547+
return Promise.resolve({
548+
code: -1,
549+
message: 'Not in a git repository.'
550+
});
555551
}
556552

557553
const body = {
@@ -587,7 +583,7 @@ export class GitExtension implements IGitExtension, IDisposable {
587583
} else {
588584
this.refreshStatus();
589585
}
590-
return response;
586+
return response.json();
591587
} catch (err) {
592588
throw new ServerConnection.NetworkError(err);
593589
}

src/tokens.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export interface IGitExtension {
132132
*
133133
* @param options Checkout options
134134
*/
135-
checkout(options?: Git.ICheckoutOptions): Promise<Response>;
135+
checkout(options?: Git.ICheckoutOptions): Promise<Git.ICheckoutResult>;
136136

137137
/**
138138
* Make request to commit all staged files in repository
@@ -270,9 +270,8 @@ export namespace Git {
270270
filename?: string;
271271
}
272272

273-
/** Interface for GitShowPrefix request result,
274-
* has the prefix path of a directory in a repository,
275-
* with respect to the root directory.
273+
/** Interface for GitCheckout request result.
274+
* For reporting errors in checkout
276275
*/
277276
export interface ICheckoutResult {
278277
code: number;
@@ -292,7 +291,7 @@ export namespace Git {
292291
}
293292

294293
/** Interface for GitBranch request result,
295-
* has the result of changing the current working branch
294+
* has the result of fetching info on all branches
296295
*/
297296
export interface IBranchResult {
298297
code: number;

0 commit comments

Comments
 (0)