Skip to content

Reimplemented Git-FTP features after 489a60c merge#288

Merged
zaggino merged 4 commits intobrackets-userland:masterfrom
FezVrasta:git-ftp2
Mar 26, 2014
Merged

Reimplemented Git-FTP features after 489a60c merge#288
zaggino merged 4 commits intobrackets-userland:masterfrom
FezVrasta:git-ftp2

Conversation

@FezVrasta
Copy link
Copy Markdown
Contributor

Currently it supports:

  • Git-FTP remote (scope) creation
  • Git-FTP remote selection
  • Git-FTP remote deletion

There is a lot to rewrite and fix, will wait for your first review to proceed.

Currently it supports:
- Git-FTP remote (scope) creation
- Git-FTP remote deletion
- Git-FTP remote selection
Comment thread htmlContent/git-remotes-picker.html Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets use type="normal" and type="ftp" so we can add other types in the future

@zaggino
Copy link
Copy Markdown
Member

zaggino commented Mar 26, 2014

First review finished. Please fix the cases where you only modified the original formatting, because it's hard to review changes. Example:

                        Git.createRemote("origin", url)
                            .then(function () {
                                return Git.push("origin");
                            })
                            .then(resolve)
                            .catch(reject);

you changed to

                        Git.createRemote("origin", url)
                        .then(function () {
                            return Git.push("origin");
                        })
                        .then(resolve)
                        .catch(reject);

Please never do this. If you have some kind of extension which does this automatically - turn it off.

@FezVrasta
Copy link
Copy Markdown
Contributor Author

About the formatting problems, if I use your method the linter tells me that it expects } at 25 and instead is at 27...

@zaggino
Copy link
Copy Markdown
Member

zaggino commented Mar 26, 2014

Which linter? Do you have JSHint installed?

@zaggino
Copy link
Copy Markdown
Member

zaggino commented Mar 26, 2014

JSHint reads configuration from this file https://github.com/zaggino/brackets-git/blob/master/.jshintrc so it shouldn't show any errors.

@FezVrasta
Copy link
Copy Markdown
Contributor Author

Sorry my fault, nevermind ^^"

@FezVrasta
Copy link
Copy Markdown
Contributor Author

Just a little question.

We have Git and GitFtp.
Should I rename GitFtp.getFtpRemotes to GitFtp.getRemotes to make it like Git.getRemotes or is better repeat the Ftp word both in the name of the class and in the name of the function?

@zaggino
Copy link
Copy Markdown
Member

zaggino commented Mar 26, 2014

Yes, rename it. GitFtp.getFtpRemotes doesn't make any sense.

@zaggino
Copy link
Copy Markdown
Member

zaggino commented Mar 26, 2014

You can't use .all in this situation. .all passes only if everything passes and fails when any of the promises fail. Correct usage would be:

Git.getRemotes().then(function(gitRemotes) {
  return GitFtp.getFtpRemotes().then(function (ftpRemotes) {
    return [gitRemotes, ftpRemotes];
  }).catch(function (err) {
     // GitFtp.getFtpRemotes failed - do nothing with err
    return [gitRemotes, null];
  });
}).catch(function (err) {
  ErrorHandler.showError(err, "Git.getRemotes failed");
}).spread(function (gitRemotes, ftpRemotes) {
  // ftpRemotes might be null if getFtpRemotes failed
});

@FezVrasta
Copy link
Copy Markdown
Contributor Author

In this way them are ran one after the other, not together, and it makes the extension load in more time. Not sure this is the right solution...

@zaggino
Copy link
Copy Markdown
Member

zaggino commented Mar 26, 2014

Ok, I'll make an API for them to run simultaneously, put there a TODO comment please.

@FezVrasta
Copy link
Copy Markdown
Contributor Author

We need Promise.allSettled but looks like it's not available. Probably we should open an issue on Bluebird instead of write some tweak by ourselves.

@zaggino
Copy link
Copy Markdown
Member

zaggino commented Mar 26, 2014

Btw why do you want to ignore an error? If I have ftps turned on, I don't want them to fail silently - I want to see an error dialog and submit a bug.

@FezVrasta
Copy link
Copy Markdown
Contributor Author

Because is the shortest way I've found to make the GitFtp.getRemotes part pluggable without have to write two almost identical functions.

But now that you make me think about it maybe I could just write something like:

