1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-04 03:48:07 +02:00

Handle trailing slash in worktree path (#2947)

This commit is contained in:
Jesse Duffield 2023-08-21 13:26:58 +10:00 committed by GitHub
commit 6a6cb25d7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 6 deletions

View File

@ -158,6 +158,7 @@ func linkedWorktreeGitDirPath(fs afero.Fs, worktreePath string) (string, error)
gitDir := strings.TrimPrefix(gitDirLine[0], "gitdir: ")
gitDir = filepath.Clean(gitDir)
// For windows support
gitDir = filepath.ToSlash(gitDir)
@ -223,7 +224,7 @@ func getCurrentRepoGitDirPath(
// If this error causes issues, we could relax the constraint and just always
// return the path
return "", "", errors.Errorf("could not find git dir for %s: path is not under `worktrees` or `modules` directories", currentPath)
return "", "", errors.Errorf("could not find git dir for %s: the path '%s' is not under `worktrees` or `modules` directories", currentPath, worktreeGitPath)
}
// takes a path containing a symlink and returns the true path

View File

@ -55,6 +55,24 @@ func TestGetRepoPathsAux(t *testing.T) {
},
Err: nil,
},
{
Name: "worktree with trailing separator in path",
BeforeFunc: func(fs afero.Fs) {
// setup for linked worktree
_ = fs.MkdirAll("/path/to/repo/.git/worktrees/worktree1", 0o755)
_ = afero.WriteFile(fs, "/path/to/repo/worktree1/.git", []byte("gitdir: /path/to/repo/.git/worktrees/worktree1/"), 0o644)
},
Path: "/path/to/repo/worktree1",
Expected: &RepoPaths{
currentPath: "/path/to/repo/worktree1",
worktreePath: "/path/to/repo/worktree1",
worktreeGitDirPath: "/path/to/repo/.git/worktrees/worktree1",
repoPath: "/path/to/repo",
repoGitDirPath: "/path/to/repo/.git",
repoName: "repo",
},
Err: nil,
},
{
Name: "worktree .git file missing gitdir directive",
BeforeFunc: func(fs afero.Fs) {
@ -117,7 +135,7 @@ func TestGetRepoPathsAux(t *testing.T) {
},
Path: "/path/to/repo/my/submodule1",
Expected: nil,
Err: errors.New("failed to get repo git dir path: could not find git dir for /path/to/repo/my/submodule1: path is not under `worktrees` or `modules` directories"),
Err: errors.New("failed to get repo git dir path: could not find git dir for /path/to/repo/my/submodule1: the path '/random/submodule1' is not under `worktrees` or `modules` directories"),
},
}

View File

@ -186,7 +186,7 @@ branch refs/heads/mybranch-worktree
assert.EqualError(t, errors.New(s.expectedErr), err.Error())
} else {
assert.NoError(t, err)
assert.EqualValues(t, worktrees, s.expectedWorktrees)
assert.EqualValues(t, s.expectedWorktrees, worktrees)
}
})
}

View File

@ -79,7 +79,7 @@ func TestGetPadWidths(t *testing.T) {
for _, test := range tests {
output := getPadWidths(test.input)
assert.EqualValues(t, output, test.expected)
assert.EqualValues(t, test.expected, output)
}
}
@ -217,6 +217,6 @@ func TestRenderDisplayStrings(t *testing.T) {
for _, test := range tests {
output := RenderDisplayStrings(test.input, test.columnAlignments)
assert.EqualValues(t, output, test.expected)
assert.EqualValues(t, test.expected, output)
}
}

View File

@ -326,7 +326,7 @@ func TestRebaseCommands_moveFixupCommitDown(t *testing.T) {
assert.EqualError(t, actualErr, scenario.expectedErr.Error())
}
assert.EqualValues(t, actualTodos, scenario.expectedTodos)
assert.EqualValues(t, scenario.expectedTodos, actualTodos)
})
}
}