diff --git a/README.md b/README.md index 71133adf..dc7dfd61 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/docs/hgrepo.md b/docs/hgrepo.md index d570add0..529f3737 100644 --- a/docs/hgrepo.md +++ b/docs/hgrepo.md @@ -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) @@ -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' }); ``` @@ -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 @@ -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 @@ -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 @@ -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 @@ -220,7 +216,7 @@ Pulls files to the Hg repo instance. ```javascript let output = await repo.pull(); -console.log(result); +console.log(output); // OR @@ -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 | @@ -250,7 +247,7 @@ Update Hg repo instance. ```javascript let output = await repo.update(); -console.log(result); +console.log(output); // OR @@ -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 @@ -313,7 +310,7 @@ Rename files to the Hg repo instance. ```javascript let output = await repo.merge(); -console.log(result); +console.log(output); // OR @@ -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 diff --git a/src/HgRepo.js b/src/HgRepo.js index 0ac0fbd2..1e73d258 100644 --- a/src/HgRepo.js +++ b/src/HgRepo.js @@ -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 = []; @@ -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) { @@ -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 = []; @@ -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; \ No newline at end of file +module.exports = HgRepo;