Skip to content

Problems with remote refs containing slashes #1478

Description

@scop

Description

Lefthook config from remotes where ref contains slashes fail to checkout properly, leading to

  • refetch happening every time, no matter the config
  • scripts from remote not working

lefthook.yml

remotes:
  - git_url: https://github.com/scop/lefthook-test.git
    ref: feat/test-branch
    refetch_frequency: 24h

Commands to reproduce

Full reproducer repo at https://github.com/scop/lefthook-test/tree/feat/test-branch, copying here

$ lefthook run --verbose pre-commit 
│  [lefthook] git: git version       
│             out: git version 2.53.0

│  [lefthook] git: git rev-parse --path-format=absolute --show-toplevel --git-path hooks --git-path info --git-dir
│             out: /tmp/tmp.jTQCBYVFuF                                                                            
│                  /tmp/tmp.jTQCBYVFuF/.git/hooks                                                                 
│                  /tmp/tmp.jTQCBYVFuF/.git/info                                                                  
│                  /tmp/tmp.jTQCBYVFuF/.git                                                                       

│  loading config:  /tmp/tmp.jTQCBYVFuF/lefthook.yaml
│  Merging remote config: https://github.com/scop/lefthook-test.git: /tmp/tmp.jTQCBYVFuF/.git/info/lefthook-remotes/lefthook-test-feat/test-branch/lefthook.yml
╭──────────────────────────────────────────╮
│ 🥊 lefthook  v2.1.10   hook:  pre-commit │
╰──────────────────────────────────────────╯
│  Cloning remote config repository: /tmp/tmp.jTQCBYVFuF/.git/info/lefthook-remotes/lefthook-test-feat/test-branch/lefthook-test-feat/test-branch
│  [lefthook] git: git diff --name-only --cached --diff-filter=ACMR

│  [lefthook] git: git diff --name-only --cached --diff-filter=ACMRD

│  [lefthook] git: git status --short --porcelain -z
│             out: ?? lefthook.yaml                 

│  [lefthook] git: git -C /tmp/tmp.jTQCBYVFuF/.git/info/lefthook-remotes clone --quiet --origin origin --depth 1 --branch feat/test-branch https://github.com/scop/lefthook-test.git lefthook-test-feat/test-branch

│  [lefthook] git: git -C /tmp/tmp.jTQCBYVFuF/.git/info/lefthook-remotes/lefthook-test-feat/test-branch fetch --quiet --depth 1 origin -- feat/test-branch

│  [lefthook] git: git -C /tmp/tmp.jTQCBYVFuF/.git/info/lefthook-remotes/lefthook-test-feat/test-branch checkout FETCH_HEAD

│  Reloading config...
│  Merging remote config: https://github.com/scop/lefthook-test.git: /tmp/tmp.jTQCBYVFuF/.git/info/lefthook-remotes/lefthook-test-feat/test-branch/lefthook.yml
│  Removing stale remote:  /tmp/tmp.jTQCBYVFuF/.git/info/lefthook-remotes/lefthook-test-feat
│  hello (skip) no matching staged files
│  [lefthook] script doesn't exist: /tmp/tmp.jTQCBYVFuF/.lefthook/pre-commit/hello.sh
│  [lefthook] script doesn't exist: /tmp/tmp.jTQCBYVFuF/.lefthook-local/pre-commit/hello.sh
│  [lefthook] script doesn't exist: /tmp/tmp.jTQCBYVFuF/.config/lefthook/pre-commit/hello.sh
│  [lefthook] script doesn't exist: /tmp/tmp.jTQCBYVFuF/.config/lefthook-local/pre-commit/hello.sh
│  [lefthook] script doesn't exist: /tmp/tmp.jTQCBYVFuF/.git/info/lefthook-remotes/lefthook-test-feat/test-branch/.lefthook/pre-commit/hello.sh
│  script (skip) script does not exist: hello.sh
  ────────────────────────────────────
summary: (done in 0.00 seconds)
🥊 script: script does not exist: hello.sh (0.00 seconds)

Lefthook version

2.1.10

Possible solution

Improve the way the dir for a remote is derived from the git_url and ref. Some alternatives discussed in #1284 which deals with other problems caused by the current way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions