示例#1
0
 EventEmitter.emit(Events.GIT_CHANGE_USERNAME, null, function () {
     EventEmitter.emit(Events.GIT_CHANGE_EMAIL, null, function () {
         Git.init().then(function (result) {
             defer.resolve(result);
         }).catch(function (err) {
             defer.reject(err);
         });
     });
 });
示例#2
0
    function pullFromRemote(remoteName) {
        if (!remoteName) {
            ErrorHandler.showError("No remote has been selected for pull!");
            return;
        }

        EventEmitter.emit(Events.PULL_STARTED);

        Git.pull(remoteName).then(function (result) {
            Utils.showOutput(result, Strings.GIT_PULL_RESPONSE);
        }).catch(function (err) {
            ErrorHandler.showError(err, "Pulling from remote repository failed.");
        }).finally(function () {
            EventEmitter.emit(Events.PULL_FINISHED);
        });
    }
示例#3
0
        return Git.getDeletedFiles(oldBranchName, newBranchName).then(function (deletedFiles) {

            var gitRoot     = Preferences.get("currentGitRoot"),
                openedFiles = MainViewManager.getWorkingSet(MainViewManager.ALL_PANES);

            // Close files that does not exists anymore in the new selected branch
            deletedFiles.forEach(function (dFile) {
                var oFile = _.find(openedFiles, function (oFile) {
                    return oFile.fullPath == gitRoot + dFile;
                });
                if (oFile) {
                    DocumentManager.closeFullEditor(oFile);
                }
            });

            EventEmitter.emit(Events.REFRESH_ALL);

        }).catch(function (err) {
示例#4
0
            return Git.init().catch(function (err) {

                if (ErrorHandler.contains(err, "Please tell me who you are")) {
                    var defer = Promise.defer();
                    EventEmitter.emit(Events.GIT_CHANGE_USERNAME, null, function () {
                        EventEmitter.emit(Events.GIT_CHANGE_EMAIL, null, function () {
                            Git.init().then(function (result) {
                                defer.resolve(result);
                            }).catch(function (err) {
                                defer.reject(err);
                            });
                        });
                    });
                    return defer.promise;
                }

                throw err;

            });
        return git(["branch", "--no-color"]).then(function (stdout) {
            var branchName = _.find(stdout.split("\n"), function (l) { return l[0] === "*"; });
            if (branchName) {
                branchName = branchName.substring(1).trim();

                var m = branchName.match(/^\(.*\s(\S+)\)$/); // like (detached from f74acd4)
                if (m) { return m[1]; }

                return branchName;
            }

            // no branch situation so we need to create one by doing a commit
            if (stdout.match(/^\s*$/)) {
                EventEmitter.emit(Events.GIT_NO_BRANCH_EXISTS);
                // master is the default name of the branch after git init
                return "master";
            }

            // alternative
            return git(["log", "--pretty=format:%H %d", "-1"]).then(function (stdout) {
                var m = stdout.trim().match(/^(\S+)\s+\((.*)\)$/);
                var hash = m[1].substring(0, 20);
                m[2].split(",").forEach(function (info) {
                    info = info.trim();

                    if (info === "HEAD") { return; }

                    var m = info.match(/^tag:(.+)$/);
                    if (m) {
                        hash = m[1].trim();
                        return;
                    }

                    hash = info;
                });
                return hash;
            });
        });
示例#6
0
        Git.getRemotes().then(function (remotes) {
            // Set default remote name and cache the remotes dropdown menu
            var defaultRemoteName    = getDefaultRemote();

            // Disable Git-push and Git-pull if there are not remotes defined
            $gitPanel
                .find(".git-pull, .git-push")
                .prop("disabled", remotes.length === 0);

            // Add options to change remote
            remotes.forEach(function (remote) {
                remote.deletable = remote.name !== "origin";
            });

            // Pass to Mustache the needed data
            var compiledTemplate = Mustache.render(gitRemotesPickerTemplate, {
                Strings: Strings,
                remotes: remotes
            });

            // Inject the rendered template inside the $remotesDropdown
            $remotesDropdown.html(compiledTemplate);

            // Notify others that they may add more stuff to this dropdown
            EventEmitter.emit(Events.REMOTES_REFRESH_PICKER);
            // TODO: is it possible to wait for listeners to finish?

            // TODO: if there're no remotes but there are some ftp remotes
            // we need to adjust that something other may be put as default
            // low priority
            if (remotes.length > 0) {
                selectRemote(defaultRemoteName, "git");
            } else {
                clearRemotePicker();
            }
        }).catch(function (err) {
示例#7
0
 }).then(function (results) {
     EventEmitter.emit(Events.GIT_STATUS_RESULTS, results);
     return results;
 });
 var refreshCallback  = function () {
     // dialog.close();
     EventEmitter.emit(Events.REFRESH_ALL);
 };
示例#9
0
 $(ProjectManager).on("beforeProjectClose", function () {
     // Disable Git when closing a project so listeners won't fire before new is opened
     EventEmitter.emit(Events.GIT_DISABLED);
 });
示例#10
0
 return q.finally(function () {
     EventEmitter.emit(Events.REFRESH_ALL);
 });
示例#11
0
 .then(function () {
     EventEmitter.emit(Events.REFRESH_ALL);
 });
示例#12
0
 $(DocumentManager).on("documentSaved", function (evt, doc) {
     // we care only for files in current project
     if (doc.file.fullPath.indexOf(Utils.getProjectRoot()) === 0) {
         EventEmitter.emit(Events.BRACKETS_DOCUMENT_SAVED, evt, doc);
     }
 });
示例#13
0
	FileSystem.on("change", function (evt, file) {
        // we care only for files in current project
        if (file && file.fullPath.indexOf(Utils.getProjectRoot()) === 0) {
            EventEmitter.emit(Events.BRACKETS_FILE_CHANGED, evt, file);
        }
    });
示例#14
0
 }).finally(function () {
     EventEmitter.emit(Events.PUSH_FINISHED);
 });
示例#15
0
    function pushToRemote(remoteName) {
        if (!remoteName) {
            ErrorHandler.showError("No remote has been selected for push!");
            return;
        }

        EventEmitter.emit(Events.PUSH_STARTED);
        decideRemoteBranch(remoteName).spread(function (remoteBranch, newUpstream) {
            var p;
            if (newUpstream) {
                p = Git.pushToNewUpstream(remoteName, remoteBranch);
            } else {
                p = Git.push(remoteName, remoteBranch);
            }
            return p.catch(function (err) {

                if (!ErrorHandler.contains(err, "git remote add <name> <url>")) {
                    throw err;
                }

                // this will ask user to enter an origin url for pushing
                // it's pretty dumb because if he enters invalid url, he has to go to console again
                // but our users are very wise so that definitely won't happen :)))

                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);
                    });
                });

            }).catch(function (err) {

                throw err;
                /* this shouldn't be needed anymore
                if (typeof err !== "string") { throw err; }
                var m = err.match(/git push --set-upstream (\S+) (\S+)/);
                if (!m) { throw err; }
                return Git.pushToNewUpstream(m[1], m[2]);
                */

            }).catch(function (err) {

                var validFail = false;
                if (ErrorHandler.contains(err, "rejected because")) {
                    validFail = true;
                }
                if (validFail) {
                    throw err;
                }
                console.warn("Traditional push failed: " + err);
                return handleGitPushWithPassword(err, remoteName);

            }).then(function (result) {

                var template = [
                    "<h3>{{flagDescription}}</h3>",
                    "Info:",
                    "Remote url - {{remoteUrl}}",
                    "Local branch - {{from}}",
                    "Remote branch - {{to}}",
                    "Summary - {{summary}}",
                    "<h4>Status - {{status}}</h4>"
                ].join("<br>");

                Dialogs.showModalDialog(
                    DefaultDialogs.DIALOG_ID_INFO,
                    Strings.GIT_PUSH_RESPONSE, // title
                    Mustache.render(template, result) // message
                );

            }).catch(function (err) {
                console.warn("Pushing to remote repositories with username / password is not fully supported! See github page/issues for details.");
                ErrorHandler.showError(err, "Pushing to remote repository failed.");
            });
        }).finally(function () {
            EventEmitter.emit(Events.PUSH_FINISHED);
        });
    }
示例#16
0
 }).then(function () {
     return EventEmitter.emit(Events.HANDLE_PROJECT_REFRESH);
 });
示例#17
0
 $(DocumentManager).on("currentDocumentChange", function (evt, currentDocument, previousDocument) {
     currentDocument = currentDocument || DocumentManager.getCurrentDocument();
     if (!HistoryViewer.isVisible()) {
         EventEmitter.emit(Events.BRACKETS_CURRENT_DOCUMENT_CHANGE, evt, currentDocument, previousDocument);
     }
 });
示例#18
0
 $(ProjectManager).on("projectOpen", function () {
     EventEmitter.emit(Events.BRACKETS_PROJECT_CHANGE);
 });
示例#19
0
 Utils.showOutput(stdout, Strings.MERGE_RESULT).finally(function () {
     EventEmitter.emit(Events.REFRESH_ALL);
 });
示例#20
0
 $(ProjectManager).on("projectRefresh", function () {
     EventEmitter.emit(Events.BRACKETS_PROJECT_REFRESH);
 });
示例#21
0
 }).then(function () {
     closeDropdown();
     EventEmitter.emit(Events.REFRESH_ALL);
 });
示例#22
0
 .catch(function (err) {
     // disable the button for this session
     EventEmitter.emit(Events.TERMINAL_DISABLE);
     ErrorHandler.showError(err);
 });