Added -d and --delete to git push to delete remote branches

This commit is contained in:
Jack Bird 2023-07-15 20:56:07 +01:00
parent f961b0c0c8
commit 229415444e

View file

@ -3,6 +3,7 @@ var intl = require('../intl');
var Graph = require('../graph');
var Errors = require('../util/errors');
const { compact } = require('underscore');
var CommandProcessError = Errors.CommandProcessError;
var GitError = Errors.GitError;
var Warning = Errors.Warning;
@ -744,7 +745,9 @@ var commandConfig = {
push: {
regex: /^git +push($|\s)/,
options: [
'--force'
'--force',
'--delete',
'-d'
],
execute: function(engine, command) {
if (!engine.hasOrigin()) {
@ -758,14 +761,46 @@ var commandConfig = {
var source;
var sourceObj;
var commandOptions = command.getOptionsMap();
var isDelete = commandOptions['-d'] || commandOptions['--delete'];
// git push is pretty complex in terms of
// the arguments it wants as well... get ready!
var generalArgs = command.getGeneralArgs();
// put the commandOption of delete back in the generalArgs
// as it is a flag option
if(isDelete) {
let option = commandOptions['-d'] || commandOptions['--delete'];
generalArgs = option[0] === 'origin'
? option.concat(generalArgs)
: generalArgs.concat(option);
}
command.twoArgsForOrigin(generalArgs);
assertOriginSpecified(generalArgs);
var firstArg = generalArgs[1];
if(isDelete) {
if(!firstArg) {
throw new GitError({
msg: intl.todo(
'--delete doesn\'t make sense without any refs'
)
});
}
if(isColonRefspec(firstArg)) {
throw new GitError({
msg: intl.todo(
'--delete only accepts plain target ref names'
)
});
}
// transform delete target ref to delete colon refspec
firstArg = ":"+firstArg;
}
if (firstArg && isColonRefspec(firstArg)) {
var refspecParts = firstArg.split(':');
source = refspecParts[0];
@ -773,7 +808,7 @@ var commandConfig = {
if (source === "" && !engine.origin.resolveID(destination)) {
throw new GitError({
msg: intl.todo(
'cannot delete branch ' + options.destination + ' which doesnt exist'
'cannot delete branch ' + options.destination + ' which doesn\'t exist'
)
});
}