Skip to content

Commit

Permalink
fix(mergedeep): hasChanges for empty source and non-empty target
Browse files Browse the repository at this point in the history
Fix for empty collaborators config not removing excess members.
Using config `collaborators: []` this fix makes sure that manually
added collaborators are removed.
  • Loading branch information
anderssonjohan committed Jan 24, 2023
1 parent c3ad7b4 commit 852fa64
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/mergeDeep.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ class MergeDeep {
modifications = this.removeEmptyAndNulls(modifications, key)
additions = this.removeEmptyAndNulls(additions, key)
}
return ({ additions, modifications, hasChanges: !this.isEmpty(additions) || !this.isEmpty(modifications) })
let hasChanges = !this.isEmpty(additions) || !this.isEmpty(modifications)
// Indicate changes when source is empty and target is not
hasChanges |= this.isEmpty(source) && !this.isEmpty(target)
return ({ additions, modifications, hasChanges })
}

validateOverride (key, baseconfig, overrideconfig) {
Expand Down
12 changes: 12 additions & 0 deletions test/unit/lib/mergeDeep.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1013,3 +1013,15 @@ it('CompareDeep produces correct result for arrays of named objects', () => {

expect(result.modifications.teams).toEqual(['developers'])
})

it('CompareDeep result has changes when source is empty and target is not', () => {
const ignorableFields = []
const mergeDeep = new MergeDeep(log, ignorableFields)
const target = [
{ username: 'unwanted-collaborator' }
]
const source = []
const result = mergeDeep.compareDeep(target, source)

expect(result.hasChanges).toBeTruthy()
})

0 comments on commit 852fa64

Please sign in to comment.