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

cli: add --no-history flag not to preserve deploy history #277

Merged
merged 1 commit into from Jan 7, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions bin/gh-pages.js
Expand Up @@ -66,6 +66,10 @@ function main(args) {
ghpages.defaults.only
)
.option('-n, --no-push', 'Commit only (with no push)')
.option(
'-f, --no-history',
'Push force new commit without parent history'
)
.parse(args);

let user;
Expand Down Expand Up @@ -95,6 +99,7 @@ function main(args) {
only: program.remove,
remote: program.remote,
push: !!program.push,
history: !!program.history,
user: user
};

Expand Down
17 changes: 15 additions & 2 deletions lib/git.js
Expand Up @@ -176,10 +176,15 @@ Git.prototype.tag = function(name) {
* Push a branch.
* @param {string} remote Remote alias.
* @param {string} branch Branch name.
* @param {boolean} force Force push.
* @return {Promise} A promise.
*/
Git.prototype.push = function(remote, branch) {
return this.exec('push', '--tags', remote, branch);
Git.prototype.push = function(remote, branch, force) {
const args = ['push', '--tags', remote, branch];
if (force) {
args.push('--force');
}
return this.exec.apply(this, args);
};

/**
Expand Down Expand Up @@ -212,6 +217,14 @@ Git.prototype.getRemoteUrl = function(remote) {
});
};

/**
* Delete ref to remove branch history
* @param {string} branch
*/
Git.prototype.deleteRef = function(branch) {
return this.exec('update-ref', '-d', 'refs/heads/' + branch);
};

/**
* Clone a repo into the given dir if it doesn't already exist.
* @param {string} repo Repository URL.
Expand Down
10 changes: 9 additions & 1 deletion lib/index.js
Expand Up @@ -33,6 +33,7 @@ exports.defaults = {
src: '**/*',
only: '.',
push: true,
history: true,
message: 'Updates',
silent: false
};
Expand Down Expand Up @@ -142,6 +143,13 @@ exports.publish = function publish(basePath, config, callback) {
log('Checking out %s/%s ', options.remote, options.branch);
return git.checkout(options.remote, options.branch);
})
.then(git => {
if (!options.history) {
return git.deleteRef(options.branch);
} else {
return git;
}
})
.then(git => {
if (!options.add) {
log('Removing files');
Expand Down Expand Up @@ -193,7 +201,7 @@ exports.publish = function publish(basePath, config, callback) {
.then(git => {
if (options.push) {
log('Pushing');
return git.push(options.remote, options.branch);
return git.push(options.remote, options.branch, !options.history);
} else {
return git;
}
Expand Down
13 changes: 13 additions & 0 deletions readme.md
Expand Up @@ -241,6 +241,19 @@ ghpages.publish('dist', {push: false}, callback);
```


#### <a id="optionshistory">options.history</a>
* type: `boolean`
* default: `true`

Push force new commit without parent history.

Example use of the `history` option:

```js
ghpages.publish('dist', {history: false}, callback);
```


#### <a id="optionssilent">options.silent</a>
* type: `boolean`
* default: `false`
Expand Down
5 changes: 5 additions & 0 deletions test/bin/gh-pages.spec.js
Expand Up @@ -26,6 +26,11 @@ describe('gh-pages', () => {
dist: 'lib',
config: {push: false}
},
{
args: ['--dist', 'lib', '-f'],
dist: 'lib',
config: {history: false}
},
{
args: ['--dist', 'lib', '-x'],
dist: 'lib',
Expand Down