Skip to content

Commit 4be5704

Browse files
authored
Fix missing tracked decorations (#3801)
1 parent 695719e commit 4be5704

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

extension/src/repository/model/collect.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,55 @@ describe('collectDataStatus', () => {
251251
makeAbsPathSet(dvcDemoPath, rawDataDir)
252252
)
253253
})
254+
255+
it('should fill in the gaps for tracked decorations', () => {
256+
const data = {
257+
not_in_remote: [
258+
join('static', 'uploads', 'images', '2019-12-14', 'devsprints.png')
259+
],
260+
unchanged: [
261+
join('static', 'uploads', 'images', '2019-09-26', 'dvc-org.png')
262+
],
263+
uncommitted: {
264+
added: [
265+
join(
266+
'static',
267+
'uploads',
268+
'images',
269+
'2017-05-15',
270+
'20190925_181739.jpg'
271+
)
272+
],
273+
modified: [join('static', 'uploads') + sep]
274+
}
275+
}
276+
const collected = collectDataStatus(dvcDemoPath, data)
277+
278+
expect(
279+
collected.trackedDecorations.has(
280+
join(
281+
dvcDemoPath,
282+
'static',
283+
'uploads',
284+
'images',
285+
'2019-09-26',
286+
'dvc-org.png'
287+
)
288+
)
289+
).toBe(true)
290+
291+
expect(
292+
collected.trackedDecorations.has(
293+
join(dvcDemoPath, 'static', 'uploads', 'images')
294+
)
295+
).toBe(true)
296+
297+
expect(
298+
collected.trackedDecorations.has(
299+
join(dvcDemoPath, 'static', 'uploads', 'images', '2019-09-26')
300+
)
301+
).toBe(true)
302+
})
254303
})
255304

256305
const makeUri = (...paths: string[]): Uri =>

extension/src/repository/model/collect.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join, relative, resolve } from 'path'
1+
import { join, relative, resolve, sep } from 'path'
22
import { Uri } from 'vscode'
33
import { Resource } from '../commands'
44
import { addToMapSet } from '../../util/map'
@@ -195,6 +195,33 @@ const uncommitNotInCache = (
195195
return ('un' + status) as ExtendedStatus
196196
}
197197

198+
const collectMissingTracked = (
199+
trackedDecorations: Set<String>,
200+
path: string,
201+
add: boolean
202+
) => {
203+
if (add) {
204+
trackedDecorations.add(path)
205+
}
206+
}
207+
208+
const fillGapsInTrackedDecorations = (
209+
rootDepth: number,
210+
trackedDecorations: Set<string>
211+
) => {
212+
for (const path of trackedDecorations) {
213+
const pathArray = getPathArray(path)
214+
let add = false
215+
for (let idx = rootDepth; idx < pathArray.length; idx++) {
216+
const currPath = getPath(pathArray, idx)
217+
if (trackedDecorations.has(currPath)) {
218+
add = true
219+
}
220+
collectMissingTracked(trackedDecorations, currPath, add)
221+
}
222+
}
223+
}
224+
198225
const collectGroupWithMissingAncestors = (
199226
acc: DataStatusAccumulator,
200227
dvcRoot: string,
@@ -214,6 +241,11 @@ const collectGroupWithMissingAncestors = (
214241

215242
addToTracked(acc.trackedDecorations, absPath, originalStatus)
216243
}
244+
245+
fillGapsInTrackedDecorations(
246+
dvcRoot.split(sep).length + 1,
247+
acc.trackedDecorations
248+
)
217249
}
218250

219251
export const collectDataStatus = (

0 commit comments

Comments
 (0)