Skip to content

Commit

Permalink
fix: add ignoreEol setting (#547)
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech authored Sep 4, 2020
1 parent 656aa5b commit f7f4f52
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ const config = {
default: false,
description: "Mute 'Latest backup is already applied' message.",
},
ignoreEol: {
title: 'Ignore EOL',
description: 'Ignore end of line characters when checking backup.',
type: 'boolean',
default: false,
},
hiddenSettings: {
title: 'Hidden Settings',
type: 'object',
Expand Down
8 changes: 6 additions & 2 deletions lib/sync-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,12 @@ module.exports = class SyncSettings {
const localFile = localData.files ? localData.files[fileName] : null
if (backupFile && localFile) {
const isBinary = isBinaryPath(fileName)
const localContent = localFile.content.toString(isBinary ? 'base64' : 'utf8')
const backupContent = backupFile.content.toString(isBinary ? 'base64' : 'utf8')
let localContent = localFile.content.toString(isBinary ? 'base64' : 'utf8')
let backupContent = backupFile.content.toString(isBinary ? 'base64' : 'utf8')
if (atom.config.get('sync-settings.ignoreEol')) {
localContent = localContent.replace(/\r\n/g, '\n')
backupContent = backupContent.replace(/\r\n/g, '\n')
}
if (localContent !== backupContent) {
let content
if (isBinary) {
Expand Down
21 changes: 21 additions & 0 deletions spec/sync-settings-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,27 @@ describe('syncSettings', () => {
},
})
})

it('ignore same files with diff EOL', async () => {
atom.config.set('sync-settings.ignoreEol', true)
const diffData = await syncSettings.getDiffData({
files: {
added: { content: 'added\r\n' },
updated: { content: 'updated\r\n' },
},
}, {
files: {
added: { content: 'added\n' },
updated: { content: 'updated\n' },
},
})

expect(diffData).toEqual({
settings: null,
packages: null,
files: null,
})
})
})

describe('check for update', () => {
Expand Down

0 comments on commit f7f4f52

Please sign in to comment.