if(!gitFtpEnabled) {
    function getFtpRemotes() { return null; }
}
else {
    getFtpRemotes = GitFtp.getRemotes;
}
Promise.all([Git.getRemotes(), getFtpRemotes])

What do you think?

@FezVrasta
Copy link
Copy Markdown
Contributor Author

@zaggino
Copy link
Copy Markdown
Member

zaggino commented Mar 26, 2014

Why don't you just do this?

var promises = [];
promises.push(git.getremotes());
if (ftpEnabled) promises.push(ftp.getremotes())
Promise.all(promises).spread(remotes, ftpRemotes)

remotes will be always there and ftpRemotes will be there only if it was enabled

@FezVrasta
Copy link
Copy Markdown
Contributor Author

Umh yes actualy in this way it's much better, thanks.

@FezVrasta
Copy link
Copy Markdown
Contributor Author

Just a problem with your method, I can't know what failed of the two taks if one of them fails... Does it matter?

@zaggino
Copy link
Copy Markdown
Member

zaggino commented Mar 26, 2014

No, it really doesn't matter, just do the normal handler maybe with an addition

var msg = "Getting the remotes failed";
if (ftpEnabled) msg += " (FTP enabled)";
ErrorHandler.showError(err, msg)

@FezVrasta
Copy link
Copy Markdown
Contributor Author

Problem:

var promises = [];
    promises.push(Git.getRemotes());
    if (gitFtpEnabled) { promises.push(GitFtp.getRemotes()); }

is wrong, because I assign the result of the two functions to promises.

var promises = [];
    promises.push(Git.getRemotes);
    if (gitFtpEnabled) { promises.push(GitFtp.getRemotes); }

is even wrong because the resulting array is:

[function, function]
0: function getRemotes() 
1: function getRemotes() 

and not

[function, function]
0: function Git.getRemotes() 
1: function GitFtp.getRemotes() 

@zaggino
Copy link
Copy Markdown
Member

zaggino commented Mar 26, 2014

The first case is right because Git.getRemotes() returns a promise - not a value. Have you tested it?

@FezVrasta
Copy link
Copy Markdown
Contributor Author

yes, it doesn't work, I think the function is executed during the assignment (note the ())

@zaggino
Copy link
Copy Markdown
Member

zaggino commented Mar 26, 2014

The function is executed and returns a promise which will be resolved later.

Git.getRemotes().then(function(remotes) { ... })

is exactly the same as

var promise = Git.getRemotes();
promise.then(function (remotes) { ... });

@zaggino
Copy link
Copy Markdown
Member

zaggino commented Mar 26, 2014

Just put a TODO comment there I'll look at it - it has to work, I have done this before.

@zaggino
Copy link
Copy Markdown
Member

zaggino commented Mar 26, 2014

Can I review again / merge this?

@FezVrasta
Copy link
Copy Markdown
Contributor Author

As you prefer, I'm not at office so I will not work on it till tomorrow (EU time).
A review would be welcome I think.

Comment thread htmlContent/git-remotes-picker.html Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why there's this check for gitFtpEnabled and again lower at line 15?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get it, nevermind.

@zaggino
Copy link
Copy Markdown
Member

zaggino commented Mar 26, 2014

I'm reading the diff wrong or have this disappeared completely?

if (remotes.length > 0) {
 -                EventEmitter.emit(Events.GIT_REMOTE_AVAILABLE);
 -            } else {
 -                EventEmitter.emit(Events.GIT_REMOTE_NOT_AVAILABLE);
 -                clearRemotePicker();
 -                return;
 -            }

Comment thread src/Remotes.js
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use 4 spaces for indentation

@FezVrasta
Copy link
Copy Markdown
Contributor Author

#288 (comment) looks like it's disappeared, I've almost replaced the entire Remotes.js with my old version.

@zaggino
Copy link
Copy Markdown
Member

zaggino commented Mar 26, 2014

Ok, I'll merge this today so you can continue tomorrow.

@FezVrasta
Copy link
Copy Markdown
Contributor Author

Thanks :)

@zaggino zaggino mentioned this pull request Mar 26, 2014
zaggino added a commit that referenced this pull request Mar 26, 2014
@zaggino zaggino merged commit 29f60dd into brackets-userland:master Mar 26, 2014
@zaggino
Copy link
Copy Markdown
Member

zaggino commented Mar 26, 2014

@FezVrasta done, see #294 for details.

@FezVrasta FezVrasta deleted the git-ftp2 branch March 27, 2014 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants