Skip to content

Commit

Permalink
Fix: separate task to check clean working dir (#34), before bump/build
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Sep 21, 2015
1 parent f0f0cb6 commit 7abe320
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 9 additions & 8 deletions lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ function getRemoteUrl() {
});
}

function hasChanges(repo, requireCleanWorkingDir) {
function isWorkingDirClean(requireCleanWorkingDir) {
return requireCleanWorkingDir ? run('!git', 'diff-index --name-only HEAD --exit-code').catch(function() {
throw new Error('Working dir must be clean.');
}) : noop;
}

function hasChanges(repo) {
// Inverted: reject if run promise is resolved (i.e. `git diff-index` returns exit code 0)
return when.promise(function(resolve) {
run('!git', 'diff-index --name-only HEAD --exit-code').then(function() {
Expand All @@ -34,13 +40,7 @@ function hasChanges(repo, requireCleanWorkingDir) {
log.warn('Nothing to commit in ' + repo + ' repo. The latest commit will be tagged.');
}
resolve();
}).catch(function() {
if(requireCleanWorkingDir && repo === 'src') {
log.error('Working dir must be clean.')
} else {
resolve();
}
});
}).catch(resolve);
});
}

Expand Down Expand Up @@ -243,5 +243,6 @@ module.exports = {
getChangelog: getChangelog,
getGithubToken: getGithubToken,
release: release,
isWorkingDirClean: isWorkingDirClean,
hasChanges: hasChanges
};
4 changes: 3 additions & 1 deletion lib/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function releaseSourceRepo(options) {

var executeTasks = [
repo.isRepo,
repo.checkClean,
repo.bump,
repo.build,
repo.stage,
Expand Down Expand Up @@ -167,10 +168,11 @@ function getSrcRepoTasks(options) {
isPublish = !options['non-interactive'] || (options.npm.publish && !options.dist.repo);

return _.extend({}, getGenericTasks(options), {
checkClean: git.isWorkingDirClean.bind(null, options.requireCleanWorkingDir),
bump: shell.bump.bind(null, options.pkgFiles, options.version),
stage: git.stage.bind(null, options.pkgFiles),
stageDir: isStageBuildDir ? git.stageDir.bind(null, options.dist.baseDir) : noop,
hasChanges: git.hasChanges.bind(null, 'src', options.requireCleanWorkingDir),
hasChanges: git.hasChanges.bind(null, 'src'),
push: git.push.bind(null, options.remoteUrl, options.src.pushRepo),
pushTags: git.pushTags.bind(null, options.src.pushRepo),
release: options.github.release ? git.release.bind(null, options, options.remoteUrl) : noop,
Expand Down

0 comments on commit 7abe320

Please sign in to comment.