Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using --force to continue doesn't really replacing hooks file #68

Open
alundiak opened this issue Jun 29, 2017 · 0 comments
Open

Using --force to continue doesn't really replacing hooks file #68

alundiak opened this issue Jun 29, 2017 · 0 comments
Assignees

Comments

@alundiak
Copy link
Contributor

alundiak commented Jun 29, 2017

My env: MacOS 10.12.5, node 8.1.2, npm 5.0.3, grunt-githooks 0.6.0, zsh 5.2.
The same behavior on Windows 7, git version 2.9.0.windows.1.

My Grunt configs (example with pre-commit hook):

eslint...,

githooks: {
    viaNode: {
        'pre-commit': 'eslint'
    },
    viaShell: {
        options: {
            hashbang: '#!/bin/sh',
            template: './node_modules/grunt-githooks/templates/shell.hb',
            startMarker: '## LET THE FUN BEGIN',
            endMarker: '## PARTY IS OVER'
        },
        'pre-commit': 'eslint'
    }
}

Expected behavior

If I use grunt githooks --force then grunt-githooks module should drop existed file .git/hooks/pre-commit aka recreate it with new template.

Actual behavior

Message in CLI is shown, but file in fact is not changed.

Steps to reproduce

  • run grunt githooks:viaNode it will create default templated pre-commit file.
  • open .git/hooks/pre-commit file, it's created using Node template.
  • run grunt githooks:viaShell it will throw warning "A hook already exist for pre-commit but doesn't seem to be written in the same language as the binding script. Use --force to continue."
  • run grunt githooks:viaShell --force it will throw warning "A hook already exist for pre-commit but doesn't seem to be written in the same language as the binding script. Used --force, continuing."
  • open .git/hooks/pre-commit file, it's still the same (node-templated).
  • Delete file .git/hooks/pre-commit
  • run again grunt githooks:viaShell
  • and now file .git/hooks/pre-commit created from dedicated Shell-like template.

My version of files:

  • Node-Template-Based:
#!/usr/bin/env node

// GRUNT-GITHOOKS START
var exec = require('child_process').exec;

exec('grunt eslint', {
       cwd: '/Users/alund/prj/builders'
     }, function (err, stdout, stderr) {

  var exitCode = 0;
  if (err) {
    console.log(stderr || err);
    exitCode = -1;
  }

  process.exit(exitCode);
}).stdout.on('data', function (chunk){
    process.stdout.write(chunk);
});
// GRUNT-GITHOOKS END

Shell-template-based + Gruntfile.config:

#!/bin/sh

## LET THE FUN BEGIN
(cd "/Users/alund/prj/builders" && grunt eslint)

## PARTY IS OVER

Changes to discuss

If such behavior is designed, then IMHO it's odd. What the exactly it continues?
So far, I delete file manually and re-run command. If --force really worked, I could avoid such monkey job :)

So what people think about it?

cc/ @rhumaric @franz-josef-kaiser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants