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

error calling replace command for {files}: exit status 128 when there is no upstream #568

Closed
tilak-puli opened this issue Oct 26, 2023 · 2 comments · Fixed by #687
Closed
Labels
bug Something isn't working

Comments

@tilak-puli
Copy link

🔧 Summary

Exiting with error code:128 on running any hook from left hook. verbose logs shows that this is because of no upstream

Lefthook version

v1.5.2

Steps to reproduce

  1. Create a new local repo without upstream
  2. Install lefthook and run a hook with replace command like {files}

Expected results

Hooks should run without any problem

Actual results

error calling replace command for {files}: exit status 128
error replacing {files}: exit status 128

Logs / Screenshots

lefthook run pre-commit -v
│ [lefthook] cmd: [git rev-parse --show-toplevel]
│ [lefthook] dir:
│ [lefthook] err:
│ [lefthook] out: /Users/tilakpur/projects/mosip/ovp-ble

│ [lefthook] cmd: [git rev-parse --git-path hooks]
│ [lefthook] dir:
│ [lefthook] err:
│ [lefthook] out: .git/hooks

│ [lefthook] cmd: [git rev-parse --git-path info]
│ [lefthook] dir:
│ [lefthook] err:
│ [lefthook] out: .git/info

│ [lefthook] cmd: [git rev-parse --git-dir]
│ [lefthook] dir:
│ [lefthook] err:
│ [lefthook] out: .git

╭──────────────────────────────────────╮
│ 🥊 lefthook v1.5.2 hook: pre-commit │
╰──────────────────────────────────────╯
│ [lefthook] cmd: [sh -c git status --short]
│ [lefthook] dir: /Users/tilakpur/projects/mosip/ovp-ble
│ [lefthook] err:
│ [lefthook] out:
│ [lefthook] cmd: [sh -c git diff --name-only @{push}]
│ [lefthook] cmd: [sh -c git diff --name-only @{push}]
│ [lefthook] dir: /Users/tilakpur/projects/mosip/ovp-ble
│ [lefthook] dir: /Users/tilakpur/projects/mosip/ovp-ble
│ [lefthook] err: exit status 128
│ [lefthook] err: exit status 128
│ [lefthook] out: fatal: no upstream configured for branch 'main'

│ [lefthook] out: fatal: no upstream configured for branch 'main'

error calling replace command for {files}: exit status 128
error replacing {files}: exit status 128
│ types (skip) error
│ lint (skip) error
│ [lefthook] cmd: [sh -c git stash list]
│ [lefthook] dir: /Users/tilakpur/projects/mosip/ovp-ble
│ [lefthook] err:
│ [lefthook] out:

@tilak-puli tilak-puli added the bug Something isn't working label Oct 26, 2023
@keithhackbarth
Copy link

@tilak-puli - Do you have a workaround for this?

@mrexox - Any suggestions? Seems like a very critical issue as unable to push any code from local to origin. See multiple places online. https://gitlab.com/gitlab-org/gitlab/-/issues/448387 Happy to help but our team is brand new to using lefthook.

@mrexox
Copy link
Member

mrexox commented Apr 1, 2024

@keithhackbarth, @tilak-puli I think I have a solution but I'd like to know what you think about it.

Lefthook gets the diff with the previously pushed commit to the upstream. If there's no upstream, then lefthook fails. But maybe the better option would be to get the whole diff from the empty tree?

git diff --name-only HEAD $(git hash-object -t tree /dev/null)

Unfortunately, this diff will be very-very huge (depending on a number of commits since the first commit). However this looks correct if you are pushing new changes you haven't ever pushed. Otherwise there's no way to know what changes you have already pushed and what changes are new.

Does it feel convenient to get the diff from the very first commit (it can be very huge), or should lefthook throw an error to STDOUT? Or maybe it should skip the hook? I feel like using the huge diff is a better option but my vision is not accurate since I always have an upstream in my local repos and never face this error. I'd be glad to hear your thoughts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants