Skip to content

Commit 5d69164

Browse files
author
FezVrasta
committed
Added error handling for refreshremotes
1 parent 46edb0a commit 5d69164

3 files changed

Lines changed: 58 additions & 45 deletions

File tree

src/Ftp.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ define(function (require) {
3737
var gitFtpRemote = $gitPanel.find(".git-remote-selected").text().trim();
3838
$gitPanel.find(".gitftp-push").prop("disabled", true).addClass("btn-loading");
3939

40-
GitFtp.gitFtpPush(gitFtpRemote).done(function (result) {
40+
GitFtp.push(gitFtpRemote).done(function (result) {
4141
Dialogs.showModalDialog(
4242
DefaultDialogs.DIALOG_ID_INFO,
4343
Strings.GITFTP_PUSH_RESPONSE, // title
@@ -63,7 +63,7 @@ define(function (require) {
6363
Strings.ENTER_GITFTP_REMOTE_URL,
6464
{defaultValue: "ftp://user:passwd@example.org/folder"}).then(function (url) {
6565

66-
return GitFtp.gitFtpAddScope(name, url).then(function () {
66+
return GitFtp.addScope(name, url).then(function () {
6767
// return handleGitFtpRemoteInit();
6868
}).fail(function (err) {
6969
ErrorHandler.showError(err, "Git-FTP remote creation failed");
@@ -92,7 +92,7 @@ define(function (require) {
9292
{booleanResponse: true}
9393
).then(function (response) {
9494
if (response) {
95-
return GitFtp.gitFtpRemoveScope(remoteName).then(function () {
95+
return GitFtp.removeScope(remoteName).then(function () {
9696
$selectedElement.parent().remove();
9797
var newRemote = $gitPanel.find(".git-remotes-dropdown .remote").first().find("a").data("remote-name");
9898
$currentRemote.data("remote-name", newRemote).html(newRemote);

src/Git/GitFtp.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ define(function (require, exports) {
1414

1515
// Implementation
1616

17-
function gitFtpInit(scope) {
17+
function init(scope) {
1818
return git(["ftp", "init", "--scope", scope]);
1919
}
2020

21-
function gitFtpPush(scope) {
21+
function push(scope) {
2222
return git(["ftp", "push", "--scope", scope]);
2323
}
2424

25-
function getFtpRemotes() {
25+
function getRemotes() {
2626
return git(["config", "--list"]).then(function (stdout) {
2727
return stdout.split("\n").reduce(function (result, row) {
2828
var io = row.indexOf(".url");
@@ -37,7 +37,7 @@ define(function (require, exports) {
3737
});
3838
}
3939

40-
function gitFtpAddScope(scope, url) {
40+
function addScope(scope, url) {
4141
var uri = new URI(url),
4242
username = uri.username(),
4343
password = uri.password();
@@ -59,15 +59,15 @@ define(function (require, exports) {
5959
});
6060
}
6161

62-
function gitFtpRemoveScope(scope) {
62+
function removeScope(scope) {
6363
return git(["ftp", "remove-scope", scope]);
6464
}
6565

6666
// Public API
67-
exports.gitFtpInit = gitFtpInit;
68-
exports.gitFtpPush = gitFtpPush;
69-
exports.getFtpRemotes = getFtpRemotes;
70-
exports.gitFtpAddScope = gitFtpAddScope;
71-
exports.gitFtpRemoveScope = gitFtpRemoveScope;
67+
exports.init = init;
68+
exports.push = push;
69+
exports.getRemotes = getRemotes;
70+
exports.addScope = addScope;
71+
exports.removeScope = removeScope;
7272

7373
});

src/Remotes.js

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -76,41 +76,54 @@ define(function (require) {
7676

7777
function refreshRemotesPicker() {
7878
// Run both getRemotes and getFtpRemotes and render with Mustache the template
79-
Promise.all([Git.getRemotes(), GitFtp.getFtpRemotes()]).spread(function (remotes, ftpRemotes) {
80-
81-
// Set default remote name and cache the remotes dropdown menu
82-
var defaultRemoteName = getDefaultRemote(),
83-
$remotesDropdown = $gitPanel.find(".git-remotes-dropdown"),
84-
$remotesDropdownList = "";
85-
86-
// Disable Git-push and Git-pull if there are not remotes defined
87-
$gitPanel.find(".git-pull, .git-push").prop("disabled", (remotes.length === 0 && ftpRemotes.length === 0));
88-
89-
// Add options to change remote
90-
remotes = $.map(remotes, function (remote) {
91-
return {
92-
"name": remote.name,
93-
"deletable": (remote.name !== "origin") ? true : false
94-
};
95-
});
79+
Promise.settle([Git.getRemotes(), GitFtp.getRemotes()]).spread(function (remotes, ftpRemotes) {
80+
81+
// If Git.getRemotes was fulfilled and (GitFtp.getRemotes was fulfilled or disabled)...
82+
if (remotes.isFulfilled() && (ftpRemotes.isFulfilled() || !gitFtpEnabled)) {
83+
84+
// Set default remote name and cache the remotes dropdown menu
85+
var defaultRemoteName = getDefaultRemote(),
86+
$remotesDropdown = $gitPanel.find(".git-remotes-dropdown"),
87+
$remotesDropdownList = "";
88+
89+
// Disable Git-push and Git-pull if there are not remotes defined
90+
$gitPanel
91+
.find(".git-pull, .git-push")
92+
.prop("disabled", (remotes._settledValue.length === 0 && ftpRemotes._settledValue.length === 0));
93+
94+
// Add options to change remote
95+
remotes._settledValue = $.map(remotes._settledValue, function (remote) {
96+
return {
97+
"name": remote.name,
98+
"deletable": (remote.name !== "origin") ? true : false
99+
};
100+
});
96101

97-
// Pass to Mustache the needed data
98-
$remotesDropdownList = Mustache.render(gitRemotesPickerTemplate, {
99-
Strings: Strings,
100-
remotes: remotes,
101-
ftpRemotes: ftpRemotes,
102-
hasRemotes: remotes.length ? true : false,
103-
hasFtpRemotes: ftpRemotes.length ? true : false,
104-
gitFtpEnabled: gitFtpEnabled
105-
});
102+
// Pass to Mustache the needed data
103+
$remotesDropdownList = Mustache.render(gitRemotesPickerTemplate, {
104+
Strings: Strings,
105+
remotes: remotes._settledValue,
106+
ftpRemotes: ftpRemotes._settledValue,
107+
hasRemotes: remotes._settledValue.length ? true : false,
108+
hasFtpRemotes: ftpRemotes._settledValue.length ? true : false,
109+
gitFtpEnabled: gitFtpEnabled
110+
});
106111

107-
// Inject the rendered template inside the $remotesDropdown
108-
$remotesDropdown.html($remotesDropdownList);
112+
// Inject the rendered template inside the $remotesDropdown
113+
$remotesDropdown.html($remotesDropdownList);
109114

110-
if (remotes.length !== 0) {
111-
selectRemote(defaultRemoteName);
112-
} else {
113-
clearRemotePicker();
115+
if (remotes._settledValue.length !== 0) {
116+
selectRemote(defaultRemoteName);
117+
} else {
118+
clearRemotePicker();
119+
}
120+
}
121+
// Git.getRemotes was not fulfilled or (GitFtp.getRemotes was not fulfilled and enabled)...
122+
else {
123+
ErrorHandler.showError(remotes.error(), "Git remotes fetching failed.");
124+
if (ftpRemotes.isRejected() && gitFtpEnabled) {
125+
ErrorHandler.showError(ftpRemotes.error(), "Git-FTP remotes fetching failed.");
126+
}
114127
}
115128

116129
});

0 commit comments

Comments
 (0)