1+ import * as Git from 'nodegit' ;
2+ import { remote , clipboard } from 'electron' ;
3+ import { RepoState , removeReferencePrefix } from './repo-state' ;
4+ import { InputDialogHandler } from '../components/input-dialog' ;
5+
6+ export function createCommitContextMenu ( repo : RepoState ,
7+ commit : Git . Commit ,
8+ onCreateBranch : ( commit : Git . Commit ) => void ,
9+ onOpenInputDialog : InputDialogHandler ) {
10+ function openCreateTagDialog ( ) {
11+ onOpenInputDialog ( 'Name' , 'Create tag' , ( value ) => repo . createTag ( value , commit ) ) ;
12+ }
13+
14+ const template : Electron . MenuItemConstructorOptions [ ] = [
15+ {
16+ label : 'Create branch here' ,
17+ click : ( ) => onCreateBranch ( commit )
18+ } ,
19+ {
20+ label : 'Cherrypick commit' ,
21+ click : ( ) => repo . cherrypick ( commit )
22+ } ,
23+ ] ;
24+ if ( repo . head ) {
25+ template . push (
26+ {
27+ label : `Reset ${ removeReferencePrefix ( repo . head ) } to this commit` ,
28+ submenu : [
29+ {
30+ label : 'Soft' ,
31+ click : ( ) => repo . reset ( commit , Git . Reset . TYPE . SOFT )
32+ } ,
33+ {
34+ label : 'Mixed' ,
35+ click : ( ) => repo . reset ( commit , Git . Reset . TYPE . MIXED )
36+ } ,
37+ {
38+ label : 'Hard' ,
39+ click : ( ) => repo . reset ( commit , Git . Reset . TYPE . HARD )
40+ }
41+ ]
42+ }
43+ ) ;
44+ }
45+ template . push (
46+ {
47+ label : 'Revert commit' ,
48+ click : ( ) => repo . revert ( commit )
49+ } ,
50+ {
51+ type : 'separator'
52+ } ,
53+ {
54+ label : 'Copy commit sha to clipboard' ,
55+ click : ( ) => clipboard . writeText ( commit . sha ( ) )
56+ } ,
57+ {
58+ type : 'separator'
59+ } ,
60+ {
61+ label : 'Create tag here' ,
62+ click : openCreateTagDialog
63+ }
64+ ) ;
65+ return remote . Menu . buildFromTemplate ( template ) ;
66+ }
0 commit comments