-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Make sure we resolve the symlink of the cwd #3017
Conversation
Make sure we resolve the current directory symlink or it would fail getting confused about the repo root. Signed-off-by: Chmouel Boudjnah <[email protected]>
@jesseduffield i'd like to add tests but it seems that MemFs driver of aerofs does not support Symlinking, would that be okay to create a temporary dir and create a repo in there with symlink ? that would be in the integration test isnt it ? let me know if you have any suggestions on how to do this.. |
@chmouel yep it is annoying that aeofs doesn't cover symlinking. I say in that case it's best to create an integration test for this. Should be simple enough to verify that you can start lazygit inside the symlinked repo without it exiting with an error. There's an example of such a test at pkg/integration/tests/config/remote_named_star.go |
This works only if E.g.:
|
Before discovering that it was a known issue (and before finding this PR), I created a minimal repo to reproduce the same symlink issue The README has simple reproduction instructions. Feel free to use it if it helps in any way. https://github.com/JL102/lazygit-submodule-symlink-test/tree/main |
@@ -228,7 +228,7 @@ func getCurrentRepoGitDirPath( | |||
} | |||
|
|||
// takes a path containing a symlink and returns the true path | |||
func resolveSymlink(path string) (string, error) { | |||
func ResolveSymlink(path string) (string, error) { | |||
l, err := os.Lstat(path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we even need this check if it's os.ModeSymlink
?
In order to be able to call lazygit
from a folder whose path contains a symlink this check fails, and lazygit
fails to start, but if we just return filepath.EvalSymlinks(path)
, all works as expected.
The example is what I've written in the conversation for this PR.
@jesseduffield could this have been done for potential performance reasons? Tried blaming it, but it went through two refactors so I stopped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've never made any performance-related decisions around symlinks. If filepath.EvalSymlinks(path)
works I'm happy for us to use it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs say:
// EvalSymlinks returns the path name after the evaluation of any symbolic
// links.
// If path is relative the result will be relative to the current directory,
// unless one of the components is an absolute symbolic link.
// EvalSymlinks calls Clean on the result.
That would suggest nothing changes if the given path isn't a symlink/contains a symlink, so I see no reason to for this function at all.if-else
on it being a symlink
But I'd wait for tests that confirm it.
Works for me. 👍 |
@chmouel are you still up for this? It would be great to have an integration test for this, and like Jesse said:
|
@mark2185 you are right, i am still up for it, let me find some time this week-end or i'll close this PR |
No need to close it, someone else can just build on top of it! |
So I have tried to build an integration and I have some difficulty changing the directory of where the test run: //cat pkg/integration/tests/misc/symlinks_repo.go
package misc
import (
"fmt"
"os"
"path/filepath"
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var SymlinkRepo = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Make sure lazygit open on a symlink into a repository",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.NewBranch("mybranch")
shell.CreateDir("symlinked")
shell.CreateFileAndAdd("symlinked/blah.txt", "blah")
shell.Commit("initial commit")
},
Run: func(t *TestDriver, _ config.KeybindingConfig) {
tempdir, _ := os.MkdirTemp("", "lazygit-symlink")
t.Shell().RunShellCommand(fmt.Sprintf("ln -s $PWD/symlinked %s", tempdir))
_ := os.Chdir(filepath.Join(tempdir, "symlinked"))
t.Views().Commits()
},
}) It need to be outside of where the test run currently since that bug would not reproduce otherwise so using a tempdir, but when I run that test against (i haven't defer the os.RemoveAll of tempdir because i think it was bringing other issues) |
FYI, this PR would be obsoleted by PR #3183, which replaces lazygit's pathfinding code by delegating that work to git (via |
@jwhitley perfect thank you, i may close this PR now since it was stalled for too long! |
Make sure we resolve the current directory symlink or it would fail
getting confused about the repo root.
Fixes #3015
go run scripts/cheatsheet/main.go generate
)