Skip to content

Commit c7fca1c

Browse files
committed
git: checkout & branch commands
1 parent 79b37a7 commit c7fca1c

3 files changed

Lines changed: 56 additions & 25 deletions

File tree

extensions/git/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@
119119
"title": "Undo Last Commit",
120120
"category": "Git"
121121
},
122+
{
123+
"command": "git.checkout",
124+
"title": "Checkout to...",
125+
"category": "Git"
126+
},
127+
{
128+
"command": "git.branch",
129+
"title": "Create Branch...",
130+
"category": "Git"
131+
},
122132
{
123133
"command": "git.pull",
124134
"title": "Pull",

extensions/git/src/commands.ts

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,36 @@ export class CommandCenter {
295295
return await this.model.clean(...this.model.workingTreeGroup.resources);
296296
}
297297

298+
@CommandCenter.Command('git.commitStaged')
299+
@CommandCenter.CatchErrors
300+
async commitStaged(): Promise<void> {
301+
await Promise.reject('not implemented');
302+
}
303+
304+
@CommandCenter.Command('git.commitStagedSigned')
305+
@CommandCenter.CatchErrors
306+
async commitStagedSigned(): Promise<void> {
307+
await Promise.reject('not implemented');
308+
}
309+
310+
@CommandCenter.Command('git.commitAll')
311+
@CommandCenter.CatchErrors
312+
async commitAll(): Promise<void> {
313+
await Promise.reject('not implemented');
314+
}
315+
316+
@CommandCenter.Command('git.commitAllSigned')
317+
@CommandCenter.CatchErrors
318+
async commitAllSigned(): Promise<void> {
319+
await Promise.reject('not implemented');
320+
}
321+
322+
@CommandCenter.Command('git.undoCommit')
323+
@CommandCenter.CatchErrors
324+
async undoCommit(): Promise<void> {
325+
await Promise.reject('not implemented');
326+
}
327+
298328
@CommandCenter.Command('git.checkout')
299329
@CommandCenter.CatchErrors
300330
async checkout(): Promise<void> {
@@ -323,34 +353,20 @@ export class CommandCenter {
323353
await choice.run(this.model);
324354
}
325355

326-
@CommandCenter.Command('git.commitStaged')
327-
@CommandCenter.CatchErrors
328-
async commitStaged(): Promise<void> {
329-
await Promise.reject('not implemented');
330-
}
331-
332-
@CommandCenter.Command('git.commitStagedSigned')
333-
@CommandCenter.CatchErrors
334-
async commitStagedSigned(): Promise<void> {
335-
await Promise.reject('not implemented');
336-
}
337-
338-
@CommandCenter.Command('git.commitAll')
356+
@CommandCenter.Command('git.branch')
339357
@CommandCenter.CatchErrors
340-
async commitAll(): Promise<void> {
341-
await Promise.reject('not implemented');
342-
}
358+
async branch(): Promise<void> {
359+
const result = await window.showInputBox({
360+
placeHolder: 'Branch name',
361+
prompt: 'Please provide a branch name'
362+
});
343363

344-
@CommandCenter.Command('git.commitAllSigned')
345-
@CommandCenter.CatchErrors
346-
async commitAllSigned(): Promise<void> {
347-
await Promise.reject('not implemented');
348-
}
364+
if (!result) {
365+
return;
366+
}
349367

350-
@CommandCenter.Command('git.undoCommit')
351-
@CommandCenter.CatchErrors
352-
async undoCommit(): Promise<void> {
353-
await Promise.reject('not implemented');
368+
const name = result.replace(/^\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.$/g, '-');
369+
await this.model.branch(name);
354370
}
355371

356372
@CommandCenter.Command('git.pull')

extensions/git/src/model.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ export class Model {
322322
await this.update();
323323
}
324324

325+
async branch(name: string): Promise<void> {
326+
await this.repository.branch(name, true);
327+
await this.update();
328+
}
329+
325330
async checkout(treeish: string): Promise<void> {
326331
await this.repository.checkout(treeish, []);
327332
await this.update();

0 commit comments

Comments
 (0)