@@ -22,14 +22,16 @@ import { isDvcError } from '../../cli/dvc/reader'
2222import { Disposable } from '../../class/dispose'
2323import { sameContents } from '../../util/array'
2424import { Data } from '../data'
25- import { isDirectory } from '../../fileSystem'
25+ import { isDirectory , isSameOrChild } from '../../fileSystem'
2626import { DOT_DVC } from '../../cli/dvc/constants'
2727import { getCliErrorLabel } from '../../tree'
28+ import { RepositoryState as GitRepositoryState } from '../../extensions/git'
2829
2930export class RepositoryModel extends Disposable {
3031 private readonly dvcRoot : string
3132
32- private hasChanges = false
33+ private hasGitChanges = false
34+ private hasDvcChanges = false
3335
3436 private tracked = new Set < string > ( )
3537
@@ -49,7 +51,26 @@ export class RepositoryModel extends Disposable {
4951 return this . tree . get ( path ) || [ ]
5052 }
5153
52- public transformAndSet ( { dataStatus, hasGitChanges, untracked } : Data ) {
54+ public async transformAndSetGit ( state : GitRepositoryState ) {
55+ const [ workingTreeChanges , indexChanges , mergeChanges ] = await Promise . all ( [
56+ state . workingTreeChanges . filter ( ( { uri } ) =>
57+ isSameOrChild ( this . dvcRoot , uri . fsPath )
58+ ) ,
59+ state . indexChanges . filter ( ( { uri } ) =>
60+ isSameOrChild ( this . dvcRoot , uri . fsPath )
61+ ) ,
62+ state . mergeChanges . filter ( ( { uri } ) =>
63+ isSameOrChild ( this . dvcRoot , uri . fsPath )
64+ )
65+ ] )
66+
67+ this . hasGitChanges =
68+ workingTreeChanges . length > 0 ||
69+ indexChanges . length > 0 ||
70+ mergeChanges . length > 0
71+ }
72+
73+ public transformAndSetCli ( { dataStatus, untracked } : Data ) {
5374 if ( isDvcError ( dataStatus ) ) {
5475 return this . handleCliError ( dataStatus )
5576 }
@@ -59,7 +80,7 @@ export class RepositoryModel extends Disposable {
5980 untracked : [ ...untracked ] . map ( path => relative ( this . dvcRoot , path ) )
6081 } )
6182 this . collectTree ( data . tracked )
62- this . collectHasChanges ( data , hasGitChanges )
83+ this . collectHasDvcChanges ( data )
6384
6485 return {
6586 scmDecorationState : this . getScmDecorationState ( data ) ,
@@ -68,12 +89,12 @@ export class RepositoryModel extends Disposable {
6889 }
6990
7091 public getHasChanges ( ) : boolean {
71- return this . hasChanges
92+ return this . hasGitChanges || this . hasDvcChanges
7293 }
7394
7495 private handleCliError ( { error : { msg } } : DvcError ) {
7596 const emptyState = createDataStatusAccumulator ( )
76- this . hasChanges = true
97+ this . hasDvcChanges = true
7798
7899 this . tracked = new Set ( )
79100 this . tree = createTreeFromError ( this . dvcRoot , msg )
@@ -97,12 +118,8 @@ export class RepositoryModel extends Disposable {
97118 }
98119 }
99120
100- private collectHasChanges (
101- data : DataStatusAccumulator ,
102- hasGitChanges : boolean
103- ) {
104- this . hasChanges = ! ! (
105- hasGitChanges ||
121+ private collectHasDvcChanges ( data : DataStatusAccumulator ) {
122+ this . hasDvcChanges = ! ! (
106123 data . committedAdded . size > 0 ||
107124 data . committedDeleted . size > 0 ||
108125 data . committedModified . size > 0 ||
0 commit comments