Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dry-run option #1141

Merged
merged 1 commit into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ class Generator extends EventEmitter {
this.conflicter = new Conflicter(this.env.adapter, this.options.force, {
bail: this.options.bail,
ignoreWhitespace: this.options.whitespace,
skipRegenerate: this.options.skipRegenerate
skipRegenerate: this.options.skipRegenerate,
dryRun: this.options.dryRun
});

// Mirror the adapter log method on the generator.
Expand Down
17 changes: 17 additions & 0 deletions lib/util/conflicter.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Conflicter {
this.bail = options.bail;
this.ignoreWhitespace = options.ignoreWhitespace;
this.skipRegenerate = options.skipRegenerate;
this.dryRun = options.dryRun;
}

this.force = force === true;
Expand All @@ -56,6 +57,11 @@ class Conflicter {
this.ignoreWhitespace = true;
this.skipRegenerate = true;
}

if (this.dryRun) {
// Ignore whitespace changes with "ignoreWhitespace === true" option
this.skipRegenerate = true;
}
}

/**
Expand Down Expand Up @@ -210,6 +216,11 @@ class Conflicter {
throw new ConflictError();
}

if (this.dryRun) {
cb('skip');
return;
}

cb('create');
return;
}
Expand All @@ -228,6 +239,12 @@ class Conflicter {
throw new ConflictError();
}

if (this.dryRun) {
this._printDiff(file);
cb('skip');
return;
}

this._ask(file, cb);
} else {
this.adapter.log.identical(rfilepath);
Expand Down
69 changes: 69 additions & 0 deletions test/conflicter.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,75 @@ describe('Conflicter', () => {
done();
});

it('skip file changes with dryRun', function(done) {
const conflicter = new Conflicter(new TestAdapter(), false, {
dryRun: true
});
conflicter.collision(
{
path: path.join(__dirname, 'fixtures/file-conflict.txt'),
contents: `initial
content
`
},
status => {
assert.equal(status, 'skip');
done();
}
);
});

it('skip new file with dryRun', function(done) {
const conflicter = new Conflicter(new TestAdapter(), false, {
dryRun: true
});
conflicter.collision(
{
path: 'file-who-does-not-exist2.js',
contents: ''
},
status => {
assert.equal(status, 'skip');
done();
}
);
});

it('skip deleted file with dryRun', function(done) {
const conflicter = new Conflicter(new TestAdapter(), false, {
dryRun: true
});
conflicter.collision(
{
path: path.join(__dirname, 'fixtures/foo.js'),
contents: null
},
status => {
assert.equal(status, 'skip');
done();
}
);
});

it('skip whitespace changes with dryRun', function(done) {
const conflicter = new Conflicter(new TestAdapter(), false, {
dryRun: true,
ignoreWhitespace: true
});
conflicter.collision(
{
path: path.join(__dirname, 'fixtures/file-conflict.txt'),
contents: `initial
content
`
},
status => {
assert.equal(status, 'skip');
done();
}
);
});

it('does not give a conflict with ignoreWhitespace', function(done) {
const conflicter = new Conflicter(new TestAdapter(), false, {
ignoreWhitespace: true
Expand Down