Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Don't detect executable mode changes on added or deleted files
Browse files Browse the repository at this point in the history
  • Loading branch information
smashwilson committed Aug 9, 2018
1 parent 1a05be8 commit c760c9f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/models/file-patch.js
Expand Up @@ -131,6 +131,12 @@ export default class FilePatch {
didChangeExecutableMode() {
const oldMode = this.getOldMode();
const newMode = this.getNewMode();

if (!oldMode || !newMode) {
// Addition or deletion
return false;
}

return oldMode === '100755' && newMode !== '100755' ||
oldMode !== '100755' && newMode === '100755';
}
Expand Down
32 changes: 32 additions & 0 deletions test/models/file-patch.test.js
Expand Up @@ -17,6 +17,38 @@ function createFilePatch(oldFilePath, newFilePath, status, hunks) {
}

describe('FilePatch', function() {
it('detects executable mode changes', function() {
const of0 = new FilePatch.File({path: 'a.txt', mode: '100644'});
const nf0 = new FilePatch.File({path: 'a.txt', mode: '100755'});
const p0 = new FilePatch.Patch({status: 'modified', hunks: []});
const fp0 = new FilePatch(of0, nf0, p0);
assert.isTrue(fp0.didChangeExecutableMode());

const of1 = new FilePatch.File({path: 'a.txt', mode: '100755'});
const nf1 = new FilePatch.File({path: 'a.txt', mode: '100644'});
const p1 = new FilePatch.Patch({status: 'modified', hunks: []});
const fp1 = new FilePatch(of1, nf1, p1);
assert.isTrue(fp1.didChangeExecutableMode());

const of2 = new FilePatch.File({path: 'a.txt', mode: '100755'});
const nf2 = new FilePatch.File({path: 'a.txt', mode: '100755'});
const p2 = new FilePatch.Patch({status: 'modified', hunks: []});
const fp2 = new FilePatch(of2, nf2, p2);
assert.isFalse(fp2.didChangeExecutableMode());

const of3 = FilePatch.File.empty();
const nf3 = new FilePatch.File({path: 'a.txt', mode: '100755'});
const p3 = new FilePatch.Patch({status: 'modified', hunks: []});
const fp3 = new FilePatch(of3, nf3, p3);
assert.isFalse(fp3.didChangeExecutableMode());

const of4 = FilePatch.File.empty();
const nf4 = new FilePatch.File({path: 'a.txt', mode: '100755'});
const p4 = new FilePatch.Patch({status: 'modified', hunks: []});
const fp4 = new FilePatch(of4, nf4, p4);
assert.isFalse(fp4.didChangeExecutableMode());
});

describe('getStagePatchForLines()', function() {
it('returns a new FilePatch that applies only the specified lines', function() {
const filePatch = createFilePatch('a.txt', 'a.txt', 'modified', [
Expand Down

0 comments on commit c760c9f

Please sign in to comment.