mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-27 16:38:50 +02:00
Add git switch --create
This commit is contained in:
parent
8a3dd90e35
commit
2edc86e9a0
2 changed files with 20 additions and 10 deletions
|
@ -82,6 +82,13 @@ describe('Git', function() {
|
||||||
'{"branches":{"main":{"target":"C1","id":"main"},"side":{"target":"C1","id":"side"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"HEAD":{"target":"side","id":"HEAD"}}'
|
'{"branches":{"main":{"target":"C1","id":"main"},"side":{"target":"C1","id":"side"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"HEAD":{"target":"side","id":"HEAD"}}'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('to a branch with --create option', function() {
|
||||||
|
return expectTreeAsync(
|
||||||
|
'git switch --create side',
|
||||||
|
'{"branches":{"main":{"target":"C1","id":"main"},"side":{"target":"C1","id":"side"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"HEAD":{"target":"side","id":"HEAD"}}'
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Rebases', function() {
|
it('Rebases', function() {
|
||||||
|
|
|
@ -923,23 +923,26 @@ var commandConfig = {
|
||||||
regex: /^git +switch($|\s)/,
|
regex: /^git +switch($|\s)/,
|
||||||
options: [
|
options: [
|
||||||
'-c',
|
'-c',
|
||||||
|
'--create',
|
||||||
'-'
|
'-'
|
||||||
],
|
],
|
||||||
execute: function(engine, command) {
|
execute: function(engine, command) {
|
||||||
var generalArgs = command.getGeneralArgs();
|
var generalArgs = command.getGeneralArgs();
|
||||||
var commandOptions = command.getOptionsMap();
|
var commandOptions = command.getOptionsMap();
|
||||||
|
|
||||||
var args = null;
|
{
|
||||||
if (commandOptions['-c']) {
|
let createOption = commandOptions['-c'] ? commandOptions['-c'] : commandOptions['--create'];
|
||||||
// the user is really trying to just make a
|
if (createOption) {
|
||||||
// branch and then switch to it. so first:
|
// the user is really trying to just make a
|
||||||
args = commandOptions['-c'].concat(generalArgs);
|
// branch and then switch to it. so first:
|
||||||
command.twoArgsImpliedHead(args, '-c');
|
var args = createOption.concat(generalArgs)
|
||||||
|
command.twoArgsImpliedHead(args, '-c');
|
||||||
|
|
||||||
var validId = engine.validateBranchName(args[0]);
|
var validId = engine.validateBranchName(args[0]);
|
||||||
engine.branch(validId, args[1]);
|
engine.branch(validId, args[1]);
|
||||||
engine.checkout(validId);
|
engine.checkout(validId);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commandOptions['-']) {
|
if (commandOptions['-']) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue