1
1
import * as vscode from 'vscode'
2
2
import { GitFacade , NO_UPSTREAM } from './GitFacade'
3
- import { Commit } from './types'
4
3
5
4
export const activate = ( context : vscode . ExtensionContext ) : void => {
6
5
@@ -11,6 +10,25 @@ export const activate = (context: vscode.ExtensionContext): void => {
11
10
outputChannel . appendLine ( `${ new Date ( ) . toISOString ( ) } ${ message } ` )
12
11
}
13
12
13
+ const getCommitIcon = ( isInUpstream : boolean , isHighlighted : boolean ) : vscode . IconPath => {
14
+ const getThemeIconUri = ( theme : 'light' | 'dark' ) : vscode . Uri => {
15
+ const fileNameParts : string [ ] = [ ]
16
+ fileNameParts . push ( 'commit' )
17
+ fileNameParts . push ( theme )
18
+ if ( isInUpstream ) {
19
+ fileNameParts . push ( 'upstream' )
20
+ }
21
+ if ( isHighlighted ) {
22
+ fileNameParts . push ( 'highlighted' )
23
+ }
24
+ return vscode . Uri . joinPath ( context . extensionUri , 'images' , `${ fileNameParts . join ( '-' ) } .svg` )
25
+ }
26
+ return {
27
+ light : getThemeIconUri ( 'light' ) ,
28
+ dark : getThemeIconUri ( 'dark' )
29
+ }
30
+ }
31
+
14
32
const disposable = vscode . commands . registerCommand ( 'git-fixup.amendStagedChanges' , async ( ) => {
15
33
16
34
try {
@@ -21,8 +39,8 @@ export const activate = (context: vscode.ExtensionContext): void => {
21
39
}
22
40
git . updateWorkingDirectory ( workspaceFolder )
23
41
24
- const hasStagedFiles = await git . hasStagedFiles ( )
25
- if ( ! hasStagedFiles ) {
42
+ const stagedFiles = await git . getStagedFiles ( )
43
+ if ( stagedFiles . length === 0 ) {
26
44
vscode . window . showErrorMessage ( 'No staged files' )
27
45
return
28
46
}
@@ -39,16 +57,19 @@ export const activate = (context: vscode.ExtensionContext): void => {
39
57
}
40
58
41
59
const commitsNotInUpstream = await git . getCommitsNotInUpstream ( )
42
- const commitChoices = selectableCommits . map ( ( commit : Commit ) => {
60
+ const commitChoices = await Promise . all ( ( selectableCommits . map ( async ( commit ) => {
43
61
const isInUpstream = ( commitsNotInUpstream !== NO_UPSTREAM ) && ( commitsNotInUpstream . find ( ( upstreamCommit ) => upstreamCommit . hash === commit . hash ) === undefined )
62
+ const modifiedFiles = await git . getModifiedFiles ( commit . hash )
63
+ const isHighlighted = modifiedFiles . some ( ( filePath ) => stagedFiles . includes ( filePath ) )
44
64
const messageSubject = commit . subject
45
65
return {
46
- label : `${ isInUpstream ? '$(cloud)' : '$(git-commit)' } ${ messageSubject } ` ,
66
+ iconPath : getCommitIcon ( isInUpstream , isHighlighted ) ,
67
+ label : ` ${ messageSubject } ` ,
47
68
hash : commit . hash ,
48
69
messageSubject,
49
- isInUpstream : isInUpstream
70
+ isInUpstream
50
71
}
51
- } )
72
+ } ) ) )
52
73
const selectedCommit = await vscode . window . showQuickPick ( commitChoices , { placeHolder : 'Select a Git commit to fix up' } )
53
74
54
75
if ( selectedCommit !== undefined ) {
0 commit comments