mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add delete local branch option
This commit is contained in:
@@ -234,7 +234,7 @@ Project.prototype.update = function (user, data) {
|
||||
if (data.git.hasOwnProperty('remotes')) {
|
||||
var remoteNames = Object.keys(data.git.remotes);
|
||||
var remotesChanged = false;
|
||||
var modifyRemotesPromise = when.resolve();
|
||||
var modifyRemotesPromise = Promise.resolve();
|
||||
remoteNames.forEach(function(name) {
|
||||
if (data.git.remotes[name].removed) {
|
||||
remotesChanged = true;
|
||||
@@ -348,7 +348,7 @@ Project.prototype.status = function(user) {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
fetchPromise = when.resolve();
|
||||
fetchPromise = Promise.resolve();
|
||||
}
|
||||
|
||||
var completeStatus = function(fetchError) {
|
||||
@@ -461,18 +461,23 @@ Project.prototype.getBranches = function (user, isRemote) {
|
||||
if (isRemote) {
|
||||
fetchPromise = self.fetch(user);
|
||||
} else {
|
||||
fetchPromise = when.resolve();
|
||||
fetchPromise = Promise.resolve();
|
||||
}
|
||||
return fetchPromise.then(function() {
|
||||
return gitTools.getBranches(self.path,isRemote);
|
||||
});
|
||||
};
|
||||
|
||||
Project.prototype.deleteBranch = function (user, branch, isRemote, force) {
|
||||
// TODO: isRemote==true support
|
||||
// TODO: make sure we don't try to delete active branch
|
||||
return gitTools.deleteBranch(this.path,branch,isRemote, force);
|
||||
};
|
||||
|
||||
Project.prototype.fetch = function(user,remoteName) {
|
||||
var username;
|
||||
if (!user) {
|
||||
username = "_";
|
||||
console.log(new Error().stack);
|
||||
} else {
|
||||
username = user.username;
|
||||
}
|
||||
@@ -484,7 +489,7 @@ Project.prototype.fetch = function(user,remoteName) {
|
||||
})
|
||||
} else {
|
||||
var remotes = Object.keys(this.remotes);
|
||||
var promise = when.resolve();
|
||||
var promise = Promise.resolve();
|
||||
remotes.forEach(function(remote) {
|
||||
promise = promise.then(function() {
|
||||
return gitTools.fetch(project.path,remote,authCache.get(project.name,project.remotes[remote].fetch,username))
|
||||
@@ -661,7 +666,7 @@ function createProject(user, metadata) {
|
||||
}
|
||||
|
||||
var project = metadata.name;
|
||||
return when.promise(function(resolve,reject) {
|
||||
return new Promise(function(resolve,reject) {
|
||||
var projectPath = fspath.join(projectsDir,project);
|
||||
fs.stat(projectPath, function(err,stat) {
|
||||
if (!err) {
|
||||
|
@@ -55,10 +55,9 @@ function runGitCommand(args,cwd,env) {
|
||||
err.code = "git_local_overwrite";
|
||||
} else if (/CONFLICT/.test(err.stdout)) {
|
||||
err.code = "git_pull_merge_conflict";
|
||||
} else if (/not fully merged/.test(stderr)) {
|
||||
err.code = "git_delete_branch_unmerged";
|
||||
}
|
||||
|
||||
|
||||
|
||||
return reject(err);
|
||||
}
|
||||
resolve(stdout);
|
||||
@@ -276,8 +275,7 @@ function getBranches(cwd, remote) {
|
||||
if (remote) {
|
||||
args.push('-r');
|
||||
}
|
||||
//TODO: parse out ahead/behind status (currently m[5] vvv )
|
||||
var branchRE = /^([ \*] )(\S+) +(\S+)(?: \[(\S+?)(?:: (.*))?\])? (.*)$/;
|
||||
var branchRE = /^([ \*] )(\S+) +(\S+)(?: \[(\S+?)(?:: (?:ahead (\d+)(?:, )?)?(?:behind (\d+))?)?\])? (.*)$/;
|
||||
return runGitCommand(args,cwd).then(function(output) {
|
||||
var branches = [];
|
||||
var lines = output.split("\n");
|
||||
@@ -288,10 +286,13 @@ function getBranches(cwd, remote) {
|
||||
branch = {
|
||||
name: m[2],
|
||||
remote: m[4],
|
||||
status: m[5],
|
||||
status: {
|
||||
ahead: m[5]||0,
|
||||
behind: m[6]||0,
|
||||
},
|
||||
commit: {
|
||||
sha: m[3],
|
||||
subject: m[6]
|
||||
subject: m[7]
|
||||
}
|
||||
}
|
||||
if (m[1] === '* ') {
|
||||
@@ -516,6 +517,19 @@ module.exports = {
|
||||
args.push(branchName);
|
||||
return runGitCommand(args,cwd);
|
||||
},
|
||||
deleteBranch: function(cwd, branchName, isRemote, force) {
|
||||
if (isRemote) {
|
||||
throw new Error("Deleting remote branches not supported");
|
||||
}
|
||||
var args = ['branch'];
|
||||
if (force) {
|
||||
args.push('-D');
|
||||
} else {
|
||||
args.push('-d');
|
||||
}
|
||||
args.push(branchName);
|
||||
return runGitCommand(args, cwd);
|
||||
},
|
||||
getBranchStatus: getBranchStatus,
|
||||
addRemote: addRemote,
|
||||
removeRemote: removeRemote
|
||||
|
@@ -212,6 +212,12 @@ function getBranches(user, project,isRemote) {
|
||||
checkActiveProject(project);
|
||||
return activeProject.getBranches(user, isRemote);
|
||||
}
|
||||
|
||||
function deleteBranch(user, project, branch, isRemote, force) {
|
||||
checkActiveProject(project);
|
||||
return activeProject.deleteBranch(user, branch, isRemote, force);
|
||||
}
|
||||
|
||||
function setBranch(user, project,branchName,isCreate) {
|
||||
checkActiveProject(project);
|
||||
return activeProject.setBranch(branchName,isCreate).then(function() {
|
||||
@@ -419,6 +425,7 @@ module.exports = {
|
||||
resolveMerge: resolveMerge,
|
||||
abortMerge: abortMerge,
|
||||
getBranches: getBranches,
|
||||
deleteBranch: deleteBranch,
|
||||
setBranch: setBranch,
|
||||
getBranchStatus:getBranchStatus,
|
||||
|
||||
|
Reference in New Issue
Block a user