mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-07-13 16:14:27 +02:00
Merge pull request #1104 from kazzna/add-switch-options
Add switch options
This commit is contained in:
commit
6e88757bc4
2 changed files with 91 additions and 15 deletions
|
@ -60,11 +60,67 @@ describe('Git', function() {
|
|||
);
|
||||
});
|
||||
|
||||
it('Switches', function() {
|
||||
return expectTreeAsync(
|
||||
'git switch -c 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"}}'
|
||||
);
|
||||
describe('Switches', function() {
|
||||
it("to a commit", function () {
|
||||
return expectTreeAsync(
|
||||
'git switch C0',
|
||||
'{"branches":{"main":{"target":"C1","id":"main"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"HEAD":{"target":"C0","id":"HEAD"}}'
|
||||
);
|
||||
});
|
||||
|
||||
it("to a branch", function () {
|
||||
return expectTreeAsync(
|
||||
'git switch 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"}}',
|
||||
'{"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":"main","id":"HEAD"}}'
|
||||
);
|
||||
});
|
||||
|
||||
it('to a branch with -c option', function() {
|
||||
return expectTreeAsync(
|
||||
'git switch -c 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('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('to a branch with -C option', function() {
|
||||
return expectTreeAsync(
|
||||
'git switch -C 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"}}',
|
||||
'{"branches":{"main":{"target":"C1","id":"main"},"side":{"target":"C0","id":"side"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"HEAD":{"target":"main","id":"HEAD"}}'
|
||||
);
|
||||
});
|
||||
|
||||
it('to a branch with -C option and given base branch', function() {
|
||||
return expectTreeAsync(
|
||||
'git switch -C side main',
|
||||
'{"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":"C0","id":"side"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"HEAD":{"target":"C0","id":"HEAD"}}'
|
||||
);
|
||||
});
|
||||
|
||||
it('to a branch with --force-create option', function() {
|
||||
return expectTreeAsync(
|
||||
'git switch --force-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"}}',
|
||||
'{"branches":{"main":{"target":"C1","id":"main"},"side":{"target":"C0","id":"side"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"HEAD":{"target":"main","id":"HEAD"}}'
|
||||
);
|
||||
});
|
||||
|
||||
it('to a branch with --force-create option and given base branch', function() {
|
||||
return expectTreeAsync(
|
||||
'git switch --force-create side main',
|
||||
'{"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":"C0","id":"side"}},"commits":{"C0":{"parents":[],"id":"C0","rootCommit":true},"C1":{"parents":["C0"],"id":"C1"}},"HEAD":{"target":"C0","id":"HEAD"}}'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Rebases', function() {
|
||||
|
|
|
@ -923,23 +923,43 @@ var commandConfig = {
|
|||
regex: /^git +switch($|\s)/,
|
||||
options: [
|
||||
'-c',
|
||||
'--create',
|
||||
'-C',
|
||||
'--force-create',
|
||||
'-'
|
||||
],
|
||||
execute: function(engine, command) {
|
||||
var generalArgs = command.getGeneralArgs();
|
||||
var commandOptions = command.getOptionsMap();
|
||||
|
||||
var args = null;
|
||||
if (commandOptions['-c']) {
|
||||
// the user is really trying to just make a
|
||||
// branch and then switch to it. so first:
|
||||
args = commandOptions['-c'].concat(generalArgs);
|
||||
command.twoArgsImpliedHead(args, '-c');
|
||||
{
|
||||
let createOption = commandOptions['-c'] ? commandOptions['-c'] : commandOptions['--create'];
|
||||
if (createOption) {
|
||||
// the user is really trying to just make a
|
||||
// branch and then switch to it. so first:
|
||||
let args = createOption.concat(generalArgs)
|
||||
command.twoArgsImpliedHead(args, '-c');
|
||||
|
||||
var validId = engine.validateBranchName(args[0]);
|
||||
engine.branch(validId, args[1]);
|
||||
engine.checkout(validId);
|
||||
return;
|
||||
let validId = engine.validateBranchName(args[0]);
|
||||
engine.branch(validId, args[1]);
|
||||
engine.checkout(validId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
let sfc = '-C';
|
||||
let lfc = '--force-create';
|
||||
let fcOption = commandOptions[sfc] ? commandOptions[sfc] : commandOptions[lfc];
|
||||
if (fcOption) {
|
||||
let args = fcOption.concat(generalArgs);
|
||||
command.twoArgsImpliedHead(args, sfc);
|
||||
|
||||
let validId = engine.validateBranchName(args[0]);
|
||||
engine.forceBranch(validId, args[1]);
|
||||
engine.checkout(validId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (commandOptions['-']) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue