desktop / dugite-native

A toolchain for building a portable, cross-platform Git for applications
GNU General Public License v2.0
197 stars 108 forks source link

Pre-commit hook compatibility #164

Open IdanAdar opened 5 years ago

IdanAdar commented 5 years ago

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.

j-f1 commented 5 years ago

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

IdanAdar commented 5 years ago

No. When using git commit it worked.

shiftkey commented 5 years ago

@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 commented 5 years ago

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

shiftkey commented 5 years ago

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

IdanAdar commented 5 years ago

Thanks. Still hopeful for fast resolution.

sandyjernigan commented 4 years ago

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 commented 3 years ago

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