Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit d3c8b5b

Browse files
author
Michelle Tilley
authored
Merge pull request #709 from atom/mkt-just-cant-palette-these-errors
Show Git errors when running commands from command palette
2 parents 4a335ba + fb86d5e commit d3c8b5b

File tree

2 files changed

+72
-61
lines changed

2 files changed

+72
-61
lines changed

lib/controllers/status-bar-tile-controller.js

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33

4+
import {GitError} from '../git-shell-out-strategy';
45
import ObserveModelDecorator from '../decorators/observe-model';
56
import {BranchPropType, RemotePropType} from '../prop-types';
67
import BranchView from '../views/branch-view';
@@ -149,7 +150,6 @@ export default class StatusBarTileController extends React.Component {
149150
<PushPullMenuView
150151
onMarkSpecialClick={this.handleOpenGitTimingsView}
151152
workspace={this.props.workspace}
152-
notificationManager={this.props.notificationManager}
153153
inProgress={this.state.inProgress}
154154
push={this.push}
155155
pull={this.pull}
@@ -186,25 +186,89 @@ export default class StatusBarTileController extends React.Component {
186186
});
187187
}
188188

189+
async attemptGitOperation(operation, errorTransform = message => ({message})) {
190+
const operationPromise = operation();
191+
try {
192+
return await operationPromise;
193+
} catch (error) {
194+
if (!(error instanceof GitError)) { throw error; }
195+
const {message, description} = errorTransform(error.stdErr);
196+
this.props.notificationManager.addError(
197+
message || 'Cannot complete remote interaction',
198+
{description, dismissable: true},
199+
);
200+
return null;
201+
}
202+
}
203+
189204
@autobind
190205
checkout(branchName, options) {
191206
return this.setInProgressWhile(() => this.props.repository.checkout(branchName, options));
192207
}
193208

194209
@autobind
195-
async push(options) {
210+
async push({force, setUpstream}) {
211+
await this.attemptGitOperation(
212+
() => this.doPush({force, setUpstream}),
213+
description => {
214+
if (/rejected[\s\S]*failed to push/.test(description)) {
215+
return {
216+
message: 'Push rejected',
217+
description: 'The tip of your current branch is behind its remote counterpart.' +
218+
' Try pulling before pushing again. Or, to force push, hold `cmd` or `ctrl` while clicking.',
219+
};
220+
}
221+
222+
return {message: 'Unable to push', description: `<pre>${description}</pre>`};
223+
},
224+
);
225+
}
226+
227+
async doPush(options) {
196228
await this.setInProgressWhile(() => {
197229
return this.props.repository.push(this.props.currentBranch.getName(), options);
198230
}, {push: true});
199231
}
200232

201233
@autobind
202234
async pull() {
235+
await this.attemptGitOperation(
236+
() => this.doPull(),
237+
description => {
238+
if (/error: Your local changes to the following files would be overwritten by merge/.test(description)) {
239+
const lines = description.split('\n');
240+
const files = lines.slice(3, lines.length - 3).map(l => `\`${l.trim()}\``).join('<br>');
241+
return {
242+
message: 'Pull aborted',
243+
description: 'Local changes to the following would be overwritten by merge:<br>' + files +
244+
'<br>Please commit your changes or stash them before you merge.',
245+
};
246+
}
247+
248+
return {message: 'Unable to pull', description: `<pre>${description}</pre>`};
249+
},
250+
);
251+
252+
}
253+
254+
async doPull() {
203255
await this.setInProgressWhile(() => this.props.repository.pull(this.props.currentBranch.getName()), {pull: true});
204256
}
205257

206258
@autobind
207259
async fetch() {
260+
await this.attemptGitOperation(
261+
() => this.doFetch(),
262+
description => {
263+
return {
264+
message: 'Unable to fetch',
265+
description: `<pre>${description}</pre>`,
266+
};
267+
},
268+
);
269+
}
270+
271+
async doFetch() {
208272
await this.setInProgressWhile(() => this.props.repository.fetch(this.props.currentBranch.getName()), {fetch: true});
209273
}
210274
}

lib/views/push-pull-menu-view.js

Lines changed: 6 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import {autobind} from 'core-decorators';
44

5-
import {GitError} from '../git-shell-out-strategy';
65
import {BranchPropType, RemotePropType} from '../prop-types';
76

87
export default class PushPullMenuView extends React.Component {
98
static propTypes = {
10-
notificationManager: PropTypes.object.isRequired,
119
currentBranch: BranchPropType.isRequired,
1210
currentRemote: RemotePropType.isRequired,
1311
inProgress: PropTypes.bool,
@@ -120,69 +118,18 @@ export default class PushPullMenuView extends React.Component {
120118
}
121119
}
122120

123-
async attemptGitOperation(operation, errorTransform = message => ({message})) {
124-
const operationPromise = operation();
125-
try {
126-
return await operationPromise;
127-
} catch (error) {
128-
if (!(error instanceof GitError)) { throw error; }
129-
const {message, description} = errorTransform(error.stdErr);
130-
this.props.notificationManager.addError(
131-
message || 'Cannot complete remote interaction',
132-
{description, dismissable: true},
133-
);
134-
return null;
135-
}
136-
}
137-
138121
@autobind
139-
async fetch() {
140-
await this.attemptGitOperation(
141-
() => this.props.fetch(),
142-
description => {
143-
return {
144-
message: 'Unable to fetch',
145-
description: `<pre>${description}</pre>`,
146-
};
147-
},
148-
);
122+
fetch() {
123+
return this.props.fetch();
149124
}
150125

151126
@autobind
152-
async pull() {
153-
await this.attemptGitOperation(
154-
() => this.props.pull(),
155-
description => {
156-
if (/error: Your local changes to the following files would be overwritten by merge/.test(description)) {
157-
const lines = description.split('\n');
158-
const files = lines.slice(3, lines.length - 3).map(l => `\`${l.trim()}\``).join('<br>');
159-
return {
160-
message: 'Pull aborted',
161-
description: 'Local changes to the following would be overwritten by merge:<br>' + files +
162-
'<br>Please commit your changes or stash them before you merge.',
163-
};
164-
}
165-
166-
return {message: 'Unable to pull', description: `<pre>${description}</pre>`};
167-
},
168-
);
127+
pull() {
128+
return this.props.pull();
169129
}
170130

171131
@autobind
172-
async push() {
173-
await this.attemptGitOperation(
174-
() => this.props.push({force: this.state.force, setUpstream: !this.props.currentRemote.isPresent()}),
175-
description => {
176-
if (/rejected[\s\S]*failed to push/.test(description)) {
177-
return {
178-
message: 'Push rejected',
179-
description: 'The tip of your current branch is behind its remote counterpart.' +
180-
' Try pulling before pushing again. Or, to force push, hold `cmd` while clicking.',
181-
};
182-
}
183-
184-
return {message: 'Unable to push', description: `<pre>${description}</pre>`};
185-
},
186-
);
132+
push() {
133+
return this.props.push({force: this.state.force, setUpstream: !this.props.currentRemote.isPresent()});
187134
}
188135
}

0 commit comments

Comments
 (0)