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

Pre-commit hook compatibility #164

Open
IdanAdar opened this issue Dec 31, 2018 · 8 comments
Open

Pre-commit hook compatibility #164

IdanAdar opened this issue Dec 31, 2018 · 8 comments
Labels

Comments

@IdanAdar
Copy link

My company now requires the use of a detect-secrets tool and a pre-commit step.
After following the instructions and attempting to push a commit, it failed with the following:

Commit failed - exit code 1 received, with output: '[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to /Users/iadar/.cache/pre-commit/patch1546236539.
[INFO] Initializing environment for git@github.****.com:****/****-detect-secrets.
[INFO] Restored changes from /Users/iadar/.cache/pre-commit/patch1546236539.
An unexpected error has occurred: CalledProcessError: Command: ('/Applications/GitHub Desktop.app/Contents/Resources/app/git/libexec/git-core/git', 'submodule', 'update', '--init', '--recursive')
Return code: 1
Expected return code: 0
Output: (none)
Errors: 
    /Applications/GitHub Desktop.app/Contents/Resources/app/git/libexec/git-core/git-sh-setup: line 46: //libexec/git-core/git-sh-i18n: No such file or directory
    

Check the log at /Users/iadar/.cache/pre-commit/pre-commit.log'

The log file shows:

An unexpected error has occurred: CalledProcessError: Command: ('/Applications/GitHub Desktop.app/Contents/Resources/app/git/libexec/git-core/git', 'submodule', 'update', '--init', '--recursive')
Return code: 1
Expected return code: 0
Output: (none)
Errors:
    /Applications/GitHub Desktop.app/Contents/Resources/app/git/libexec/git-core/git-sh-setup: line 46: //libexec/git-core/git-sh-i18n: No such file or directory


Traceback (most recent call last):
  File "/Users/iadar/Library/Python/2.7/lib/python/site-packages/pre_commit/error_handler.py", line 47, in error_handler
    yield
  File "/Users/iadar/Library/Python/2.7/lib/python/site-packages/pre_commit/main.py", line 261, in main
    return run(runner, store, args)
  File "/Users/iadar/Library/Python/2.7/lib/python/site-packages/pre_commit/commands/run.py", line 256, in run
    for _, hook in repo.hooks:
  File "/Users/iadar/Library/Python/2.7/lib/python/site-packages/cached_property.py", line 35, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/Users/iadar/Library/Python/2.7/lib/python/site-packages/pre_commit/repository.py", line 162, in hooks
    if hook['id'] not in self.manifest_hooks:
  File "/Users/iadar/Library/Python/2.7/lib/python/site-packages/cached_property.py", line 35, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/Users/iadar/Library/Python/2.7/lib/python/site-packages/pre_commit/repository.py", line 155, in manifest_hooks
    repo_path = self.store.clone(repo, rev)
  File "/Users/iadar/Library/Python/2.7/lib/python/site-packages/pre_commit/store.py", line 149, in clone
    return self._new_repo(repo, ref, deps, clone_strategy)
  File "/Users/iadar/Library/Python/2.7/lib/python/site-packages/pre_commit/store.py", line 125, in _new_repo
    make_strategy(directory)
  File "/Users/iadar/Library/Python/2.7/lib/python/site-packages/pre_commit/store.py", line 147, in clone_strategy
    _git_cmd('submodule', 'update', '--init', '--recursive')
  File "/Users/iadar/Library/Python/2.7/lib/python/site-packages/pre_commit/store.py", line 144, in _git_cmd
    return cmd_output('git', *args, cwd=directory, env=env)
  File "/Users/iadar/Library/Python/2.7/lib/python/site-packages/pre_commit/util.py", line 186, in cmd_output
    returncode, cmd, retcode, output=(stdout, stderr),
CalledProcessError: Command: ('/Applications/GitHub Desktop.app/Contents/Resources/app/git/libexec/git-core/git', 'submodule', 'update', '--init', '--recursive')
Return code: 1
Expected return code: 0
Output: (none)
Errors:
    /Applications/GitHub Desktop.app/Contents/Resources/app/git/libexec/git-core/git-sh-setup: line 46: //libexec/git-core/git-sh-i18n: No such file or directory

I don't know if the problem is on the GitHub Desktop 1.5.2 beta 0 side, the pre-commit side, the Git side or the Python side. Any clues to resolve this will be much appreciated.

@IdanAdar IdanAdar changed the title Pre-commit compatibility Pre-commit hook compatibility Dec 31, 2018
@j-f1
Copy link

j-f1 commented Dec 31, 2018

Does a manual git commit in the command line (hit Ctrl+`) also produce the issue?

@IdanAdar
Copy link
Author

IdanAdar commented Dec 31, 2018

No. When using git commit it worked.

@shiftkey
Copy link
Member

@IdanAdar thanks for the report. I believe this is an issue with the embedded Git, and I suspect I need to patch it to address this properly.

What's happening is inside the git-sh-setup that your pre-commit hook is failing on this command:

# Source git-sh-i18n for gettext support.
. "$(git --exec-path)/git-sh-i18n"

That's because the output of git --exec-path isn't resolving correctly. I can verify this by running the command directly against that version of Git:

$ ./git --exec-path
//libexec/git-core

This works fine on the command line because Git is installed at a known location, but the embedded Git needs to be "aware" that it's embedded inside a .app (or in a version-specific path on Windows).

@IdanAdar
Copy link
Author

IdanAdar commented Dec 31, 2018

Thanks @shiftkey. Hopefully it's an easy fix. I'd like to continue using the client and of course promote it internally...

@shiftkey
Copy link
Member

shiftkey commented Dec 31, 2018

@IdanAdar i'm going to move this into dugite-native which is the project that needs to address this issue (there's not much the app itself can do aside from update the package once it's been fixed).

@shiftkey shiftkey transferred this issue from desktop/desktop Dec 31, 2018
@IdanAdar
Copy link
Author

Thanks. Still hopeful for fast resolution.

@sandyjernigan
Copy link

Not sure how well it is going to work but I copied my git-secrets file and pasted into the "C:\Users%username%\AppData\Local\GitHubDesktop\app-2.2.3\resources\app\git\usr\bin" it allowed me to commit like I did before installing git secrets I have not tested if it will prevent uploading secrets yet.

@AndrewDorn
Copy link

Not sure how well it is going to work but I copied my git-secrets file and pasted into the "C:\Users%username%\AppData\Local\GitHubDesktop\app-2.2.3\resources\app\git\usr\bin" it allowed me to commit like I did before installing git secrets I have not tested if it will prevent uploading secrets yet.

To expand on the above:

  1. Copy the file 'git-secrets' into the bin folder.
  2. Edit the new, copied file. Replace '#!/usr/bin/env bash' with '#!/bin/sh'
  3. Repeat step 2 on any file in your repo's .git/hooks folder that isn't marked '.sample'.

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

No branches or pull requests

5 participants