Exemple #1
0
        }).spread(function (branchHash, remoteUrl) {

            var isHttp = remoteUrl.indexOf("http") === 0;
            if (!isHttp) {
                throw ErrorHandler.rewrapError(originalPushError,
                                               new Error("Asking for username/password aborted because remote is not HTTP(S)"));
            }

            var username,
                password,
                hasUsername,
                hasPassword,
                shouldSave = false;

            var m = remoteUrl.match(/https?:\/\/([^@]+)@/);
            if (!m) {
                hasUsername = false;
                hasPassword = false;
            } else if (m[1].split(":").length === 1) {
                hasUsername = true;
                hasPassword = false;
            } else {
                hasUsername = true;
                hasPassword = true;
            }

            if (hasUsername && hasPassword) {
                throw ErrorHandler.rewrapError(originalPushError, new Error("Username/password is already present in the URL"));
            }

            var p = Promise.resolve();
            if (!hasUsername) {
                p = p.then(function () {
                    return Utils.askQuestion(Strings.TOOLTIP_PUSH, Strings.ENTER_USERNAME).then(function (str) {
                        username = encodeURIComponent(str);
                    });
                });
            }
            if (!hasPassword) {
                p = p.then(function () {
                    return Utils.askQuestion(Strings.TOOLTIP_PUSH, Strings.ENTER_PASSWORD, {password: true}).then(function (str) {
                        password = encodeURIComponent(str);
                    });
                });
            }
            if (Preferences.get("storePlainTextPasswords")) {
                p = p.then(function () {
                    return Utils.askQuestion(Strings.TOOLTIP_PUSH, Strings.SAVE_PASSWORD_QUESTION, {booleanResponse: true}).then(function (bool) {
                        shouldSave = bool;
                    });
                });
            }
            return p.then(function () {
                if (!hasUsername) {
                    remoteUrl = remoteUrl.replace(/(https?:\/\/)/, function (a, protocol) { return protocol + username + "@"; });
                }
                if (!hasPassword) {
                    var io = remoteUrl.indexOf("@");
                    remoteUrl = remoteUrl.substring(0, io) + ":" + password + remoteUrl.substring(io);
                }
                return Git.push(remoteUrl, branchHash).then(function (pushResponse) {
                    if (shouldSave) {
                        return Git.setConfig("remote." + remoteName + ".url", remoteUrl).then(function () {
                            return pushResponse;
                        });
                    }
                    return pushResponse;
                });
            });
        });
Exemple #2
0
 return Git.getConfig("remote." + remoteName + ".url").then(function (remoteUrl) {
     if (!remoteUrl) {
         throw ErrorHandler.rewrapError(originalPushError, new Error("git config remote." + remoteName + ".url is empty!"));
     }
     return [branchHash, remoteUrl];
 });