Skip to content

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

@alundiak

Description

@alundiak

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

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions