diff --git a/pkg/commands/git_commands/repo_paths.go b/pkg/commands/git_commands/repo_paths.go index 1fdc016d8..13cda86a4 100644 --- a/pkg/commands/git_commands/repo_paths.go +++ b/pkg/commands/git_commands/repo_paths.go @@ -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 diff --git a/pkg/commands/git_commands/repo_paths_test.go b/pkg/commands/git_commands/repo_paths_test.go index 6533b733d..5e6275522 100644 --- a/pkg/commands/git_commands/repo_paths_test.go +++ b/pkg/commands/git_commands/repo_paths_test.go @@ -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"), }, } diff --git a/pkg/commands/git_commands/worktree_loader_test.go b/pkg/commands/git_commands/worktree_loader_test.go index 7f805b1b9..12b308074 100644 --- a/pkg/commands/git_commands/worktree_loader_test.go +++ b/pkg/commands/git_commands/worktree_loader_test.go @@ -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) } }) } diff --git a/pkg/utils/formatting_test.go b/pkg/utils/formatting_test.go index 2de282311..b1777911b 100644 --- a/pkg/utils/formatting_test.go +++ b/pkg/utils/formatting_test.go @@ -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) } } diff --git a/pkg/utils/rebase_todo_test.go b/pkg/utils/rebase_todo_test.go index a9bcb574b..40f44a3cb 100644 --- a/pkg/utils/rebase_todo_test.go +++ b/pkg/utils/rebase_todo_test.go @@ -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) }) } }