diff --git a/bin/creature-start b/bin/creature-start index cc106a8..767cbfa 100755 --- a/bin/creature-start +++ b/bin/creature-start @@ -1,5 +1,8 @@ #!/usr/bin/env node +const path = x => require("../" + x); +const immutable = path("js/immutable"); + const commander = require("commander"); const program = new commander.Command(); @@ -9,13 +12,14 @@ const exec = util.promisify(require("child_process").exec); program.parse(process.argv); function setCurrentBranch(dp) { - return exec(`git branch|grep '\*'|sed 's/\*\s*//'`) + const cmd = "git rev-parse --abbrev-ref HEAD"; + return exec(cmd) .then(x => x.stdout.trim()) .then(x => Object.assign({}, dp, { currentBranch: x })); } function setStandardBranches(dp) { - return Object.assign({}, dp, { standardBranches: ["master", "release"] }); + return immutable.set(dp, "standardBranches", ["master", "release"]); } function validateCurrentBranch(dp) { @@ -26,7 +30,7 @@ function validateCurrentBranch(dp) { } } -function validateFeatureBranch(dp) { +function validateFeatureName(dp) { if (dp.standardBranches.includes(dp.featureName)) { throw `invalid feature branch: ${dp.featureName}`; } else { @@ -49,13 +53,40 @@ function setFeatureBranch(dp) { return Object.assign({}, dp, { featureBranch: fb }); } -const x = Promise.resolve({ program }) +function gitFetch(dp) { + const cmd = "git fetch origin -p && git fetch origin --tags"; + console.log(cmd); + return exec(cmd).then(x => dp); +} + +function setMergeBranch(dp) { + return immutable.set( + dp, + "mergeBranch", + ["origin", dp.currentBranch].join("/") + ); +} + +function gitMerge(dp) { + const cmd = `git merge ${dp.mergeBranch}`; + console.log(cmd); + return exec(cmd).then(x => dp); +} + +function toPromise(dp) { + return Promise.resolve(dp); +} + +const x = toPromise({ program }) .then(setStandardBranches) .then(setFeatureName) + .then(validateFeatureName) .then(setPrefix) .then(setCurrentBranch) .then(validateCurrentBranch) .then(setFeatureBranch) - .then(validateFeatureBranch) + .then(gitFetch) + .then(setMergeBranch) + .then(gitMerge) .then(x => console.log("x", x)) .catch(err => console.error(err)); diff --git a/js/immutable.js b/js/immutable.js new file mode 100644 index 0000000..c3c3e89 --- /dev/null +++ b/js/immutable.js @@ -0,0 +1,13 @@ +const _ = require("lodash"); + +let lib; + +function set(dp, path, value) { + return _.assign({}, dp, _.set({}, path, value)); +} + +lib = { + set +}; + +module.exports = lib; diff --git a/package-lock.json b/package-lock.json index e736f45..fe15913 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,11 @@ "version": "2.20.0", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==" + }, + "lodash": { + "version": "4.17.14", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.14.tgz", + "integrity": "sha512-mmKYbW3GLuJeX+iGP+Y7Gp1AiGHGbXHCOh/jZmrawMmsE7MS4znI3RL2FsjbqOyMayHInjOeykW7PEajUk1/xw==" } } } diff --git a/package.json b/package.json index 2770ec4..d96836e 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ }, "homepage": "https://github.com/rkiel/git-utilities#readme", "dependencies": { - "commander": "^2.20.0" + "commander": "^2.20.0", + "lodash": "^4.17.14" } }