1+ import { Command } from 'commander' ;
12import { showFilesChooser , showFilesChooserAnd } from './cli' ;
23import { gitStatus , gitAdd , gitReset , gitStash , gitDiff } from './git' ;
34
45export const add = withErrorHandler ( async ( ) => {
5- const status = ( await gitStatus ( ) ) . filter (
6- ( file ) => file . status !== 'staged'
7- ) ;
6+ const status = ( await gitStatus ( ) ) . filter ( ( file ) => file . status !== 'staged' ) ;
87 if ( ! status . length ) {
98 console . log ( '\x1b[33m' , 'There are no changes here. Get back to work 🤓' ) ;
109 return ;
@@ -15,9 +14,7 @@ export const add = withErrorHandler(async () => {
1514} ) ;
1615
1716export const reset = withErrorHandler ( async ( ) => {
18- const status = ( await gitStatus ( ) ) . filter (
19- ( file ) => file . status === 'staged'
20- ) ;
17+ const status = ( await gitStatus ( ) ) . filter ( ( file ) => file . status === 'staged' ) ;
2118 if ( ! status . length ) {
2219 console . log (
2320 '\x1b[33m' ,
@@ -31,40 +28,51 @@ export const reset = withErrorHandler(async () => {
3128} ) ;
3229
3330export const stash = withErrorHandler ( async ( ) => {
34- const status = ( await gitStatus ( ) ) ;
31+ const status = await gitStatus ( ) ;
3532 if ( ! status . length ) {
3633 console . log ( '\x1b[33m' , 'Stash what exactly 🤥?' ) ;
3734 return ;
3835 }
3936 const choices = status . map ( ( file ) => file . path ) ;
40- const { files, message} = await showFilesChooserAnd ( 'Files to stash' , choices , {
41- message : {
42- type : 'input' ,
43- message : 'Leave a message to your future self ("-m").. or not, whatever' ,
37+ const { files, message } = await showFilesChooserAnd (
38+ 'Files to stash' ,
39+ choices ,
40+ {
41+ message : {
42+ type : 'input' ,
43+ message :
44+ 'Leave a message to your future self ("-m").. or not, whatever' ,
45+ } ,
4446 }
45- } ) ;
47+ ) ;
4648
4749 await gitStash ( files , message ) ;
4850} ) ;
4951
50- export const diff = withErrorHandler ( async ( ) => {
51- const status = ( await gitStatus ( ) ) ;
52+ export const diff = withErrorHandler ( async ( comObj : Command ) => {
53+ const cached = comObj . args . includes ( '--cached' ) ;
54+ const status = ( await gitStatus ( ) ) . filter (
55+ ( file ) =>
56+ ! file . deleted &&
57+ ( cached ? file . status === 'staged' : file . status !== 'staged' )
58+ ) ;
59+
5260 if ( ! status . length ) {
5361 console . log ( '\x1b[33m' , `You can't view diff of.. nothing 🧐` ) ;
5462 return ;
5563 }
5664 const choices = status . map ( ( file ) => file . path ) ;
5765 const files = await showFilesChooser ( 'Files to diff' , choices ) ;
5866
59- await gitDiff ( files ) ;
67+ await gitDiff ( files , comObj . args ) ;
6068} ) ;
6169
6270function withErrorHandler ( fn : Function ) {
63- return ( ...args : any [ ] ) : Promise < void > => {
71+ return ( ...args : Array < unknown > ) : Promise < void > => {
6472 try {
6573 return fn ( ...args ) ;
6674 } catch ( error ) {
6775 console . log ( '\x1b[31m' , 'Oops, something went wrong' , error ) ;
6876 }
69- }
70- }
77+ } ;
78+ }
0 commit comments