Skip to content

Commit

Permalink
Log when directory is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Jul 30, 2023
1 parent 6b4a638 commit ae01936
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pkg/commands/git_commands/worktree.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func (self *WorktreeCommands) Delete(worktreePath string, force bool) error {
}

func (self *WorktreeCommands) Detach(worktreePath string) error {
cmdArgs := NewGitCmd("checkout").Arg("--detach").WorktreePath(worktreePath).ToArgv()
cmdArgs := NewGitCmd("checkout").Arg("--detach").ToArgv()

return self.cmd.New(cmdArgs).Run()
return self.cmd.New(cmdArgs).SetWd(worktreePath).Run()
}

func (self *WorktreeCommands) IsCurrentWorktree(w *models.Worktree) bool {
Expand Down
9 changes: 9 additions & 0 deletions pkg/commands/oscommands/cmd_obj.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ type ICmdObj interface {
AddEnvVars(...string) ICmdObj
GetEnvVars() []string

// sets the working directory
SetWd(string) ICmdObj

// runs the command and returns an error if any
Run() error
// runs the command and returns the output as a string, and an error if any
Expand Down Expand Up @@ -142,6 +145,12 @@ func (self *CmdObj) GetEnvVars() []string {
return self.cmd.Env
}

func (self *CmdObj) SetWd(wd string) ICmdObj {
self.cmd.Dir = wd

return self
}

func (self *CmdObj) DontLog() ICmdObj {
self.dontLog = true
return self
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/controllers/branches_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func (self *BranchesController) promptWorktreeBranchDelete(selectedBranch *model
Title: fmt.Sprintf("Branch %s is checked out by worktree %s", selectedBranch.Name, worktree.Name()),
Items: []*types.MenuItem{
{
Label: "Switch to worktree " + worktree.Name(),
Label: "Switch to worktree",
OnPress: func() error {
return self.c.Helpers().Worktree.Switch(worktree, context.LOCAL_BRANCHES_CONTEXT_KEY)
},
Expand Down
2 changes: 2 additions & 0 deletions pkg/gui/controllers/helpers/repos_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ func (self *ReposHelper) DispatchSwitchTo(path string, reuse bool, errMsg string
return nil
}

self.c.LogCommand(fmt.Sprintf("Changing directory to %s", path), false)

if err := os.Chdir(path); err != nil {
if os.IsNotExist(err) {
return self.c.ErrorMsg(errMsg)
Expand Down
10 changes: 7 additions & 3 deletions pkg/gui/controllers/helpers/worktree_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (self *WorktreeHelper) NewWorktree() error {
if err := self.c.Git().Worktree.New(sanitizedBranchName(path), committish); err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.WORKTREES, types.BRANCHES, types.FILES}})
})
},
})
Expand Down Expand Up @@ -122,7 +122,7 @@ func (self *WorktreeHelper) Remove(worktree *models.Worktree, force bool) error
}
return self.c.ErrorMsg(errMessage)
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.WORKTREES}})
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.WORKTREES, types.BRANCHES, types.FILES}})
})
},
})
Expand All @@ -132,6 +132,10 @@ func (self *WorktreeHelper) Detach(worktree *models.Worktree) error {
return self.c.WithWaitingStatus(self.c.Tr.DetachingWorktree, func(gocui.Task) error {
self.c.LogAction(self.c.Tr.RemovingWorktree)

return self.c.Git().Worktree.Detach(worktree.Path)
err := self.c.Git().Worktree.Detach(worktree.Path)
if err != nil {
return self.c.Error(err)
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.WORKTREES, types.BRANCHES, types.FILES}})
})
}

0 comments on commit ae01936

Please sign in to comment.