-
Notifications
You must be signed in to change notification settings - Fork 186
Reimplemented Git-FTP features after 489a60c merge #288
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,7 @@ define(function (require, exports) { | |
| usernameArgs = ["config", "--add", "git-ftp." + scope + ".user", username], | ||
| passwordArgs = ["config", "--add", "git-ftp." + scope + ".password", password]; | ||
|
|
||
| // FIXME: `Possibly unhandled TypeError: Object [object Object] has no method 'fail'` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| return Promise.all([ | ||
| git(scopeArgs), | ||
| git(usernameArgs), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,19 +11,27 @@ define(function (require) { | |
| Events = require("src/Events"), | ||
| EventEmitter = require("src/EventEmitter"), | ||
| Git = require("src/Git/Git"), | ||
| GitFtp = require("src/Git/GitFtp"), | ||
| Preferences = require("src/Preferences"), | ||
| Promise = require("bluebird"), | ||
| Strings = require("strings"), | ||
| Utils = require("src/Utils"); | ||
| Utils = require("src/Utils"), | ||
| q = require("../thirdparty/q"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use new
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay thanks.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a problem replacing q with bluebird... So I can use
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's the use-case with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I already get the two arrays I need, I just don't get the state of the tasks.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, use Q for now and I'll look at it when I'll be merging.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to abort and throw error only if "Git.getRemotes" fails. |
||
|
|
||
| // Templates | ||
| var gitRemotesPickerTemplate = require("text!htmlContent/git-remotes-picker.html"); | ||
|
|
||
| // Module variables | ||
| var $selectedRemote = null, | ||
| $remotesDropdown = null; | ||
| $remotesDropdown = null, | ||
| $gitPanel = null, | ||
| gitFtpEnabled = false; | ||
|
|
||
| function initVariables() { | ||
| var $gitPanel = $("#git-panel"); | ||
| $gitPanel = $("#git-panel"); | ||
| $selectedRemote = $gitPanel.find(".git-selected-remote"); | ||
| $remotesDropdown = $gitPanel.find(".git-remotes-dropdown"); | ||
| gitFtpEnabled = Preferences.get("useGitFtp"); | ||
| } | ||
|
|
||
| // Implementation | ||
|
|
@@ -43,100 +51,119 @@ define(function (require) { | |
|
|
||
| function clearRemotePicker() { | ||
| $selectedRemote | ||
| .html("—") | ||
| .data("remote", null); | ||
| .html("—") | ||
| .data("remote", null); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you format it like this? please use formatting recomenned by jquery with indentation: http://api.jquery.com/end/
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry it's the auto indentator, I hate it :| |
||
| } | ||
|
|
||
| function selectRemote(remoteName) { | ||
| if (!remoteName) { | ||
| return clearRemotePicker(); | ||
| } | ||
| setDefaultRemote(remoteName); | ||
| $selectedRemote | ||
| .text(remoteName) | ||
| .data("remote", remoteName); | ||
| } | ||
|
|
||
| function refreshRemotesPicker() { | ||
| Git.getRemotes().then(function (remotes) { | ||
| var defaultRemoteName = getDefaultRemote(), | ||
| defaultRemote; | ||
| // Check if the selected remote is a FTP remote | ||
| var isGitFtp = ($remotesDropdown.find(".remote-name[data-is-gitftp=true][data-remote-name=\"" + remoteName + "\"]").length) ? true : false; | ||
|
|
||
| // empty the list first | ||
| $remotesDropdown.empty(); | ||
| // Set as default remote only if is not an FTP remote | ||
| if (!isGitFtp) { setDefaultRemote(remoteName); } | ||
|
|
||
| // Add option to define new remote | ||
| $remotesDropdown.append("<li><a class=\"git-remote-new\"><span>" + Strings.CREATE_NEW_REMOTE + "</span></a></li>"); | ||
| $remotesDropdown.append("<li class=\"divider\"></li>"); | ||
| // If is an FTP remote, disable the "pull" button, if not, enable it | ||
| $gitPanel.find("git-pull").prop("disabled", isGitFtp); | ||
|
|
||
| if (remotes.length > 0) { | ||
| EventEmitter.emit(Events.GIT_REMOTE_AVAILABLE); | ||
| } else { | ||
| EventEmitter.emit(Events.GIT_REMOTE_NOT_AVAILABLE); | ||
| clearRemotePicker(); | ||
| return; | ||
| } | ||
| // Enable the Git-FTP prefix if needed (or disable it) | ||
| $selectedRemote.prev(".ftp-prefix").attr("data-is-gitftp", isGitFtp); | ||
|
|
||
| // Add options to change remote | ||
| remotes.forEach(function (remoteInfo) { | ||
| var canDelete = remoteInfo.name !== "origin"; | ||
| // Update remote name of $selectedRemote | ||
| $selectedRemote.text(remoteName).data("remote", remoteName); | ||
| } | ||
|
|
||
| var $a = $("<a/>") | ||
| .attr("href", "#") | ||
| .addClass("remote-name") | ||
| .data("remote-name", remoteInfo.name); | ||
| function refreshRemotesPicker() { | ||
| // Run both getRemotes and getFtpRemotes and render with Mustache the template | ||
| q.allSettled([Git.getRemotes(), GitFtp.getFtpRemotes()]).spread(function (remotes, ftpRemotes) { | ||
|
|
||
| // If both promises are fullfilled then render the template | ||
| if (remotes.state === "fulfilled" && (ftpRemotes.state === "fulfilled" || gitFtpEnabled === false)) { | ||
|
|
||
| // Set default remote name and cache the remotes dropdown menu | ||
| var defaultRemoteName = getDefaultRemote(), | ||
| $remotesDropdown = $gitPanel.find(".git-remotes-dropdown"), | ||
| $remotesDropdownList = ""; | ||
|
|
||
| // Disable Git-push and Git-pull if there are not remotes defined | ||
| $gitPanel.find(".git-pull, .git-push").prop("disabled", (remotes.value.length === 0 && ftpRemotes.value.length === 0)); | ||
|
|
||
| // Add options to change remote | ||
| remotes.value = $.map(remotes.value, function (remote) { | ||
| return { | ||
| "name": remote.name, | ||
| "deletable": (remote.name !== "origin") ? true : false | ||
| }; | ||
| }); | ||
|
|
||
| if (canDelete) { | ||
| $a.append("<span class='trash-icon remove-remote'>×</span>"); | ||
| } | ||
| // Pass to Mustache the needed data | ||
| $remotesDropdownList = Mustache.render(gitRemotesPickerTemplate, { | ||
| Strings: Strings, | ||
| remotes: remotes.value, | ||
| ftpRemotes: ftpRemotes.value, | ||
| hasRemotes: remotes.value.length ? true : false, | ||
| hasFtpRemotes: ftpRemotes.value.length ? true : false, | ||
| gitFtpEnabled: gitFtpEnabled | ||
| }); | ||
|
|
||
| $a.append("<span class='change-remote'>" + remoteInfo.name + "</span>"); | ||
| $a.appendTo($("<li class=\"remote\"/>").appendTo($remotesDropdown)); | ||
| // Inject the rendered template inside the $remotesDropdown | ||
| $remotesDropdown.html($remotesDropdownList); | ||
|
|
||
| if (remoteInfo.name === defaultRemoteName) { | ||
| defaultRemote = remoteInfo.name; | ||
| if (remotes.value.length !== 0) { | ||
| selectRemote(defaultRemoteName); | ||
| } else { | ||
| clearRemotePicker(); | ||
| } | ||
|
|
||
| return $a; | ||
| }); | ||
| if (ftpRemotes.state === "rejected" && gitFtpEnabled === true) { | ||
| throw ErrorHandler.showError( | ||
| ftpRemotes.reason, | ||
| "Failed to get a list of Git-FTP remotes, Git remotes was successfully initalized and are usable." | ||
| ); | ||
| } | ||
|
|
||
| selectRemote(defaultRemote || _.first(remotes).name); | ||
| }).catch(function (err) { | ||
| ErrorHandler.showError(err, "Preparing remotes picker failed"); | ||
| } else { | ||
| if (remotes.state === "rejected") { | ||
| throw ErrorHandler.showError(remotes.reason, "Failed to get a list of remotes."); | ||
| } | ||
| if (ftpRemotes.state === "rejected" && gitFtpEnabled === true) { | ||
| throw ErrorHandler.showError(ftpRemotes.reason, "Failed to get a list of Git-FTP remotes."); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| function handleRemoteCreation() { | ||
| return Utils.askQuestion(Strings.CREATE_NEW_REMOTE, Strings.ENTER_REMOTE_NAME) | ||
| .then(function (name) { | ||
| return Utils.askQuestion(Strings.CREATE_NEW_REMOTE, Strings.ENTER_REMOTE_URL).then(function (url) { | ||
| return [name, url]; | ||
| }); | ||
| }) | ||
| .spread(function (name, url) { | ||
| return Git.createRemote(name, url).then(function () { | ||
| return refreshRemotesPicker(); | ||
| }); | ||
| }) | ||
| .catch(function (err) { | ||
| ErrorHandler.showError(err, "Remote creation failed"); | ||
| .then(function (name) { | ||
| return Utils.askQuestion(Strings.CREATE_NEW_REMOTE, Strings.ENTER_REMOTE_URL).then(function (url) { | ||
| return [name, url]; | ||
| }); | ||
| }) | ||
| .spread(function (name, url) { | ||
| return Git.createRemote(name, url).then(function () { | ||
| return refreshRemotesPicker(); | ||
| }); | ||
| }) | ||
| .catch(function (err) { | ||
| ErrorHandler.showError(err, "Remote creation failed"); | ||
| }); | ||
| } | ||
|
|
||
| function deleteRemote(remoteName) { | ||
| return Utils.askQuestion(Strings.DELETE_REMOTE, | ||
| StringUtils.format(Strings.DELETE_REMOTE_NAME, remoteName), | ||
| { booleanResponse: true }) | ||
| .then(function (response) { | ||
| if (response === true) { | ||
| return Git.deleteRemote(remoteName).then(function () { | ||
| return refreshRemotesPicker(); | ||
| }); | ||
| } | ||
| }) | ||
| .catch(function (err) { | ||
| ErrorHandler.logError(err); | ||
| return Utils.askQuestion(Strings.DELETE_REMOTE, StringUtils.format(Strings.DELETE_REMOTE_NAME, remoteName), { booleanResponse: true }) | ||
| .then(function (response) { | ||
| if (response === true) { | ||
| return Git.deleteRemote(remoteName).then(function () { | ||
| return refreshRemotesPicker(); | ||
| }); | ||
| } | ||
| }) | ||
| .catch(function (err) { | ||
| ErrorHandler.logError(err); | ||
| }); | ||
| } | ||
|
|
||
| function pullFromRemote(remoteName) { | ||
|
|
@@ -205,11 +232,11 @@ define(function (require) { | |
| return new Promise(function (resolve, reject) { | ||
| Utils.askQuestion(Strings.SET_ORIGIN_URL, _.escape(Strings.URL)).then(function (url) { | ||
| Git.createRemote("origin", url) | ||
| .then(function () { | ||
| return Git.push("origin"); | ||
| }) | ||
| .then(resolve) | ||
| .catch(reject); | ||
| .then(function () { | ||
| return Git.push("origin"); | ||
| }) | ||
| .then(resolve) | ||
| .catch(reject); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets use
type="normal"andtype="ftp"so we can add other types in the future