Skip to content

Error running ggshield in Docker within a Git worktree #977

Open
@alikeys-nable

Description

@alikeys-nable

Environment

  • ggshield version: latest
  • Operating system (Linux, macOS, Windows): WSL2 within Windows
  • Operating system version: Windows 11
  • Python version:

Describe the bug

I am using a Git worktree. When I commit to the initial worktree directory, the pre-commit check passes. When committing to another Git worktree directory, the path doesn't resolve and there's a message saying it's not a git repository.

Steps to reproduce:

  1. clone a Git repository locally
  2. add another branch from the same repository as a Git worktree: git worktree add ../other-branch-dir feature/my_other_branch
  3. Run ggshield secret scan pre-commit
  4. An error occurs

Actual result:

git commit -m "TESTING COMMIT IN WORKTREE"
latest: Pulling from someplace/ggshield
Digest: sha256:2eb6blahblah
Status: Image is up to date for quay.io/someplace/ggshield:latest
quay.io/someplace/ggshield:latest
fatal: not a git repository: /code/../original-server-code-dir/worktrees/other-branch-dir
make: *** [.make/tools-ggshield.mk:11: ggshield/pre-commit] Error 128

The make target runs the following using Docker:

	@docker run -i --rm \
		-v .:/code \
		--workdir /code \
		--env-file .env \
		--platform=linux/amd64 \
		$(GGSHIELD_IMAGE) ggshield secret scan pre-commit

Expected result:

The ggshield check passes without error. This is the output when committing from the original folder:

latest: Pulling from someplace/ggshield
Digest: sha256:2eb6blahblah
Status: Image is up to date for quay.io/someplace/ggshield:latest
quay.io/someplace/ggshield:latest

No secrets have been found

[feature/my_original_branch 44blahblah] TEST COMMIT

If applicable, add logs or screenshots to help explain your problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:newThis issue needs to be reviewedtype:bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions