Skip to content

Commit

Permalink
commands,git: rename GetAllWorktrees() function
Browse files Browse the repository at this point in the history
The GetAllWorkTrees() function in our "git" package was introduced as
part of the implementation of the "git lfs prune" command in PR git-lfs#742,
along with the Worktree structure and various related functions, such
as the pruneTaskGetRetainedWorktree() function run by the "git lfs prune"
command.

In all instances, we use the terms "Worktree" and "worktree" rather
than the camel-case "WorkTree" or "workTree", except in the name of
the GetAllWorkTrees() function and its associated TestWorkTrees() test
function.

Before we add another implementation of the GetAllWorkTrees() function
in a subsequent commit in this PR, we first revise the function's name
to match that of the structures it returns, which slightly improves the
consistency of our naming scheme.
  • Loading branch information
chrisd8088 committed Oct 28, 2024
1 parent 3356216 commit 54d4358
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion commands/command_prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ func pruneTaskGetRetainedWorktree(gitscanner *lfs.GitScanner, fetchconf lfs.Fetc

// Retain other worktree HEADs too
// Working copy, branch & maybe commit is different but repo is shared
allWorktrees, err := git.GetAllWorkTrees(cfg.LocalGitStorageDir())
allWorktrees, err := git.GetAllWorktrees(cfg.LocalGitStorageDir())
if err != nil {
errorChan <- err
return
Expand Down
4 changes: 2 additions & 2 deletions git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,11 +908,11 @@ type Worktree struct {
Dir string
}

// GetAllWorkTrees returns the refs that all worktrees are using as HEADs plus the worktree's path.
// GetAllWorktrees returns the refs that all worktrees are using as HEADs plus the worktree's path.
// This returns all worktrees plus the master working copy, and works even if
// working dir is actually in a worktree right now
// Pass in the git storage dir (parent of 'objects') to work from
func GetAllWorkTrees(storageDir string) ([]*Worktree, error) {
func GetAllWorktrees(storageDir string) ([]*Worktree, error) {
worktreesdir := filepath.Join(storageDir, "worktrees")
dirf, err := os.Open(worktreesdir)
if err != nil && !os.IsNotExist(err) {
Expand Down
6 changes: 3 additions & 3 deletions git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func TestResolveEmptyCurrentRef(t *testing.T) {
assert.NotEqual(t, nil, err)
}

func TestWorkTrees(t *testing.T) {
func TestWorktrees(t *testing.T) {
// Only git 2.5+
if !IsGitVersionAtLeast("2.5.0") {
return
Expand Down Expand Up @@ -393,7 +393,7 @@ func TestWorkTrees(t *testing.T) {
test.RunGitCommand(t, true, "worktree", "add", "branch2_wt", "branch2")
test.RunGitCommand(t, true, "worktree", "add", "branch4_wt", "branch4")

worktrees, err := GetAllWorkTrees(filepath.Join(repo.Path, ".git"))
worktrees, err := GetAllWorktrees(filepath.Join(repo.Path, ".git"))
assert.NoError(t, err)
expectedWorktrees := []*Worktree{
{
Expand Down Expand Up @@ -448,7 +448,7 @@ func TestWorktreesBareRepo(t *testing.T) {
repo.Cleanup()
}()

worktrees, err := GetAllWorkTrees(repo.Path)
worktrees, err := GetAllWorktrees(repo.Path)
assert.NoError(t, err)
assert.Nil(t, worktrees)
}
Expand Down

0 comments on commit 54d4358

Please sign in to comment.