File tree Expand file tree Collapse file tree 2 files changed +22
-8
lines changed
src/utils/function_change Expand file tree Collapse file tree 2 files changed +22
-8
lines changed Original file line number Diff line number Diff line change @@ -9,12 +9,19 @@ import { DiffFunctionInfo, FunctionInfo } from '../../type';
9
9
10
10
// get the change of function before and after file change
11
11
export function getFunctionDiffInfo ( filePath : string , commitSha ?: string ) {
12
- const functionInfoNow = getFunctionBlock ( filePath ) ;
13
-
14
12
let functionInfoBefore ;
13
+ let functionInfoNow ;
14
+
15
+ if ( ! fs . existsSync ( filePath ) ) { // file deleted
16
+ functionInfoNow = { } ;
17
+ } else {
18
+ functionInfoNow = getFunctionBlock ( filePath ) ;
19
+ }
20
+
15
21
const blobId = getFileCtxBeforeChange ( filePath , commitSha ) ;
16
22
if ( ! blobId ) {
17
- functionInfoBefore = functionInfoNow ;
23
+ // treat it as a new file
24
+ functionInfoBefore = { } ;
18
25
} else {
19
26
const beforeCtx = execaCommandSync ( `git cat-file blob ${ blobId } ` ) . stdout ;
20
27
const tempFile = `./temp_${ path . posix . basename ( filePath ) } ` ;
Original file line number Diff line number Diff line change 1
1
import { execaCommandSync } from 'execa' ;
2
2
import { FileChange } from '../../type' ;
3
3
4
- const COMMAND = 'git diff --name-status' ;
4
+ const COMMANDS = [ 'git diff --name-status' , 'git diff --name-status --staged' ] ;
5
5
6
6
const formatList = ( str : string , type : string ) => {
7
7
const arr = str . split ( '\n' ) . filter ( item => {
@@ -22,11 +22,18 @@ export function getFileChange () {
22
22
23
23
const typeList = [ 'M' , 'D' , 'A' ] ;
24
24
25
- const changeInfo = execaCommandSync ( COMMAND ) . stdout ;
25
+ for ( const command of COMMANDS ) {
26
+ const changeInfo = execaCommandSync ( command ) . stdout ;
26
27
27
- typeList . forEach ( type => {
28
- result [ type ] = formatList ( changeInfo , type )
29
- } )
28
+ typeList . forEach ( type => {
29
+ const formatResult = formatList ( changeInfo , type ) ;
30
+ if ( result [ type ] ) {
31
+ result [ type ] . push ( ...formatResult ) ;
32
+ } else {
33
+ result [ type ] = formatResult ;
34
+ }
35
+ } ) ;
36
+ }
30
37
31
38
return result ;
32
39
}
You can’t perform that action at this time.
0 commit comments