Handle a local branch that does not yet track a remote

This commit is contained in:
Nick O'Leary 2017-12-04 13:26:47 +00:00
parent 94eeaeb8d3
commit a7e14f1093
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
3 changed files with 43 additions and 20 deletions

View File

@ -883,16 +883,32 @@ RED.projects = (function() {
} else {
branchPrefix = "";
}
$.getJSON(url,function(result) {
branches = result.branches;
result.branches.forEach(function(b) {
branchList.editableList('addItem',b);
});
branchList.editableList('addItem',{});
setTimeout(function() {
spinner.remove();
},Math.max(300-(Date.now() - start),0));
});
sendRequest({
url: url,
type: "GET",
responses: {
0: function(error) {
console.log(error);
},
200: function(result) {
branches = result.branches;
result.branches.forEach(function(b) {
branchList.editableList('addItem',b);
});
branchList.editableList('addItem',{});
setTimeout(function() {
spinner.remove();
},Math.max(300-(Date.now() - start),0));
},
400: {
'unexpected_error': function(error) {
console.log(error);
}
}
}
})
},
addItem: function(data) { branchList.editableList('addItem',data) },
filter: function() { branchList.editableList('filter') },

View File

@ -345,14 +345,16 @@ Project.prototype.status = function() {
var fetchPromise;
if (this.remotes) {
fetchPromise = gitTools.getRemoteBranch(self.path).then(function(remoteBranch) {
var allRemotes = Object.keys(self.remotes);
var match = "";
allRemotes.forEach(function(remote) {
if (remoteBranch.indexOf(remote) === 0 && match.length < remote.length) {
match = remote;
}
})
return self.fetch(match);
if (remoteBranch) {
var allRemotes = Object.keys(self.remotes);
var match = "";
allRemotes.forEach(function(remote) {
if (remoteBranch.indexOf(remote) === 0 && match.length < remote.length) {
match = remote;
}
})
return self.fetch(match);
}
});
} else {
fetchPromise = when.resolve();
@ -390,7 +392,7 @@ Project.prototype.status = function() {
Project.prototype.push = function (remoteBranchName,setRemote) {
var remote = this.parseRemoteBranch(remoteBranchName);
return gitTools.push(this.path, remote.remote || this.currentRemote,remote.branch, setRemote, authCache.get(this.name,this.remotes[this.currentRemote].fetch));
return gitTools.push(this.path, remote.remote || this.currentRemote,remote.branch, setRemote, authCache.get(this.name,this.remotes[remote.remote || this.currentRemote].fetch));
};
Project.prototype.pull = function (remoteBranchName,setRemote) {

View File

@ -489,7 +489,12 @@ module.exports = {
},
getRemotes: getRemotes,
getRemoteBranch: function(cwd) {
return runGitCommand(['rev-parse','--abbrev-ref','--symbolic-full-name','@{u}'],cwd)
return runGitCommand(['rev-parse','--abbrev-ref','--symbolic-full-name','@{u}'],cwd).catch(function(err) {
if (/no upstream configured for branch/.test(err.message)) {
return null;
}
throw err;
})
},
getBranches: getBranches,
getBranchInfo: getBranchInfo,