Skip to content

fix: resolve symlink before initializing repo paths#5454

Closed
renezander030 wants to merge 1 commit intojesseduffield:masterfrom
renezander030:fix/3015-symlink-crash
Closed

fix: resolve symlink before initializing repo paths#5454
renezander030 wants to merge 1 commit intojesseduffield:masterfrom
renezander030:fix/3015-symlink-crash

Conversation

@renezander030
Copy link
Copy Markdown

Summary

  • Resolve symlinks on the current working directory in GetRepoPaths (via filepath.EvalSymlinks) before passing it to GetRepoPathsForDir
  • When cwd is a symlink pointing into a git repo subdirectory, os.Getwd() returns the symlink path, causing lazygit to fail to locate the .git directory
  • Existing integration test worktree/symlink_into_repo_subdir covers this scenario

Test plan

  • go build ./... compiles successfully
  • go test ./pkg/commands/git_commands/... passes
  • Manual test: create a symlink to a repo subdirectory, run lazygit from the symlink — should open without crashing

Fixes #3015

When the current working directory is a symlink to a directory inside a
git repo, os.Getwd() returns the symlink path which causes lazygit to
fail to find the git repository. Resolve symlinks via
filepath.EvalSymlinks before passing the path to GetRepoPathsForDir.

Fixes jesseduffield#3015
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity . 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@stefanhaller
Copy link
Copy Markdown
Collaborator

We had the same PR a few days ago (#5417), and my question on that PR (which wasn't answered) applies here, as well.

@renezander030
Copy link
Copy Markdown
Author

renezander030 commented Mar 31, 2026

You're right - PR #3183 switched to git rev-parse for path resolution, which should handle symlinks correctly since git resolves them natively. I missed that this was already addressed. Happy to close this if it's no longer needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash when the current directory is a symlink to a directory in a GIT repo

2 participants