mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-07-03 19:24:29 +02:00
Added -d and --delete to git push to delete remote branches
This commit is contained in:
parent
f961b0c0c8
commit
229415444e
1 changed files with 38 additions and 3 deletions
|
@ -3,6 +3,7 @@ var intl = require('../intl');
|
||||||
|
|
||||||
var Graph = require('../graph');
|
var Graph = require('../graph');
|
||||||
var Errors = require('../util/errors');
|
var Errors = require('../util/errors');
|
||||||
|
const { compact } = require('underscore');
|
||||||
var CommandProcessError = Errors.CommandProcessError;
|
var CommandProcessError = Errors.CommandProcessError;
|
||||||
var GitError = Errors.GitError;
|
var GitError = Errors.GitError;
|
||||||
var Warning = Errors.Warning;
|
var Warning = Errors.Warning;
|
||||||
|
@ -744,7 +745,9 @@ var commandConfig = {
|
||||||
push: {
|
push: {
|
||||||
regex: /^git +push($|\s)/,
|
regex: /^git +push($|\s)/,
|
||||||
options: [
|
options: [
|
||||||
'--force'
|
'--force',
|
||||||
|
'--delete',
|
||||||
|
'-d'
|
||||||
],
|
],
|
||||||
execute: function(engine, command) {
|
execute: function(engine, command) {
|
||||||
if (!engine.hasOrigin()) {
|
if (!engine.hasOrigin()) {
|
||||||
|
@ -758,14 +761,46 @@ var commandConfig = {
|
||||||
var source;
|
var source;
|
||||||
var sourceObj;
|
var sourceObj;
|
||||||
var commandOptions = command.getOptionsMap();
|
var commandOptions = command.getOptionsMap();
|
||||||
|
var isDelete = commandOptions['-d'] || commandOptions['--delete'];
|
||||||
|
|
||||||
// git push is pretty complex in terms of
|
// git push is pretty complex in terms of
|
||||||
// the arguments it wants as well... get ready!
|
// the arguments it wants as well... get ready!
|
||||||
var generalArgs = command.getGeneralArgs();
|
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);
|
command.twoArgsForOrigin(generalArgs);
|
||||||
assertOriginSpecified(generalArgs);
|
assertOriginSpecified(generalArgs);
|
||||||
|
|
||||||
var firstArg = generalArgs[1];
|
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)) {
|
if (firstArg && isColonRefspec(firstArg)) {
|
||||||
var refspecParts = firstArg.split(':');
|
var refspecParts = firstArg.split(':');
|
||||||
source = refspecParts[0];
|
source = refspecParts[0];
|
||||||
|
@ -773,7 +808,7 @@ var commandConfig = {
|
||||||
if (source === "" && !engine.origin.resolveID(destination)) {
|
if (source === "" && !engine.origin.resolveID(destination)) {
|
||||||
throw new GitError({
|
throw new GitError({
|
||||||
msg: intl.todo(
|
msg: intl.todo(
|
||||||
'cannot delete branch ' + options.destination + ' which doesnt exist'
|
'cannot delete branch ' + options.destination + ' which doesn\'t exist'
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue