Comments (13)
Hi and thanks for the feedback! I think this is a good idea. As far as I can think of now, it shouldn't be too difficult. Just need the following, for support on post-commit as well:
- Have the previous version in a variable, re-set version in files.
- Check if comitted with message as defined as message (if so,
git reset
) - Check if tag created witht the tag name as defined (if so,
git tag -d
)
Scripts defined in pre-/post-hooks can't be undone, though.
from mversion.
I read your issue again and saw that I read it incorrectly the first time. pre-commit
only needed a git checkout, I implemented support for this in 53a55e3. Would be great if you could test it out and give feedback (can try it out by doing npm link
and npm link mversion
).
from mversion.
@mikaelbr It doesn't look like it works because I want to rollback the package.json
bump. However, since it's already staged it can't just be checked back out.
from mversion.
Pre-commit should happen before staging of the package.json, and thus a git checkout should work? It seemed to work as expected with me. Testing with just "exit 1".
from mversion.
Hmm, the files are all staged for me (why would it do a commit without it being staged?). I even tried it with just exit 1
.
from mversion.
I need to do a git reset HEAD package.json
to revert the state.
from mversion.
What version are you testing out?
From code:
Precommit happens here: https://github.com/mikaelbr/mversion/blob/master/index.js#L183-L188
But staging doesn't happen before: https://github.com/mikaelbr/mversion/blob/master/index.js#L192
Are you sure you are using the current un-released version?
(You can try the "edge" version by doing npm install -g mikaelbr/mversion
)
from mversion.
@mikaelbr I'm already using the latest version. Here's the issue:
Make package.json
and git init
:
{
"version": "0.0.0",
"scripts": {
"test": "exit 1"
},
"dependencies": {
"pre-commit": "^1.0.6"
}
}
Attempt to version:
mversion patch -m
Note that package.json
is staged.
from mversion.
I did this in a clean directory:
With package.json:
{
"version": "0.0.0",
"scripts": {
"test": "exit 1"
},
"dependencies": {
"pre-commit": "^1.0.6"
}
}
And .mversionrc
:
{
"scripts": {
"precommit": "npm test"
}
}
➜ mversion npm i -g mikaelbr/mversion
➜ mversion nano package.json
➜ mversion git init
Initialized empty Git repository in /tmp/mversion/.git/
➜ mversion git:(master) ✗ gst
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
package.json
nothing added to commit but untracked files present (use "git add" to track)
➜ mversion git:(master) ✗ ga . && gc -m "Initial commit"
[master (root-commit) 4c28c45] Initial commit
1 file changed, 9 insertions(+)
create mode 100644 package.json
➜ mversion git:(master) nano .mversionrc
➜ mversion git:(master) ✗ ga . && gc -m "Adds mversion rc"
[master 4d4f471] Adds mversion rc
1 file changed, 5 insertions(+)
create mode 100644 .mversionrc
➜ mversion git:(master) mversion patch -m
Error running precommit: Command failed: /bin/sh -c npm test
npm ERR! Test failed. See above for more details.
Stopping execution
➜ mversion git:(master) gst
On branch master
nothing to commit, working directory clean
As you see, there is no changes in the repo and the minor release has been reverted.
from mversion.
@mikaelbr Why would I need the .mversionrc
file? The pre-commit
module should already be adding the precommit hook to git for me. That looks like the different between what we're going and why it doesn't work as expected for me - I expected the change to work with existing git commit hooks.
from mversion.
Ag, no, sorry. This module doesn't work on git pre-commit hooks but as seperate hooks much like the npm "post_install" hook. See the section with mversionrc in the readme for more info
from mversion.
Ah, ok. Thanks for the heads up. Do you expect it would be possible to hook onto normal pre-commit
hooks since I have tests that run every time I try to commit (which may fail)? Either way, it's a neat little piece of functionality - I just figured it'd be easy enough to rollback everything automatically with a git reset HEAD .
and git checkout -- .
since (IIRC) you only version when the working directory is clean.
Edit: Potentially it could take the staged/unstaged files and save the contents to be restored when commit fails. I can look into adding it, but it's not really a priority since it only really saves me like 5 minutes a week.
from mversion.
I think the way it is now is the cleanest/easiest way to interact with it. Feel free to add a patch, though, but until then I'm closing this. Thanks for your feedback.
from mversion.
Related Issues (20)
- Paramenter `-m` doesn't create a tag HOT 4
- Execute precommit scripts right before the actual commit HOT 6
- mversion -m failing on Windows7 HOT 3
- Add "files" entry in package.json or .npmignore HOT 4
- Show 'next' version number. HOT 2
- Can't seem to run a build task in the right hook HOT 2
- Feature Request: `mversion -a` HOT 2
- TypeError on fresh install HOT 1
- no precommit nor postcommit execution HOT 4
- no output from preupdate script
- mversion with custom cwd from command line scripts HOT 2
- Handle explicit version that matches current version
- Support sonarqube properties files
- Avoiding bower.json
- is plan to support ios or android project HOT 1
- Please update MINIMATCH dependency HOT 1
- dependencies update HOT 3
- Not working if <newversion> argument contains '-h' in it
- GHSL-2020-110 HOT 2
- Remote Command Execution in mversion HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mversion.