Skip to content

Commit

Permalink
Adding alias, branch options in hg update and cleaning up spelling er…
Browse files Browse the repository at this point in the history
…rors in the readme
  • Loading branch information
jdalrymple committed Oct 30, 2017
1 parent 4825716 commit ada0d5b
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 116 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,17 @@ npm test

# Changelog

[1.2.2](https://github.com/jdalrymple/node-hg-plus/) (2017-10-29)
------------------
- Added Checkout alias for hg update
- Added branch specification for hg update


[1.2.1](https://github.com/jdalrymple/node-hg-plus/93c85be35072e774cf9f8ffa4b2c9caeac8bca76) (2017-10-29)
------------------
- Updating error messages for the creation of hg repositories
- Updating Hg.getRepo to return the correct remote url in the HgRepo instance
- Adding HgRepo.paths()
- Added HgRepo.paths()


[1.2.0](https://github.com/jdalrymple/node-hg-plus/4a7dbff90189e015a1b35e3f53e63c4ce799c12d) (2017-10-03)
Expand Down
29 changes: 13 additions & 16 deletions docs/hgrepo.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* [Hg paths](#hg-paths)
* [Hg push](#hg-push)
* [Hg pull](#hg-pull)
* [Hg update](#hg-update)
* [Hg update / Hg checkout](#hg-update-hg-checkout)
* [Hg rename](#hg-rename)
* [Hg merge](#hg-merge)
* [Convert repo from Hg to Git](#convert-repo-from-hg-to-git)
Expand Down Expand Up @@ -38,9 +38,7 @@ Note: These are only created through Hg.clone or Hg.create

```javascript
const Hg = require('hg-plus')();

let repo1 = await Hg.create({ name: 'my-fancy-repo' });

let repo2 = await Hg.clone({ url: 'http://hostname.com/my/repository/url' });

```
Expand All @@ -60,12 +58,10 @@ Inits the Hg repo instance.

```javascript
const Hg = require('hg-plus')();

let repo = await Hg.create({ name: 'my-fancy-repo' });

let output = await repo.init();

console.log(result);
console.log(output);

// OR

Expand Down Expand Up @@ -126,7 +122,7 @@ Adds untracked files to the Hg repo instance.
```javascript
let output = await repo.add();

console.log(result);
console.log(output);

// OR

Expand All @@ -152,7 +148,7 @@ Gets the paths related to the specific Hg repo instance.
```javascript
let output = await repo.paths();

console.log(result);
console.log(output);

// OR

Expand Down Expand Up @@ -185,7 +181,7 @@ Pushes untracked files to the Hg repo instance.
```javascript
let output = await repo.push();

console.log(result);
console.log(output);

// OR

Expand Down Expand Up @@ -220,7 +216,7 @@ Pulls files to the Hg repo instance.
```javascript
let output = await repo.pull();

console.log(result);
console.log(output);

// OR

Expand All @@ -230,13 +226,14 @@ repo.pull({source: 'my/repository/url/', force: true}, (error, result) => {

```

### Hg update
### Hg update / Hg checkout

Update Hg repo instance.

| Argument | Description | Type | Required | Default |
|------------------|-----------------------|--------------|----------|-------------------|
| options | | Object | No | N/A |
| options.branchOrTag| A branch or tag name| String | No | null |
| options.clean | | Boolean | No | false |
| options.check | | Boolean | No | false |
| options.revision | | String | No | null |
Expand All @@ -250,7 +247,7 @@ Update Hg repo instance.
```javascript
let output = await repo.update();

console.log(result);
console.log(output);

// OR

Expand Down Expand Up @@ -281,9 +278,9 @@ Rename files to the Hg repo instance.
| Promise <String> | Console output |

```javascript
output = await repo.rename('one/path','destination/path');
let output = await repo.rename('one/path','destination/path');

console.log(result);
console.log(output);

// OR

Expand Down Expand Up @@ -313,7 +310,7 @@ Rename files to the Hg repo instance.
```javascript
let output = await repo.merge();

console.log(result);
console.log(output);

// OR

Expand Down Expand Up @@ -343,7 +340,7 @@ Coverts Hg repo instance into a Git repo using the [gitifyhg](https://github.com

```javascript
let output = await repo.gitify();
console.log(result);
console.log(output);


// OR
Expand Down
205 changes: 106 additions & 99 deletions src/HgRepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,6 @@ class HgRepo {
this.path = path || Path.join(process.cwd(), this.name);
}

async init() {
return Command.runWithHandling('hg init', this.path);
}

async commit(message = null, { add = false } = {}, done = undefined) {
if (!message) throw new Error("Commit's must have a message");

const optionalArgs = [];
let output;

if (add) optionalArgs.push('-a');

optionalArgs.push(`-m "${message}"`);

// Cant use wrapper since this failure isnt an error
try {
output = await Command.run('hg commit', this.path, optionalArgs);
} catch (e) {
output = { stdout: e.stdout };

if (!e.stdout.includes('nothing changed')) output.error = e;
}

return Utils.asCallback(output.error, output.stdout, done);
}

async add({ files = [''], include, exclude, subrepos = false, dryRun = false } = {}, done) {
const optionArgs = [];

Expand All @@ -67,82 +41,30 @@ class HgRepo {
return Command.runWithHandling('hg add', this.path, optionArgs, done);
}

async remove({ files = [''], include, exclude, subrepos = false, force = false, after = false } = {}, done) {
const optionArgs = [];

optionArgs.push(files.join(' '));

if (include) optionArgs.push(` -I ${include}`);
if (exclude) optionArgs.push(` -X ${exclude}`);
if (subrepos) optionArgs.push(' -S');
if (force) optionArgs.push(' -f');
if (after) optionArgs.push(' -A');

return Command.runWithHandling('hg remove', this.path, optionArgs, done);
async checkout({ clean = false, check = false, revision, branchOrTag, tool } = {}, done) {
return this.update({ clean, check, revision, branchOrTag, tool }, done);
}

async paths(done) {
const pathsString = await Command.run('hg paths', this.path);
const paths = {};
const lines = pathsString.stdout.split('\n');

lines.forEach((line) => {
if (line === '') return;
const name = line.match(/(^.+)\s=/)[0];
const cleanedName = name.replace('=', '').trim();

paths[cleanedName] = line.replace(name, '').trim();
});

return Utils.asCallback(null, paths, done);
}

async push({ destination = this.url, password, username, force = false, revision, bookmark, branch, newBranch = false, ssh, insecure = false } = {}, done) {
const optionArgs = [];

if (!destination) throw new Error('Missing remote url to push to');

optionArgs.push(Utils.buildRepoURL({ username, password, url: destination }));

if (force) optionArgs.push(' -f');
if (revision) optionArgs.push(` -r ${revision}`);
if (bookmark) optionArgs.push(` -B ${bookmark}`);
if (branch) optionArgs.push(` -b ${branch}`);
if (newBranch) optionArgs.push(' --new-branch');
if (ssh) optionArgs.push(` -e ${ssh}`);
if (insecure) optionArgs.push(' --insecure');

return Command.runWithHandling('hg push', this.path, optionArgs, done);
}

async pull({ source = this.url, force = false, update = false, revision, bookmark, branch, newBranch = false, ssh, insecure = false, } = {}, done) {
const optionArgs = [];

if (!source) throw new Error('Missing remote url to pull from');
async commit(message = null, { add = false } = {}, done) {
if (!message) throw new Error("Commit's must have a message");

optionArgs.push(source);
const optionalArgs = [];
let output;

if (force) optionArgs.push(' -f');
if (update) optionArgs.push(' -u');
if (revision) optionArgs.push(` -r ${revision}`);
if (bookmark) optionArgs.push(` -B ${bookmark}`);
if (branch) optionArgs.push(` -b ${branch}`);
if (newBranch) optionArgs.push(' --new-branch');
if (ssh) optionArgs.push(` -e ${ssh}`);
if (insecure) optionArgs.push(' --insecure');
if (add) optionalArgs.push('-a');

return Command.runWithHandling('hg pull', this.path, optionArgs, done);
}
optionalArgs.push(`-m "${message}"`);

async update({ clean = false, check = false, revision, tool } = {}, done) {
const optionArgs = [];
// Cant use wrapper since this failure isnt an error
try {
output = await Command.run('hg commit', this.path, optionalArgs);
} catch (e) {
output = { stdout: e.stdout };

if (clean) optionArgs.push(' -C');
if (revision) optionArgs.push(` -r ${revision}`);
if (check) optionArgs.push(' -c');
if (tool) optionArgs.push(` -t ${tool}`);
if (!e.stdout.includes('nothing changed')) output.error = e;
}

return Command.runWithHandling('hg update', this.path, optionArgs, done);
return Utils.asCallback(output.error, output.stdout, done);
}

async gitify({ path = Path.resolve(Path.dirname(this.path), `${this.name}-git`), remoteURL, trackAll = false, clean = false } = {}, done) {
Expand Down Expand Up @@ -209,6 +131,88 @@ class HgRepo {
return Utils.asCallback(null, null, done);
}

async init() {
return Command.runWithHandling('hg init', this.path);
}

async merge({ force = false, revision, preview = false, tool } = {}, done) {
const optionArgs = [];

if (force) optionArgs.push(' -f');
if (revision) optionArgs.push(` -r ${revision}`);
if (preview) optionArgs.push(' -p');
if (tool) optionArgs.push(` -t ${tool}`);

return Command.runWithHandling('hg merge', this.path, optionArgs, done);
}

async paths(done) {
const pathsString = await Command.run('hg paths', this.path);
const paths = {};
const lines = pathsString.stdout.split('\n');

lines.forEach((line) => {
if (line === '') return;
const name = line.match(/(^.+)\s=/)[0];
const cleanedName = name.replace('=', '').trim();

paths[cleanedName] = line.replace(name, '').trim();
});

return Utils.asCallback(null, paths, done);
}

async pull({ source = this.url, force = false, update = false, revision, bookmark, branch, newBranch = false, ssh, insecure = false } = {}, done) {
const optionArgs = [];

if (!source) throw new Error('Missing remote url to pull from');

optionArgs.push(source);

if (force) optionArgs.push(' -f');
if (update) optionArgs.push(' -u');
if (revision) optionArgs.push(` -r ${revision}`);
if (bookmark) optionArgs.push(` -B ${bookmark}`);
if (branch) optionArgs.push(` -b ${branch}`);
if (newBranch) optionArgs.push(' --new-branch');
if (ssh) optionArgs.push(` -e ${ssh}`);
if (insecure) optionArgs.push(' --insecure');

return Command.runWithHandling('hg pull', this.path, optionArgs, done);
}

async push({ destination = this.url, password, username, force = false, revision, bookmark, branch, newBranch = false, ssh, insecure = false } = {}, done) {
const optionArgs = [];

if (!destination) throw new Error('Missing remote url to push to');

optionArgs.push(Utils.buildRepoURL({ username, password, url: destination }));

if (force) optionArgs.push(' -f');
if (revision) optionArgs.push(` -r ${revision}`);
if (bookmark) optionArgs.push(` -B ${bookmark}`);
if (branch) optionArgs.push(` -b ${branch}`);
if (newBranch) optionArgs.push(' --new-branch');
if (ssh) optionArgs.push(` -e ${ssh}`);
if (insecure) optionArgs.push(' --insecure');

return Command.runWithHandling('hg push', this.path, optionArgs, done);
}

async remove({ files = [''], include, exclude, subrepos = false, force = false, after = false } = {}, done) {
const optionArgs = [];

optionArgs.push(files.join(' '));

if (include) optionArgs.push(` -I ${include}`);
if (exclude) optionArgs.push(` -X ${exclude}`);
if (subrepos) optionArgs.push(' -S');
if (force) optionArgs.push(' -f');
if (after) optionArgs.push(' -A');

return Command.runWithHandling('hg remove', this.path, optionArgs, done);
}

async rename(source, destination, { after = false, force = false, include, exclude, dryRun = false } = {}, done) {
const optionArgs = [];

Expand All @@ -224,16 +228,19 @@ class HgRepo {
return Command.runWithHandling('hg rename', this.path, optionArgs, done);
}

async merge({ force = false, revision, preview = false, tool } = {}, done) {
async update({ clean = false, check = false, revision, tool, branchOrTag } = {}, done) {
const optionArgs = [];

if (force) optionArgs.push(' -f');
if (branchOrTag) optionArgs.push(branchOrTag);
if (clean) optionArgs.push(' -C');
if (revision) optionArgs.push(` -r ${revision}`);
if (preview) optionArgs.push(' -p');
if (revision) optionArgs.push(` -r ${revision}`);

if (check) optionArgs.push(' -c');
if (tool) optionArgs.push(` -t ${tool}`);

return Command.runWithHandling('hg merge', this.path, optionArgs, done);
return Command.runWithHandling('hg update', this.path, optionArgs, done);
}
}

module.exports = HgRepo;
module.exports = HgRepo;

0 comments on commit ada0d5b

Please sign in to comment.