Giter Club home page Giter Club logo

Comments (13)

mikaelbr avatar mikaelbr commented on August 23, 2024

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:

  1. Have the previous version in a variable, re-set version in files.
  2. Check if comitted with message as defined as message (if so, git reset)
  3. 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.

mikaelbr avatar mikaelbr commented on August 23, 2024

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.

blakeembrey avatar blakeembrey commented on August 23, 2024

@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.

mikaelbr avatar mikaelbr commented on August 23, 2024

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.

blakeembrey avatar blakeembrey commented on August 23, 2024

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.

blakeembrey avatar blakeembrey commented on August 23, 2024

I need to do a git reset HEAD package.json to revert the state.

from mversion.

mikaelbr avatar mikaelbr commented on August 23, 2024

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.

blakeembrey avatar blakeembrey commented on August 23, 2024

@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.

mikaelbr avatar mikaelbr commented on August 23, 2024

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.

blakeembrey avatar blakeembrey commented on August 23, 2024

@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.

mikaelbr avatar mikaelbr commented on August 23, 2024

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.

blakeembrey avatar blakeembrey commented on August 23, 2024

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.

mikaelbr avatar mikaelbr commented on August 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.